我正在使用.Net 3.5並嘗試配置WCF服務並且正在接收異常,HTTP請求未經客戶端身份驗證方案「協商」授權。從服務器收到的驗證頭是'Negotiate,NTLM'。我在下面附加了我的服務器端和客戶端.config文件。
只是幾個筆記。由於網絡訪問要求,應用程序和服務都使用模擬。 Web應用程序駐留在與WCF服務不同的服務器上。兩者都在其各自的web.config文件中指定了以下內容。WCF認證方案不匹配?
<authentication mode="Windows"/>
<identity impersonate="true" userName="userName" password="password"/>
Web應用程序(Server1上)
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="BasicHttpBinding_IReports" 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="false" proxyAddress="http://server2/Services/ReportService">
<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 name="BasicHttpBinding_IReports" address="http://server2/Services/ReportService/Reports.svc"
binding="basicHttpBinding" contract="WCFServiceRef.IReports" bindingConfiguration="BasicHttpBinding_IReports"
behaviorConfiguration="ClientBehavior"/>
</client>
<behaviors>
<endpointBehaviors>
<behavior name="ClientBehavior" >
<clientCredentials supportInteractive="true" >
<windows allowedImpersonationLevel="Impersonation" allowNtlm="true" />
</clientCredentials>
</behavior>
</endpointBehaviors>
</behaviors>
</system.serviceModel>
WCF服務(Server2上)
<system.serviceModel>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true"/>
<bindings>
<basicHttpBinding>
<binding name="default" maxReceivedMessageSize="200000">
<readerQuotas maxStringContentLength="200000" maxArrayLength="200000"/>
<security mode="TransportCredentialOnly">
<transport clientCredentialType="Windows" proxyCredentialType="None" realm="" />
<message clientCredentialType="UserName" algorithmSuite="Default" />
</security>
</binding>
</basicHttpBinding>
</bindings>
<services>
<service behaviorConfiguration="ReportService.ReportsBehavior" name="ReportService.Reports">
<endpoint address="" binding="basicHttpBinding" contract="ReportService.IReports" bindingConfiguration="default">
<identity>
<dns value="localhost"/>
</identity>
</endpoint>
<endpoint name="mex" address="mex" binding="basicHttpBinding" contract="IMetadataExchange" bindingConfiguration="default"/>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="ReportService.ReportsBehavior">
<serviceAuthorization impersonateCallerForAllOperations="false"/>
<serviceMetadata httpGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="false"/>
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
我想,如果我是在應用程序中,這將適用allowNtlm="true"
指令被修復。在我看來,服務器期待Windows身份驗證,但沒有收到它?由於應用程序和服務駐留在不同的服務器上,我是否需要使用代理值?我覺得我沒有理解一些基本的東西,不管它是在服務器端的IIS配置還是在我的應用程序中,我不知道。 感謝您的幫助!
我會看看你提供的鏈接,但我已經嘗試過許多設置的變化。我相信我的初始配置沒有消息指令。我與服務器操作組通話,他們確認IIS配置爲支持Windows身份驗證。 – McArthey
您提供的鏈接中有一個重要提示。 「...將WCF服務的Web引用添加到您的客戶端應用程序,本文如何使用Web引用來顯示WCF服務作爲舊Web服務的用法;否則,您可以將其添加爲服務引用。 「看起來這可能是我的伎倆。雖然具體爲什麼,我不確定。 – McArthey