Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/300.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 使用摘要身份验证使用web服务_C#_Web Services_Api_Digest Authentication - Fatal编程技术网

C# 使用摘要身份验证使用web服务

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),

我们正在使用C#通过SOAP发送XML数据。该服务需要使用
#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个不同的问题

  • 传输-XML不包含任何安全信息
  • TransportCredentialOnly-我们得到的错误表明端点不能是https://
  • TransportWithMessagecredential-这不是使用摘要
  • 现在,他们的ServiceReference允许我们使用ClientCredentials类,下面是我们尝试使用HttpDigest的方法:

    typeClient.ClientCredentials.HttpDigest.ClientCredential.UserName = "username";
    typeClient.ClientCredentials.HttpDigest.ClientCredential.Password = "password";
    

    我读过另一个StackOverflow问题,对于digest,我们应该将SoapHeader与AuthHeader一起使用,但我们无法将其与API中提供的内容相匹配。还有别的办法吗?或者是他们的API没有为C#?

    正确编写在这种情况下使用摘要身份验证要复杂得多-您需要实现
    IClientMessageInspector
    才能使其正常工作。。。这使您能够以摘要身份验证所需的方式修改http头

    有用链接:


    在此场景中使用摘要身份验证要复杂得多-您需要实现
    IClientMessageInspector
    以使其正常工作。。。这使您能够以摘要身份验证所需的方式修改http头

    有用链接: