C# 使用摘要身份验证使用web服务
我们正在使用C#通过SOAP发送XML数据。该服务需要使用C# 使用摘要身份验证使用web服务,c#,web-services,api,digest-authentication,C#,Web Services,Api,Digest Authentication,我们正在使用C#通过SOAP发送XML数据。该服务需要使用#PasswordDigest和#base64二进制Nonce进行HttpDigest身份验证。我们的绑定代码: protected BasicHttpBinding binding = new BasicHttpBinding() { Name = "ShipmentServiceSoapBinding", CloseTimeout = new TimeSpan(0, 01, 0),
#PasswordDigest
和#base64二进制Nonce
进行HttpDigest身份验证。我们的绑定
代码:
protected BasicHttpBinding binding = new BasicHttpBinding()
{
Name = "ShipmentServiceSoapBinding",
CloseTimeout = new TimeSpan(0, 01, 0),
OpenTimeout = new TimeSpan(0, 01, 0),
ReceiveTimeout = new TimeSpan(0, 10, 0),
SendTimeout = new TimeSpan(0, 5, 0),
AllowCookies = false,
BypassProxyOnLocal = false,
HostNameComparisonMode = HostNameComparisonMode.StrongWildcard,
MaxBufferPoolSize = 5242880,
MaxReceivedMessageSize = 655360,
MessageEncoding = WSMessageEncoding.Text ,
TextEncoding = new UTF8Encoding(),
UseDefaultWebProxy = true,
ReaderQuotas = new XmlDictionaryReaderQuotas() { MaxDepth = 32, MaxStringContentLength = 81920, MaxArrayLength = 1638400, MaxBytesPerRead = 409600, MaxNameTableCharCount = 163840 },
Security = new BasicHttpSecurity() { Mode = BasicHttpSecurityMode.TransportWithMessageCredential,
//Message = new BasicHttpMessageSecurity() { AlgorithmSuite = SecurityAlgorithmSuite.Default, ClientCredentialType = BasicHttpMessageCredentialType.UserName},
Transport = new HttpTransportSecurity(){ ClientCredentialType = HttpClientCredentialType.Digest}},
};
根据我们选择的BasicHttpSecurityMode的类型,我们遇到了3个不同的问题
typeClient.ClientCredentials.HttpDigest.ClientCredential.UserName = "username";
typeClient.ClientCredentials.HttpDigest.ClientCredential.Password = "password";
我读过另一个StackOverflow问题,对于digest,我们应该将SoapHeader与AuthHeader一起使用,但我们无法将其与API中提供的内容相匹配。还有别的办法吗?或者是他们的API没有为C#?正确编写在这种情况下使用摘要身份验证要复杂得多-您需要实现
IClientMessageInspector
才能使其正常工作。。。这使您能够以摘要身份验证所需的方式修改http头
有用链接:
IClientMessageInspector
以使其正常工作。。。这使您能够以摘要身份验证所需的方式修改http头
有用链接: