【发布时间】:2016-06-27 19:04:03
【问题描述】:
这就是我目前(并且成功地)连接到 C# 中的 WCF Web 服务的方式。 我无法控制此网络服务,因为它不是我开发的,所以我无法更改它。这是我使用的 C# 代码:
WSHttpBinding binding = new WSHttpBinding();
binding.Security.Mode = SecurityMode.TransportWithMessageCredential;
binding.Security.Message.ClientCredentialType = MessageCredentialType.UserName;
binding.Security.Message.NegotiateServiceCredential = true;
binding.Security.Message.AlgorithmSuite = System.ServiceModel.Security.SecurityAlgorithmSuite.Default;
binding.Security.Message.EstablishSecurityContext = true;
EndpointAddress endpoint = new EndpointAddress("<address>");
fooClient client = new fooClient(binding, endpoint);
client.ClientCredentials.UserName.UserName = "the_username";
client.ClientCredentials.UserName.Password = "the_password";
//fooClient class came from running
// svcutil.exe https://<thedomain>/foo/foo.svc?wsdl
//I now work with fooClient, call methods on it, etc.
我想在不使用 C# 的情况下连接到 Web 服务 - 通过手动创建 SOAP 信封并在端点上执行 POST 请求。我尝试执行如下所示的 POST 请求:
POST /foo/foo.svc HTTP/1.1
Content-Type: application/soap+xml; charset=utf-8
Host: <thedomain>
Connection: close
User-Agent: <my user agent>
Content-Length: 416
<?xml version="1.0" encoding="utf-8"?>
<soap12:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap12="http://www.w3.org/2003/05/soap-envelope">
<soap12:Body>
<someWebServiceFunction xmlns="http://<thedomain>/foo/foo">
<someParameter>some parameter value</someParameter>
</someWebServiceFunction>
</soap12:Body>
</soap12:Envelope>
但这不起作用,因为缺少凭据。 (我收到错误消息:“BadContextToken”、“安全上下文令牌已过期或无效。消息未处理。”)
我的问题是,如何将凭据添加到我的 SOAP 信封/HTTP 请求中?我尝试做普通的 HTTP Basic Auth(在 Authorization HTTP 标头中),但这仍然给我同样的“BadContextToken”错误。
【问题讨论】:
标签: c# web-services wcf post soap