繁体   English   中英

WCF客户端安全默认为Windows

[英]WCF Client Security defaulting to Windows

我正在尝试使用wsHTTPBinding并使用自定义用户名设置一个简单的WCF Web服务。 我在具有不同端口的自签名证书的远程服务器设置上具有该服务。 例如: https//service.myserice.com442 / service1.svc

由于某种原因,即使我将其设置为“用户名安全性”,客户端似乎仍默认使用Windows安全性。

这是我的Web服务配置文件:

<configuration>
<system.web>
<compilation debug="true" targetFramework="4.0" />
<customErrors mode="Off"></customErrors>
</system.web>
<system.serviceModel>
<services>
  <service name="AutoSenderWCF.Service1" behaviorConfiguration="Behavior1">
    <host>
      <baseAddresses>
        <add baseAddress="https://service.autosender.com.au:442/" />
      </baseAddresses>
    </host>
    <endpoint address="" binding="wsHttpBinding" bindingName="TransportBinding" contract="AutoSenderWCF.IService1"></endpoint>
    <endpoint address="mex"
      binding="mexHttpBinding"
      contract="IMetadataExchange" />
  </service> 

</services>
<bindings>
  <wsHttpBinding>
    <binding name="TransportBinding">
      <security mode="TransportWithMessageCredential">            
        <message clientCredentialType="UserName" />            
      </security>          
    </binding>        
  </wsHttpBinding>      
</bindings>
<behaviors>
  <serviceBehaviors>
    <behavior name="Behavior1">
      <!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment -->
      <serviceMetadata httpGetEnabled="true" httpsGetEnabled="true"/>
      <!-- To receive exception details in faults for debugging purposes, set the value below to true.  Set to false before deployment to avoid disclosing exception information -->
      <serviceDebug includeExceptionDetailInFaults="true"/>

      <serviceCredentials>
        <userNameAuthentication userNamePasswordValidationMode="Custom" customUserNamePasswordValidatorType="AutoSenderWCF.CustomValidator, AutoSenderWCF"/>

      </serviceCredentials>
    </behavior>
  </serviceBehaviors>
</behaviors>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />

和我的客户代码(注意ethe security = windows)

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
    <system.serviceModel>
        <bindings>
            <wsHttpBinding>
                <binding name="TransportBinding_IService1" 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="Windows" negotiateServiceCredential="true"
                            algorithmSuite="Default" />
                    </security>
                </binding>
            </wsHttpBinding>
        </bindings>
        <client>
            <endpoint address="http://service.autosender.com.au/Service1.svc"
                binding="wsHttpBinding" bindingConfiguration="TransportBinding_IService1"
                contract="ServiceReference1.IService1" name="TransportBinding_IService1">
                <identity>
                    <servicePrincipalName value="host/wserver" />
                </identity>
            </endpoint>
        </client>
    </system.serviceModel>
</configuration>

在客户端配置中明确指定要使用Windows:

 <security mode="Message">
                        <transport clientCredentialType="Windows" proxyCredentialType="None"
                            realm="" />
                        <message clientCredentialType="Windows" negotiateServiceCredential="true"
                            algorithmSuite="Default" />
                    </security>

从服务器配置复制该部分。

我相信我已经解决了:这条线。

<endpoint address="" binding="wsHttpBinding" bindingName="TransportBinding" contract="AutoSenderWCF.IService1"></endpoint>

它不应该是bindingName它应该是bindingConfiguration

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM