简体   繁体   English

自定义绑定C#WCF

[英]Custom binding c# WCF

I would like to add a security header to my WCF SOAP message that looks like the following: 我想向我的WCF SOAP消息中添加一个安全标头,如下所示:

<s:Header>
<Action s:mustUnderstand="1" xmlns="http://schemas.microsoft.com/ws/2005/05/addressing/none">URLWithAction</Action>
<Security xmlns="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
  <wsse:UsernameToken xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
    <wsse:Username>Username</wsse:Username>
    <wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText">Password</wsse:Password>
  </wsse:UsernameToken>
</Security>
</s:Header>

Yet, I am unable to figure out if this can be done with basicHttpBinding or another standard one, or if I have to make a custom one and how I can make a custom one... Is anyone able to help? 但是,我无法弄清楚这是否可以使用basicHttpBinding或其他标准版本来完成,或者是否必须定制一个以及如何定制一个……有人可以提供帮助吗?

It turned out that I had to play a bit more with the attributes for the security element in my custom binding. 事实证明,我在自定义绑定中必须更多地使用security元素的属性。 I added the tag includeTimestamp="false" and then the security header worked, even though the action element was not added to the header. 我添加了标记includeTimestamp =“ false”,然后安全头起作用了,即使未将action元素添加到头也是如此。

Final result of the custombinding was: 自定义绑定的最终结果是:

<customBinding>
 <binding name="BasicHttpBinding_WebService">
  <textMessageEncoding messageVersion="Soap11" writeEncoding="utf-8" />
  <security authenticationMode="UserNameOverTransport" 
            includeTimestamp="false"/>
  <httpsTransport />
 </binding>
 <binding name="BasicHttpBinding_WebService1"/>
</customBinding>

如果要在服务器或客户端上添加消息,请查看此答案。 如何为每个WCF调用添加自定义HTTP标头?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM