C# .NET SOAP不在请求头中发送基本身份验证
为了与SOAP Web服务通信,我使用了由SvcUtil.exe从wsdl文件创建的C#类 当将下面的请求发送到安全服务器(带有基本身份验证的HTTPS)时,我收到System.ServiceModel.Security.MessageSecurityException,当通过让流量通过Burp代理检查HTTP请求时,我看到没有传递基本身份验证信息。C#代码中是否缺少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();
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年前的事了。