Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/solr/3.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# .NET SOAP不在请求头中发送基本身份验证_C#_.net_Soap_Basic Authentication - Fatal编程技术网

C# .NET SOAP不在请求头中发送基本身份验证

C# .NET SOAP不在请求头中发送基本身份验证,c#,.net,soap,basic-authentication,C#,.net,Soap,Basic Authentication,为了与SOAP Web服务通信,我使用了由SvcUtil.exe从wsdl文件创建的C#类 当将下面的请求发送到安全服务器(带有基本身份验证的HTTPS)时,我收到System.ServiceModel.Security.MessageSecurityException,当通过让流量通过Burp代理检查HTTP请求时,我看到没有传递基本身份验证信息。C#代码中是否缺少SOAP请求的任何内容,或者基本身份验证不起作用的问题是什么 var binding = new WSHttpBinding();

为了与SOAP Web服务通信,我使用了由SvcUtil.exe从wsdl文件创建的C#类

当将下面的请求发送到安全服务器(带有基本身份验证的HTTPS)时,我收到System.ServiceModel.Security.MessageSecurityException,当通过让流量通过Burp代理检查HTTP请求时,我看到没有传递基本身份验证信息。C#代码中是否缺少SOAP请求的任何内容,或者基本身份验证不起作用的问题是什么

var binding = new WSHttpBinding();
binding.MessageEncoding = WSMessageEncoding.Mtom;

binding.Security.Mode = SecurityMode.Transport;
binding.Security.Transport.ClientCredentialType = HttpClientCredentialType.Basic;
binding.Name = "BasicAuthSecured";

SearchServicePortClient searchClient = new SearchServicePortClient(binding,  new EndpointAddress("https://myUrl:Port/myService"));
searchClient.ClientCredentials.UserName.UserName = "username";
searchClient.ClientCredentials.UserName.Password = "pw";

query soap = new query();
//...

queryResponse response = searchClient.query(soap);

提前感谢

尝试使用TransportWithMessageCredential:

binding.Security.Mode = SecurityMode.TransportWithMessageCredential;

这是另一种方法,但不知道它是否是最好的

using (var client = _clientFactory.GetClient())
{
    var credentials = Utils.EncodeTo64("user123:password");
    client.ChannelFactory.CreateChannel();
    using (OperationContextScope scope = new OperationContextScope(client.InnerChannel))
    {
        var httpRequestProperty = new HttpRequestMessageProperty();
        httpRequestProperty.Headers[HttpRequestHeader.Authorization] = "Basic " + credentials;
        OperationContext.Current.OutgoingMessageProperties[HttpRequestMessageProperty.Name] = httpRequestProperty;
        //operation
        client.Send(request);
    }
}

对不起,我不记得是3年前的事了。