以下SOAP操作采用搜索参数并返回搜索结果对象:
public static void SearchWebServiceClient()
{
SearchWebServiceClient client = new SearchWebServiceClient(); // Creates client
client.ClientCredentials.UserName.UserName = "someUsername"; // Assigns client credentials
client.ClientCredentials.UserName.Password = "somePassword";
client.ClientCredentials.Windows.AllowedImpersonationLevel = System.Security.Principal.TokenImpersonationLevel.Impersonation;
searchForComponents componentSearch = new searchForComponents(); // Creates operation
searchForComponentsResponse componentSearchResponse = new searchForComponentsResponse(); // Creates operation response
componentSearch.searchTerm = "someSearchTerm"; // The parameter being passed to the operation
componentSearchResponse = client.searchForComponents(componentSearch); // Sends request. Exception happens here.
}
发出请求时,会导致此异常:
$ exception {“HTTP请求未经授权与客户端 认证方案'谈判'。收到身份验证标头 从服务器是'Basic realm = \“EJBWebServiceEndpointServlet Realm \“'。”} System.Exception {System.ServiceModel.Security.MessageSecurityException}
App.config中:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5"/>
</startup>
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="SearchWebServiceBinding"
closeTimeout="00:01:00"
openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
maxBufferSize="65536" maxBufferPoolSize="524288" maxReceivedMessageSize="65536"
messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered"
useDefaultWebProxy="true">
<readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
maxBytesPerRead="4096" maxNameTableCharCount="16384" />
<security mode="TransportCredentialOnly">
<transport clientCredentialType="Windows" proxyCredentialType="None" realm=""/>
<message clientCredentialType="UserName" algorithmSuite="Default"/>
</security>
</binding>
</basicHttpBinding>
</bindings>
<client>
<endpoint address="http://someaddress.com:80/somedirectory/somedirectory/search-service?wsdl"
binding="basicHttpBinding" bindingConfiguration="SearchWebServiceBinding"
contract="SearchWebService.SearchWebService" name="Search" />
</client>
</system.serviceModel>
</configuration>
服务器在我的网络外部托管,我无法查看/编辑其配置。
有谁知道可能导致这种情况的原因?提前谢谢!
答案 0 :(得分:0)
问题在于这一行:
<transport clientCredentialType="Windows" proxyCredentialType="None" realm=""/>
您想要进行Windows身份验证,即Negotiate。尝试将其更改为:
<transport clientCredentialType="Basic" proxyCredentialType="None" realm=""/>