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

服务未对调用方进行身份验证(wsDualHttpBinding)

  •  2
  • Houman  · 技术社区  · 12 年前

    我不需要任何身份验证,客户端和服务不会在同一台机器上,也不会在不同的域中。当我尝试连接到服务时,我收到以下错误。

    “System.ServiceModel.Security.SecurityNegotiationException”其他 信息:服务未对调用方进行身份验证。

    因此,我试图关闭服务上的安全:

      <system.serviceModel>
        <bindings>
          <wsDualHttpBinding>
            <binding name="CustomDualBinding">
              <security>
                <message clientCredentialType="None" negotiateServiceCredential="false" />
              </security>
            </binding>
          </wsDualHttpBinding>
        </bindings>
        <services>
          <service name="WCFServiceWebRoleStockTrading.Service">
            <endpoint address="Service.svc" binding="wsDualHttpBinding" bindingConfiguration="CustomDualBinding"
              contract="WCFServiceWebRoleStockTrading.IService" />
          </service>
        </services>
        <behaviors>
          <serviceBehaviors>
            <behavior>
              <serviceMetadata httpGetEnabled="true"/>
              <serviceDebug includeExceptionDetailInFaults="false"/>
            </behavior>
          </serviceBehaviors>
        </behaviors>
        <serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
      </system.serviceModel>
    

    现在,当我尝试单独运行服务时,我会收到以下错误消息:

    未提供服务证书。指定服务证书 在ServiceCredentials中。

    但我不需要任何安全措施。安装服务证书意味着我希望我的客户端安装了相同的证书以进行身份验证,对吗?但这不是我想要的。

    我对这件事很感兴趣,如果能提出建议,我将不胜感激。

    1 回复  |  直到 12 年前
        1
  •  1
  •   Houman    12 年前

    我似乎发现了这一点。我发现很难用Visual Studio中的WCF配置编辑器来正确处理。最好是复制并粘贴它。

     <system.serviceModel>
        <bindings>
          <wsDualHttpBinding>
            <binding name="CustomDualBinding">
              <security mode="None" />
            </binding>
          </wsDualHttpBinding>
        </bindings>
        <services>
          <service name="WCFServiceWebRoleStockTrading.Service">
            <endpoint address="" binding="wsDualHttpBinding" bindingConfiguration="CustomDualBinding"
              contract="WCFServiceWebRoleStockTrading.IService" />
          </service>
        </services>
    ...
     </system.serviceModel>
    

    在客户端中,确保您的配置中包含以下内容:

    Uri baseAddress = new Uri("http://xxx.cloudapp.net/Service.svc");
    WSDualHttpBinding wsd = new WSDualHttpBinding();
    wsd.Security = new WSDualHttpSecurity() { Mode = WSDualHttpSecurityMode.None, Message = new MessageSecurityOverHttp() { ClientCredentialType = MessageCredentialType.None, NegotiateServiceCredential = false } };
    EndpointAddress ea = new EndpointAddress(baseAddress);            
    
    InstanceContext site = new InstanceContext(this);
    _client = new ServiceClient(site, wsd, ea);
    
    推荐文章