我必须从C#.NET连接到SOAP服务,但该服务只接受带有http身份验证头的请求。
似乎(根据我到目前为止的谷歌搜索),通过Http头进行身份验证并不是SOAP的标准,但我不能对SOAP服务进行任何更改。
注意:我不是在谈论SOAP头。
我可以设置http身份验证,并使用SoapUI成功发出请求,如下所示:

关于SoapUI在幕后做什么,我可能是错的--这是http认证,对吗?
我已经将WSDL导入到我的Visual Studio项目中,并且可以尝试发出请求,但我得到了一个"401 -未授权( HTTP请求未授权,客户端身份验证方案为‘匿名’)“。当然是错误的。
我想以如下方式调用该服务:
public List<string> GetVinsForUser(string customerId)
{
var client = new CustomerService.VehicleClient();
// client.HttpHeaders.Add("username", "SomeUser");
// client.HttpHeaders.Add("password", "SomePassword");
var result = client.findCustomerPlusVehicles(customerId);
return result.Vehicles.ToList();
}到目前为止,我看到的所有相关文章似乎都暗示,对于SOAP的.NET实现来说,没有像这样简单的属性。
我知道我可以将soap xml数据发送到手动构建整个don请求的端点,但我真的不想这样做!
有没有什么方法可以启用这种身份验证,甚至通过扩展/覆盖生成的Client类的行为?
发布于 2014-10-25 00:04:58
不要试图直接修改soap标头,只需让.net修改标头:
// windows credential
client.ClientCredentials.Windows.ClientCredential = new NetworkCredential("yourUsername", "yourPassword", "yourDomain.com");
// you can also try this
client.ClientCredentials.UserName.UserName = "yourUsername";
client.ClientCredentials.UserName.Password = "yourPassword";https://stackoverflow.com/questions/20248249
复制相似问题