我有一个使用基本身份验证的Web服务。我也有一个使用Web服务的Windows窗体应用程序。当它启动时,用户被要求提供凭证,然后在向服务发出任何请求时使用凭证。通过代理与Windows(NTLM)身份验证的基本身份验证访问Web服务
问题是,该应用程序由公司网络内的客户端使用。他们的所有互联网流量都通过使用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服务上执行基本身份验证。
UPDATE
客户端尝试这样做,得到了一个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)
它,当我从我的机器上尝试没有代理工作正常。任何想法为什么?
只要应用程序在用户的上下文中运行(例如,不作为服务帐户中的服务),它似乎应该没问题。 – EricLaw 2011-05-27 20:06:13
哦,你是提琴手!伟大的工具。 – Edgar 2011-05-31 07:25:39