5

我已经获得了一个 Web 服务 (ASMX) 来使用我需要使用Windows 凭据的女巫。

所以,我已经设置了我的客户端 VPN 并调用了 WSDL,保存为 XML 文件并使用 生成了代理类svcutil.exe,到目前为止,一切都很好......

我将服务称为

// Web Service
client = new CmListSync.Models.WebCorePlayersSoapClient();
client.ClientCredentials.Windows.AllowedImpersonationLevel = System.Security.Principal.TokenImpersonationLevel.Impersonation;
client.ClientCredentials.Windows.ClientCredential = new System.Net.NetworkCredential(cUser, cPass, cDoma);

web.config我有这个设置:

  <system.serviceModel>
    <bindings>
      <wsHttpBinding>
        <binding name="WebCorePlayersSoap" 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="true" />
          <security mode="None">
            <transport clientCredentialType="Windows" proxyCredentialType="None" realm="" />
            <message clientCredentialType="Windows" algorithmSuite="Default" negotiateServiceCredential="true" />
          </security>
        </binding>
      </wsHttpBinding>
    </bindings>
    <client>
      <endpoint address="http://vm-wssrv01/players.asmx" binding="wsHttpBinding"
        bindingConfiguration="WebCorePlayersSoap" contract="WebCorePlayersSoap"
        name="WebCorePlayersSoap" />
    </client>
  </system.serviceModel>

但是当我尝试调用该服务时,我得到一个异常说:

HTTP 请求未经客户端身份验证方案“匿名”授权。从服务器收到的身份验证标头是“Basic realm=\"vm-wssrv01\"'。

我错过了什么?由于我提供了 Windows 凭据,服务不应该正常进行身份验证吗?我还应该做什么?

我试过的:

  • 将安全模式设置Message,我得到与上述问题相同的错误
  • 将安全模式设置TransportWithMessageCredential我得到:提供的 URI 方案“http”无效;预期为“https”。\r\n参数名称:通过
  • 将安全模式设置Transport,我得到:绑定验证失败,因为 WSHttpBinding 不支持通过传输安全 (HTTPS) 进行的可靠会话。无法打开通道工厂或服务主机。使用消息安全性通过 HTTP 进行安全可靠的消息传递。

来自约翰桑德斯的评论:

我已经切换到basicHttpBinding

  <system.serviceModel>
    <bindings>
      <basicHttpBinding>
        <binding name="WebCorePlayersSoap" closeTimeout="00:01:00" openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00" bypassProxyOnLocal="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" />
          <security mode="None">
            <transport clientCredentialType="Windows" proxyCredentialType="Windows" realm="vm-wssrv01" />
            <message clientCredentialType="UserName" algorithmSuite="Default" />
          </security>
        </binding>
      </basicHttpBinding>
    </bindings>
    <client>
      <endpoint address="http://vm-wssrv01/players.asmx" binding="basicHttpBinding"
        bindingConfiguration="WebCorePlayersSoap" contract="WebCorePlayersSoap"
        name="WebCorePlayersSoap" />
    </client>
  </system.serviceModel>

并尝试将security模式更改为:

  • TransportWithMessageCredential {"提供的 URI 方案 'http' 无效;应为 'https'。\r\n参数名称: via"}

  • TransportCredentialOnly {"HTTP 请求未经客户端身份验证方案 'Negotiate' 的授权。从服务器收到的身份验证标头是 'Basic realm=\"vm-wssrv01\"'。"}

  • Message {“BasicHttp 绑定要求 BasicHttpBinding.Security.Message.ClientCredentialType 等同于安全消息的 BasicHttpMessageCredentialType.Certificate 凭据类型。为 UserName 凭据选择 Transport 或 TransportWithMessageCredential 安全性。”}

  • Transport {"提供的 URI 方案 'http' 无效;应为 'https'。\r\n参数名称: via"}

  • None {"HTTP 请求未经授权,客户端身份验证方案为“匿名”。从服务器收到的身份验证标头为 'Basic realm=\"vm-wssrv01\"'。"}

我的想法快用完了:(该服务仅是 HTTP,不是 HTTPS,而且我没有要使用的证书...

4

1 回答 1

5

3 天后,在John Saunders的大力帮助下,他说 ASMX 服务的唯一可能绑定是basicHttpBinding(我对答案的搜索开始更加集中)我进入了这个:

在服务调用者中,必须使用client.ClientCredentials.UserNameas:

// Web Service
client = new CmListSync.Models.WebCorePlayersSoapClient();
client.ClientCredentials.UserName.UserName = cUser;
client.ClientCredentials.UserName.Password = cPass;

在配置部分,需要使用:

  <system.serviceModel>
    <bindings>
      <basicHttpBinding>
        <binding name="WebCorePlayersSoap" closeTimeout="00:01:00" openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00" bypassProxyOnLocal="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" />
          <security mode="TransportCredentialOnly">
            <transport clientCredentialType="Basic" />
          </security>
        </binding>
      </basicHttpBinding>
    </bindings>
    <client>
      <endpoint address="http://vm-wssrv01/players.asmx" binding="basicHttpBinding"
        bindingConfiguration="WebCorePlayersSoap" contract="WebCorePlayersSoap"
        name="WebCorePlayersSoap">
        <identity>
          <dns value="localhost" />
        </identity>
      </endpoint>
    </client>
  </system.serviceModel>
于 2013-01-10T20:18:16.620 回答