【问题标题】:Exception thrown when connecting to web service连接到 Web 服务时抛出异常
【发布时间】:2012-11-15 00:21:03
【问题描述】:

我在通过 HTTPS 从 .NET Windows 应用程序使用 Java Web 服务时遇到问题。 Web 服务需要服务器身份验证,但是当我尝试调用任何方法时,我收到以下错误:

HTTP 请求未经客户端身份验证方案授权 '匿名的'。从服务器收到的身份验证标头是 '基本领域=登录'。

我将 Web 服务添加为 Visual Studio 中的服务引用。这是我的应用配置:

<security> 部分我有这个:

<security mode="Transport">
  transport clientCredentialType="None" proxyCredentialType="None"
   realm="" />
   <message clientCredentialType="UserName" algorithmSuite="Default" />
 </security>

&lt;httpsTransport&gt; 部分我有这个:

<httpsTransport manualAddressing="false" maxBufferPoolSize="524288"
  maxReceivedMessageSize="65536" allowCookies="false" authenticationScheme="Anonymous"
  bypassProxyOnLocal="false"
  hostNameComparisonMode="StrongWildcard" keepAliveEnabled="true"
  maxBufferSize="65536" proxyAuthenticationScheme="Anonymous"
  realm="" transferMode="Buffered" 
  unsafeConnectionNtlmAuthentication="false"
  useDefaultWebProxy="true" requireClientCertificate="false" />

我的代码如下所示:

ServiceReference1.servicePortTypeClient service = new ServiceReference1.servicePortTypeClient ("enpointbindingname"); 
service .ClientCredentials.UserName.UserName = "username";          
service .ClientCredentials.UserName.Password = "password";
service.method();

【问题讨论】:

  • 我通常需要反复试验 WCF 配置,您是否尝试过将 httpsTransport 节点中的 authenticationScheme 属性更改为“Basic”?

标签: c# .net web-services soap


【解决方案1】:

从服务器的响应来看,webservice 似乎需要基本的 http 身份验证。这意味着传输级别的身份验证,而不是消息级别的身份验证。所以也许安全配置可能是这样的:

<security mode="Transport">
    <transport clientCredentialType="Basic" />
</security>

如果 web 服务确实使用带有基本身份验证的 HTTPS,那么this msdn page 会详细描述此场景。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-03-06
    • 1970-01-01
    • 2017-06-15
    • 1970-01-01
    • 2012-03-11
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多