Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Consuming Web Service w/ SOAP Header 1

Status
Not open for further replies.

MadJock

Programmer
May 25, 2001
318
GB
Hi,

I am trying to utilise a web service that expects some additional info in the SOAP header.

I can discover and and add a reference to the web service but the Proxy class created does not deal with the extra header detail.

An example of the SOAP message expected is below:
Code:
<?xml version="1.0" encoding="utf-8"?>
      <soap:Envelope xmlns:soap="[URL unfurl="true"]http://schemas.xmlsoap.org/soap/envelope/"[/URL] xmlns:xsi="[URL unfurl="true"]http://www.w3.org/2001/XMLSchema-instance"[/URL] xmlns:xsd="[URL unfurl="true"]http://www.w3.org/2001/XMLSchema"[/URL] xmlns:wsa="[URL unfurl="true"]http://schemas.xmlsoap.org/ws/2004/08/addressing"[/URL] xmlns:wsse="[URL unfurl="true"]http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd"[/URL] xmlns:wsu="[URL unfurl="true"]http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">[/URL]
        <soap:Header>
          <wsa:Action>[URL unfurl="true"]http://damasifa.unicorn.eu/wse/RunSynchrous</wsa:Action>[/URL]
          <wsa:MessageID>urn:uuid:d4872b6c-c4fa-4330-a4df-926c46d2d17e</wsa:MessageID>
          <wsa:ReplyTo>
            <wsa:Address>[URL unfurl="true"]http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous</wsa:Address>[/URL]
          </wsa:ReplyTo>
          <wsa:To>[URL unfurl="true"]http://damasifa-test.unicorn.eu/wse/DamasService.asmx</wsa:To>[/URL]
          <wsse:Security soap:mustUnderstand="1">
            <wsu:Timestamp wsu:Id="Timestamp-2f687a73-6cf8-4fc9-b5fc-2aaf91aa95eb">
              <wsu:Created>2009-05-11T11:50:08Z</wsu:Created>
              <wsu:Expires>2009-05-11T11:55:08Z</wsu:Expires>
            </wsu:Timestamp>
            <wsse:UsernameToken xmlns:wsu="[URL unfurl="true"]http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd"[/URL] wsu:Id="SecurityToken-48a23f89-ffa6-44b7-bcaf-1b67fc7a6e20">
              <wsse:Username>XXXXXXXXX</wsse:Username>
              <wsse:Password Type="[URL unfurl="true"]http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText">X03MO1qnZdYdgyfeuILPmQ==</wsse:Password>[/URL]
              <wsse:Nonce>4bt7c6LFwDJXeCObE//hoQ==</wsse:Nonce>
              <wsu:Created>2009-05-11T11:50:08Z</wsu:Created>
            </wsse:UsernameToken>
          </wsse:Security>
        </soap:Header>
        <soap:Body>
          <RunSynchrous xmlns="[URL unfurl="true"]http://damasifa.unicorn.eu/wse">[/URL]
            <Input>
              <FID>GETDATETIME</FID>
              <MessageHeader xsi:nil="true" />
              <Parameters />
            </Input>
          </RunSynchrous>
        </soap:Body>
      </soap:Envelope>

If I call a webmethod at present, the SOAP (sniffed) looks like this:
Code:
<?xml version="1.0" encoding="utf-8"?><soap:Envelope xmlns:soap="[URL unfurl="true"]http://schemas.xmlsoap.org/soap/envelope/"[/URL] xmlns:xsi="[URL unfurl="true"]http://www.w3.org/2001/XMLSchema-instance"[/URL] xmlns:xsd="[URL unfurl="true"]http://www.w3.org/2001/XMLSchema"><soap:Body><RunSynchrous[/URL] xmlns="[URL unfurl="true"]http://damasifa.unicorn.eu/wse"><Input><FID>GETDATETIME</FID><MessageHeader[/URL] xsi:nil="true" /></Input></RunSynchrous></soap:Body></soap:Envelope>

As you can see, most of the required attributes are missing.

If it matters, I'm using C# 2.0. An snippet of the web service calling code is here:
Code:
            Damas.DamasService svc = new DamasService(); 
            svc.Proxy = new WebProxy("[URL unfurl="true"]http://myProxy:8080");[/URL] 
            InParams param = new InParams(); 
            param.FID = "GETDATETIME"; 
            OutParams op = svc.RunSynchrous(param);

I'm hoping there is a way to do this without constructing the entire header as a string and using MSXML but I'm not sure where to start.

Any help or pointers greatly appreciated!

"Just beacuse you're paranoid, don't mean they're not after you
 
Did you find a solution to this problem with the damasifa web service?
 
Hi RJTLLC,

Yes I did find the solution. In a nutshell, you need to install WSE 3.0 on the machine that will be making the web service calls.

It also changes your calling code ever so slightly. Post back if you need more information.

Thanks,

Graeme


"Just beacuse you're paranoid, don't mean they're not after you
 
Hello Graeme,

I'm trying to access exactly the same service, can you post your solution? especially the part, where the username token is being constructed. I keep on receiving this "try again later" message.

Thanks

Frank


 
Hi,

With WSE installed, this is the relevant code:
Code:
            System.Net.ServicePointManager.ServerCertificateValidationCallback = new RemoteCertificateValidationCallback(ValidateServerCertificate);
            DamasServiceWse svc = new DamasServiceWse();
            svc.Url = this["URL"];
            svc.Proxy = new WebProxy(this["Proxy"]);
            SoapContext soapContext = svc.RequestSoapContext;
            UsernameToken token = new UsernameToken(this["Username"], GetMd5Hash(this["Password"]), PasswordOption.SendPlainText);

            soapContext.Security.Tokens.Add(token);

            InParams param = new InParams();
            param.FID = "DMSWS_NOM_IN";

            XmlDocument xdoc = new XmlDocument();
            xdoc.Load(filename);
            XmlElement xel = xdoc.DocumentElement;

            XmlParam xp = new XmlParam();
            xp.Name = "XML";
            xp.Any = xel;
            param.Parameters = new ParametersCollection();
            param.Parameters.XmlParam = new XmlParam[] { xp };

            OutParams op = svc.RunSynchrous(param);

My app.config, looks like this:
Code:
  <configSections>
    <section name="microsoft.web.services3" type="Microsoft.Web.Services3.Configuration.WebServicesConfiguration, Microsoft.Web.Services3, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
  </configSections>

Good luck!

Graeme



"Just beacuse you're paranoid, don't mean they're not after you
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top