代码之家  ›  专栏  ›  技术社区  ›  Dabblernl

从basicHttpBinding升级到wsHttpBinding:连接失败

  •  1
  • Dabblernl  · 技术社区  · 14 年前

    现在,当我从托管WCF服务的同一服务器所管理的域中的任何客户机连接到WCF服务时,一切正常。但是当我尝试从域外的客户机连接到服务时,连接失败。客户端收到一个异常,说明“调用方未通过服务的身份验证”。所以这一定是一个身份验证问题。

    如何排除故障?关于这个主题的一些有用的资源的指针也是非常受欢迎的。

    编辑:

    问题如下:

    • IIS托管了两个网站:mydomain.com和www.mydomain.com
    • 我想在上主持WCF服务www.mydomain.com 因为我已经为那个网址购买了一个证书。
    • WCF抛出错误“此集合已包含具有http方案的地址”。在这个集合中,每个方案最多只能有一个地址。
    • 必须通过添加baseAddressPrefixFilter来解决此问题
    • 在解决这个问题之后,我得到了一个错误:“提供的URI方案https无效;应为“http”
    • 客户 ,而不是服务器。

    下面是实现此目的的web.config:

    <system.serviceModel>
         <serviceHostingEnvironment>
            <baseAddressPrefixFilters>
              <add prefix="http://www.mydomain.com"/>
            </baseAddressPrefixFilters>
         </serviceHostingEnvironment>
    
        <services>
          <service behaviorConfiguration="ServiceBehavior" name="MyApp.MyService">
            <endpoint address="mex"
                      binding="mexHttpsBinding"
              contract="IMetadataExchange"
               />
        <endpoint address="wsHttp"
              binding="wsHttpBinding"
                      bindingConfiguration="NoAuthentication"
                      contract="MyApp.IContract"/>
          </service>
        </services>
        <bindings>
        <wsHttpBinding>
            <binding name="NoAuthentication">
             <security mode="Transport">
                <transport clientCredentialType="None"/>
              </security>
            </binding>
        </wsHttpBinding>
       </bindings>
        <behaviors>
          <serviceBehaviors>
            <behavior name="ServiceBehavior">
              <!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment -->
              <serviceMetadata 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"/>
            </behavior>
          </serviceBehaviors>
        </behaviors>
      </system.serviceModel>
    

    最后,但非常重要:我必须告诉客户机它也应该使用transportsecurity模式,因为我没有使用svcutil创建客户机。

     public static IContract GetContract()
            {
                var binding = new WSHttpBinding(SecurityMode.Transport) {MaxReceivedMessageSize = 655350};
                var factory = new ChannelFactory<IContract>(
                              binding,
                              new EndpointAddress(@"https://www.mydomain.com/MyService.svc/wsHttp"));
                return factory.CreateChannel();
            }
    
    1 回复  |  直到 14 年前
        1
  •  2
  •   marc_s    14 年前

    这是预期的默认行为。默认情况下,WsHttpBinding将使用Windows凭据对调用方进行身份验证。这在您的域中起作用-但在域外失败。

    更新: 最终的参考是 WCF Security Guidance on Codeplex 它有很多关于如何在WCF中执行特定的安全相关操作的指南和分步说明。