[英]How to add custom header to outgoing SOAP payload using a Connected Service?
我需要为使用HTTPS端点发送到项目中的某个连接服务的每个有效负载添加自定义标头。 该自定义标头将用作接收器的身份验证。 我怎样才能做到这一点?
我试过使用System.ServiceModel.Channels.MessageHeader
和AddressHeader
没有运气。 使用SoapUI,在请求中添加自定义标头可以正常工作。
这种认证方法对接收者来说是新的。 还有HTTPS端点。 在以前的请求中,我使用Basic Http Authentication
和用户名和密码。 所以,我改变了一点来支持HTTPS绑定代码是:
BasicHttpsBinding basicAuthBinding = new BasicHttpsBinding(BasicHttpsSecurityMode.Transport);
basicAuthBinding.Security.Transport.ClientCredentialType = HttpClientCredentialType.Basic;
EndpointAddress basicAuthEndpoint = new EndpointAddress("https://whatever");
MyConnectedService.MyOperationClient client = new MyConnectedService.MyOperationClient(basicAuthBinding, basicAuthEndpoint);
client.ClientCredentials.UserName.UserName = "user";
client.ClientCredentials.UserName.Password = "pass";
client.send(payload);
我相信在这里的某个地方我需要添加自定义标题。
使用此代码,我得到了预期的HTTP 401 - Unauthorized
。
帮助赞赏。
先感谢您。
如果您接受静态自定义标头,则可以尝试使用web.config(app.config)。
<endpoint address="http://ws-wuxipc-5077:4000/calculator" binding="basicHttpBinding"
contract="ServiceInterface.CustomHeader" name="header">
<headers>
<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"
xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
<wsse:Username>
</wsse:Username>
<wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordDigest">monMonDePasse</wsse:Password>
<wsse:Nonce>sdsdsdlojhfdsdM5Nw==</wsse:Nonce>
<wsu:Created>2019-01-21T6:17:34Z</wsu:Created>
</wsse:UsernameToken>
</Security>
</headers>
</endpoint>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.