Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/wcf/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/excel/26.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/json/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
WCF身份验证:自定义用户名和密码验证程序asp.net_Wcf_Wcf Security - Fatal编程技术网

WCF身份验证:自定义用户名和密码验证程序asp.net

WCF身份验证:自定义用户名和密码验证程序asp.net,wcf,wcf-security,Wcf,Wcf Security,是否需要创建服务证书以使用自定义用户名和密码身份验证?我想用自定义用户名和密码验证我的WCF服务 我的服务web.config如下所示: <system.serviceModel> <bindings> <wsHttpBinding>`enter code here` <binding name="NewBinding0"> <security

是否需要创建服务证书以使用自定义用户名和密码身份验证?我想用自定义用户名和密码验证我的WCF服务

我的服务web.config如下所示:

<system.serviceModel>
    <bindings>
        <wsHttpBinding>`enter code here`
            <binding name="NewBinding0">
                <security mode="Message">
                    <transport clientCredentialType="Basic" />
                    <message clientCredentialType="UserName" />
                </security>
            </binding>
        </wsHttpBinding>
    </bindings>
    <services>
        <service behaviorConfiguration="WcfTest.Service1Behavior" name="WcfTest.TestService">
            <endpoint address="" binding="wsHttpBinding" contract="WcfTest.ITestService" />
            <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
        </service>
    </services>
    <behaviors>
        <endpointBehaviors>
            <behavior name="NewBehavior" />
        </endpointBehaviors>
        <serviceBehaviors>
            <behavior name="WcfTest.Service1Behavior">
                <serviceMetadata httpGetEnabled="false" />
                <serviceDebug includeExceptionDetailInFaults="false" />
                <serviceCredentials>   
                    <!-- Use our own custom validation -->
                    <userNameAuthentication userNamePasswordValidationMode="Custom"
                     customUserNamePasswordValidatorType="MyValidator,WcfTest"/>
                </serviceCredentials>
            </behavior>
        </serviceBehaviors>
    </behaviors>
</system.serviceModel>

`在这里输入代码`
客户端Web.config是:

<system.serviceModel>
    <bindings>
        <wsHttpBinding>
            <binding name="WSHttpBinding_ITestService" closeTimeout="00:01:00"
                     openTimeout="00:01:00" receiveTimeout="00:10:00" 
                     sendTimeout="00:01:00" bypassProxyOnLocal="false" 
                     transactionFlow="false" hostNameComparisonMode="StrongWildcard"
                     maxBufferPoolSize="524288" maxReceivedMessageSize="65536"
                     messageEncoding="Text" textEncoding="utf-8" 
                     useDefaultWebProxy="true" allowCookies="false">
                <readerQuotas maxDepth="32" maxStringContentLength="8192" 
                              maxArrayLength="16384" maxBytesPerRead="4096" 
                              maxNameTableCharCount="16384" />
                <reliableSession ordered="true" inactivityTimeout="00:10:00"
                                 enabled="false" />
                <security mode="Message">
                    <transport clientCredentialType="Windows" proxyCredentialType="None"
                               realm="" />
                    <message clientCredentialType="UserName" 
                             negotiateServiceCredential="true"
                             algorithmSuite="Default" 
                             establishSecurityContext="true" />
                </security>
            </binding>
        </wsHttpBinding>
    </bindings>
    <client>
        <endpoint address="http://localhost:2374/Service1.svc" binding="wsHttpBinding"
                  bindingConfiguration="WSHttpBinding_ITestService" 
                  contract="ServiceReference1.ITestService"
                  name="WSHttpBinding_ITestService">
            <identity>
                <userPrincipalName value="NYSA31\abc" />
            </identity>
        </endpoint>
    </client>
</system.serviceModel>

但是我在访问服务时遇到以下错误


WsHttpBinding
需要服务证书。WCF 4(以及具有特殊KB的旧版本)允许在没有证书的情况下公开使用用户名和密码进行身份验证的服务,但您真的想要吗?这意味着用户名和密码将以明文形式通过网络传输=没有安全性,因为任何将捕获数据包的人都可以使用被盗的凭据进行身份验证


使用用户名密码而不使用您需要的或您可以使用的证书。

您的服务和客户端之间的安全设置不匹配。您的服务正在指定消息安全性,传输设置为Basic ClientCredentialType,消息设置为UserName ClientCredentialType,并且您的客户端正在使用消息安全性,传输设置为Windows ClientCredentialType。我不确定这是否是问题所在,但你可能想看看这个领域。@Tim:谢谢你的回答。当我在默认情况下引用服务时,身份验证设置为windows,尽管我在服务中使用用户名作为身份验证类型。我已经对我的客户端web.config进行了更正,但仍然出现了相同的问题。因为模式设置为
Message
,所以无论为
传输
配置了什么
ClientCreadentialType
@Ladislav Mrnka-我想知道,但没有机会研究答案。将模式设置为
Message
是否实质上会使
传输
元素无效?