我尝试调用具有Windows身份验证的外部服务,它在我在IIS中运行的Windows开发计算机上工作正常但是一旦我将该网站发布到Azure,它就无法通过该服务进行身份验证,即使配置是一样的。我得到的错误是,
System.ServiceModel.Security.MessageSecurityException:
The HTTP request is unauthorized with client authentication scheme 'Negotiate'.
The authentication header received from the server was 'Negotiate'. --->
System.Net.WebException: The remote server returned an error: (401) Unauthorized.
感觉就像Azure一样,它甚至没有尝试过身份验证。
服务的配置如下所示
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="Custom_Binding" maxBufferSize="2147483647" maxReceivedMessageSize="2147483647" maxBufferPoolSize="524288" receiveTimeout="00:20:00" sendTimeout="00:20:00">
<readerQuotas maxDepth="32" maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />
<security mode="TransportCredentialOnly">
<transport clientCredentialType="Windows" />
</security>
</binding>
</basicHttpBinding>
</bindings>
<client>
<endpoint address="http://www.otherdomain.com/webServiceRequest" binding="basicHttpBinding" bindingConfiguration="Custom_Binding" contract="webServiceRequest_Port" name="webServiceRequest_Port" />
</client>
</system.serviceModel>
这是发出请求的c#代码,
var client = new webServiceRequest_PortClient();
client.ClientCredentials.UserName.UserName = "domain\Username";
client.ClientCredentials.UserName.Password = "Password";
var response = await client.PerformServiceAsync(method, request);
/尤
答案 0 :(得分:0)
如果设置Windows凭据,它是否有效?
var client = new webServiceRequest_PortClient();
client.ClientCredentials.Windows.ClientCredential.UserName = "domain\Username";
client.ClientCredentials.Windows.ClientCredential.Password = "Password";
var response = await client.PerformServiceAsync(method, request);
答案 1 :(得分:0)
System.ServiceModel.Security.MessageSecurityException:
The HTTP request is unauthorized with client authentication scheme 'Negotiate'.
The authentication header received from the server was 'Negotiate'. --->
System.Net.WebException: The remote server returned an error: (401) Unauthorized
根据例外情况,我假设您将网站发布到Azure WebApp。
如果我们要使用Windows Authenticated,我们需要确保为Web服务器启用了Windows身份验证。我们可以remote to Azure website检查“身份验证”选项下是否没有Windows身份验证,详情请参阅屏幕截图。
如果Azure可以提供服务,可以使用Azure cloud service作为解决方法。