如何在WCF服务中添加标头? [英] How to add headers in WCF service?

查看:112
本文介绍了如何在WCF服务中添加标头?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在app.config中的wcf服务端点中有这个标题,它工作正常,但我需要在代码中使用它。



I have this headers in my wcf service endpoint in app.config and it works fine, but I need to have this in code.

<endpoint address="https://10.275.138.219:8443/soap/efecty/" binding="basicHttpBinding" bindingConfiguration="PlacetoPay_EfectyBinding" contract="ServicioPlaceToPay.PlacetoPay_EfectyPort" name="PlacetoPay_EfectyPort">
              <headers>
                <wsse:Security xmlns:wsse="http://docs.oasis-...">
                  <wsse:UsernameToken>
                    <wsse:Username>juan</wsse:Username>
                    <wsse:Password>password*</wsse:Password>
                  </wsse:UsernameToken>
                </wsse:Security>
              </headers>
            </endpoint>





我的尝试:



我的服务是WCF服务:



我试过了:





What I have tried:

My service is a WCF service:

I have tried:

SecurityBindingElement securityElement = SecurityBindingElement.CreateUserNameOverTransportBindingElement();
                securityElement.IncludeTimestamp = false;
                TextMessageEncodingBindingElement encodingElement = new TextMessageEncodingBindingElement(MessageVersion.Soap11, Encoding.UTF8);
                HttpsTransportBindingElement transportElement = new HttpsTransportBindingElement();

                CustomBinding customBinding = new CustomBinding(securityElement, encodingElement, transportElement);

                EndpointAddress endpoint = new EndpointAddress(this.urlServicio);

                ServicioPlaceToPay.PlacetoPay_EfectyPortClient client = new ServicioPlaceToPay.PlacetoPay_EfectyPortClient(customBinding, endpoint);

                client.ClientCredentials.UserName.UserName = "juan";
                client.ClientCredentials.UserName.Password = "password*";
                
                resultadoConsulta = client.settlePayment(solicitud);





但它不起作用,它抛出一个授权错误。



谢谢



but it doesn't work, it throws an authentication error.

thanks

推荐答案

HI,

尝试使用client.headers .Add()。



快乐编程!!!

Try to use client.headers.Add().

Happy Programming !!!


这篇关于如何在WCF服务中添加标头?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆