通过具有Windows(NTLM)身份验证的代理访问具有基本身份验证的Web Service
||
我有一个使用基本身份验证的Web服务。我也有一个使用Web服务的Windows Forms应用程序。启动时,系统会要求用户提供凭据,然后在向服务提出任何请求时使用这些凭据。
问题是,该应用程序由公司网络中的客户端使用。他们的所有Internet通信都通过使用Windows身份验证的代理进行路由。我正在尝试将我的应用程序配置为在发出请求时正确使用该代理。
到目前为止,我的客户端应用程序的app.config中包含以下内容:
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name=\"mySoap\" closeTimeout=\"00:02:00\" openTimeout=\"00:02:00\"
receiveTimeout=\"00:10:00\" sendTimeout=\"00:02:00\" allowCookies=\"false\"
bypassProxyOnLocal=\"true\" 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=\"Basic\" proxyCredentialType=\"Windows\"
realm=\"myrealm\" />
<message clientCredentialType=\"UserName\" algorithmSuite=\"Default\" />
</security>
</binding>
</basicHttpBinding>
</bindings>
<client>
<endpoint address=\"http://www.myservice.com/service.asmx\"
binding=\"basicHttpBinding\" bindingConfiguration=\"mySoap\"
contract=\"MyPublicService.mySoap\" name=\"mySoap\" />
</client>
</system.serviceModel>
<system.net>
<defaultProxy useDefaultCredentials=\"true\" />
</system.net>
您认为这行得通吗?我无法轻松对其进行测试。应用程序和服务已在没有代理的情况下进行了测试,它们可以正常工作,我只需要正确配置代理即可。
从理论上讲,此配置将确保所有请求都使用默认代理,该默认代理使用Windows身份验证。它将使用默认凭据,该凭据将在其Windows设置中设置。然后,它将使用用户提供的凭据对Web服务执行基本身份验证。
更新
客户端尝试了此操作,并返回了400错误:
System.ServiceModel.ProtocolException: The remote server returned an unexpected response: (400) Bad Request. ---> System.Net.WebException: The remote server returned an error: (400) Bad Request.
at System.Net.HttpWebRequest.GetResponse()
at System.ServiceModel.Channels.HttpChannelFactory.HttpRequestChannel.HttpChannelRequest.WaitForReply(TimeSpan timeout)
--- End of inner exception stack trace ---
Server stack trace:
at System.ServiceModel.Channels.HttpChannelUtilities.ValidateRequestReplyResponse(HttpWebRequest request, HttpWebResponse response, HttpChannelFactory factory, WebException responseException, ChannelBinding channelBinding)
at System.ServiceModel.Channels.HttpChannelFactory.HttpRequestChannel.HttpChannelRequest.WaitForReply(TimeSpan timeout)
at System.ServiceModel.Channels.RequestChannel.Request(Message message, TimeSpan timeout)
at System.ServiceModel.Dispatcher.RequestChannelBinder.Request(Message message, TimeSpan timeout)
at System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[] outs, TimeSpan timeout)
at System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCallMessage methodCall, ProxyOperationRuntime operation)
at System.ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessage message)
当我在没有代理的机器上尝试时,它工作正常。知道为什么吗?
没有找到相关结果
已邀请:
1 个回复
峨躬坎抬焚