我有一個使用基本身份驗證的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