【发布时间】:2016-03-14 14:47:00
【问题描述】:
我一直在尝试创建一个自定义绑定来输出这种类型的标头 XML:
<soapenv:Header>
<wsse:Security soapenv:mustUnderstand="1" xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
<wsse:UsernameToken wsu:Id="UsernameToken-BEC9D84D8B68A3118D14543420311491">
<wsse:Username>user</wsse:Username>
<wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText">pass</wsse:Password>
<wsse:Nonce EncodingType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0#Base64Binary">hBcjVXk/NxiSiva5xXKphA==</wsse:Nonce>
<wsu:Created>2016-02-01T15:53:51.146Z</wsu:Created>
</wsse:UsernameToken>
</wsse:Security>
到目前为止,这是我的代码:
var customBinding= new CustomBinding();
var securityBindingElement = SecurityBindingElement.CreateUserNameOverTransportBindingElement();
securityBindingElement.IncludeTimestamp = false;
customBinding.Elements.Add(securityBindingElement);
customBinding.Elements.Add(new TextMessageEncodingBindingElement());
var transportElement = new HttpsTransportBindingElement();
customBinding.Elements.Add(transportElement);
但我一直收到一条消息,说明:
The message could not be processed. This is most likely because the action is incorrect or because the message contains an invalid or expired security context token or because there is a mismatch between bindings.
我很确定这与我的自定义绑定有关,但我很难弄清楚哪些属性需要设置为什么。感谢任何指导!!!
【问题讨论】:
-
您的绑定看起来很像我正在工作的自定义绑定 - 尽管我使用了 BinaryMessageEncoding.. 这值得一试
-
谢谢 - 新的错误信息:
The content type text/html of the response message does not match the content type of the binding (application/soap+msbin1). If using a custom encoder, be sure that the IsContentTypeSupported method is implemented properly -
你知道当你在 vs 中加载引用时,你会被问到你想如何处理各种集合 - 我想知道这是否是为你做的......stackoverflow.com/questions/11135392/…谈论这个错误
-
好吧,当我使用 wshttp 绑定时,它几乎创建了我需要的 XML,除了标题部分中的 4 或 5 个额外节点。在我的研究之后,我被告知要创建一个自定义绑定,但对我来说,断开连接是如何创建一个自定义绑定来模仿 wshttp 绑定,但我不想显示的节点除外
-
有时巫师自己也会对自己的魔法感到惊讶。 (这是关于一般的 XAML 技术):-)