Click here to Skip to main content
15,887,746 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have this headers in my wcf service endpoint in app.config and it works fine, but I need to have this in code.

XML
<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>


What I have tried:

My service is a WCF service:

I have tried:

C#
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
Posted
Updated 26-Dec-16 20:49pm

1 solution

HI,
Try to use client.headers.Add().

Happy Programming !!!
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900