【问题标题】:Converting a WCF (svcutil) C# code into the corresponding SOAP envelope POST request将 WCF (svcutil) C# 代码转换为相应的 SOAP 信封 POST 请求
【发布时间】: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


    【解决方案1】:

    有两种简单的方法可以解决您的问题:

    1. 如果您使用Visual Studio,在调试时,发送请求并截取请求中的详细内容,您可以使用纯HTTP POST 模拟它。

    2. 如果您可以使用 SoapUI,则可以使用 SoapUI 定位服务并发送一个工作请求,在原始选项卡中,您将看到已接受的带有凭据的请求。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-11-02
      • 1970-01-01
      • 1970-01-01
      • 2011-10-12
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多