[英]Exception thrown when connecting to web service
我在從.NET Windows應用程序通過HTTPS消費java Web服務時遇到問題。 Web服務需要服務器身份驗證,但是當我嘗試調用任何方法時,我收到了follor錯誤:
HTTP請求未經授權,客戶端身份驗證方案為“匿名”。 從服務器收到的身份驗證標頭是“Basic realm = login”。
我在Web Studio中添加了Web服務作為服務引用。 這是我的應用配置:
在<security>
部分,我有這個:
<security mode="Transport">
transport clientCredentialType="None" proxyCredentialType="None"
realm="" />
<message clientCredentialType="UserName" algorithmSuite="Default" />
</security>
在<httpsTransport>
部分中,我有:
<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();
從服務器的響應來看,Web服務看起來需要基本的http身份驗證。 這意味着在傳輸級別而不是消息級別進行身份驗證。 所以安全配置也許就是這樣:
<security mode="Transport">
<transport clientCredentialType="Basic" />
</security>
如果Web服務確實使用HTTPS和基本身份驗證,則此msdn頁面將詳細描述此方案。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.