【问题标题】:WCF Client Security defaulting to WindowsWCF 客户端安全默认为 Windows
【发布时间】:2012-06-05 20:41:13
【问题描述】:

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

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

这是我的网络服务配置文件:

<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>

【问题讨论】:

  • 客户端和服务器的配置不同。你有什么问题?

标签: c# wcf web-services


【解决方案1】:

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

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

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

【讨论】:

  • 是的,但问题是我正在通过 SVC Util 创建配置。所以我不知道它为什么会这样创建它?
  • 您是否尝试更新服务参考? MEX 端点是否可供客户使用?也许只有 WSDL 没有该信息。
  • 客户端和服务器端的 URL 也不同。是否可以为不同的实例生成代理?
  • 不应该。我不确定服务生成器为什么要输入这些信息..
【解决方案2】:

我相信我已经解决了: 这一行。

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

它不应该是 bindingName 它应该是 bindingConfiguration

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-11-04
    • 2023-04-08
    • 1970-01-01
    • 2012-02-02
    • 1970-01-01
    • 2021-11-27
    相关资源
    最近更新 更多