我遇到了这个问题,我无法解决。我对Google和Stackoverflow进行了大量研究,尝试了很多变化,但还没有解决这个问题。
我在尝试将xml请求传递给我正在集成的API时使用WS-Security标头。我的代码如下所示:
var binding = new WSHttpBinding();
binding.Security.Mode = SecurityMode.TransportWithMessageCredential;
binding.Security.Transport.ClientCredentialType = HttpClientCredentialType.Basic;
binding.Security.Message.ClientCredentialType = MessageCredentialType.UserName;
binding.UseDefaultWebProxy = true;
binding.BypassProxyOnLocal = false;
var endPoint = new EndpointAddress(new Uri("myendpointurl"));
client = new MyWebService(binding, endPoint);
client.ClientCredentials.UserName.UserName = username;
client.ClientCredentials.UserName.Password = password;
// I use this to view the generated XML
client.Endpoint.EndpointBehaviors.Add(new myCustomInspector());
client.Execute();
现在正在使用UsernameToken
的零引用生成的XML<s:Envelope xmlns:a="http://www.w3.org/2005/08/addressing" xmlns:s="http://www.w3.org/2003/05/soap-envelope">
<s:Header>
<a:Action s:mustUnderstand="1">...removed...</a:Action>
<a:MessageID>urn:uuid:c304f179-8a25-40f4-a84e-dc5081be573e</a:MessageID>
<a:ReplyTo>
<a:Address>http://www.w3.org/2005/08/addressing/anonymous</a:Address>
</a:ReplyTo>
</s:Header>
<s:Body>.......
我完全不知道下一步该做什么,我已经尝试了很多变化但是在我的生活中不能得到UsernameToken来生成