1

I need to connect with one web service and this is all the info I have:

  1. https://www.nameofthecompany.es:8443/webservices/functionIshouldcall?wsdl

  2. Example of call:

    <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:env="http://address.provided.by.the.company.es"> <soapenv:Header> <wsse:Security 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-5"> <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> </wsse:Security> </soapenv:Header> <soapenv:Body> <env:functionIshouldcall> <env:parameter1></env:parameter1> </env:functionIshouldcall> </soapenv:Body> </soapenv:Envelope>

  3. I know this function returns a string;


This is what I have done so far:

  • Created a Service Reference adding just the WSDL address given in point 1.

  • Created an instance of the webservice and called the function with all the needed parameter BUT not the user and password for the header.

How should I proceed? Thanks in advance.

1 Answers1

0

This could be a good place to start if you need to add your credentials; my guess is you might have to, since you got them somehow. The part where you add your credentials is the one below:

UsernameToken userToken = new UsernameToken(userName, password, PasswordOption.SendHashed);
Service1 serviceProxy = new Service1();
SoapContext requestContext = serviceProxy.RequestSoapContext;
requestContext.Security.Tokens.Add(userToken);

In short:

  1. Add your credentials by embedding them in a specific token - whose type belongs to the Microsoft.Web.Services2.Security.Tokens namespace
  2. Create a proxy to your service (in the above example, serviceProxy)
  3. Gain access to its request header via your service's RequestSoapContext
  4. Add the token to the request

Also, I think you might be able to skip the "?wsdl" part in the address as it refers to the web service specification. Once the above is done, you can try to call the function and see how everything works out: if the function has to return something, check whether it's what you were expecting.

Of course don't forget to put your code in a try-catch block, as you might have to check some exception and see what's possibly wrong.

Francesco B.
  • 2,729
  • 4
  • 25
  • 37
  • Link-only answers are generally [frowned upon](http://meta.stackexchange.com/a/8259/204922) on Stack Overflow. In time it is possible for links to atrophy and become unavailable, meaning that your answer is useless to users in the future. It would be best if you could provide the general details of your answer in your actual post, citing your link as a reference. – Yaroslav Surzhikov Sep 24 '17 at 20:18
  • Thank you for reminding me this; however I did include the main code from the link as a countermeasure: wouldn't that suffice? Best regards – Francesco B. Sep 24 '17 at 20:33
  • as far as i can understand - other steps from that link are required too – Yaroslav Surzhikov Sep 25 '17 at 04:59