0 votes
by (72.7k points)

(Note, this was originally asked at comment)

We got an Requirement for OpenUI , that we need to add the Header with credential and session Tokens attribute as part of Request , and parse the Header also after response.

SOAP REQUEST:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:cus="http://siebel.com/CustomUI" xmlns:fin="http://www.siebel.com/xml/FindLotInfo">
    <soapenv:Header>
      <UsernameToken xmlns="http://siebel.com/webservices">Username</UsernameToken>
      <PasswordText xmlns="http://siebel.com/webservices">Password</PasswordText>
      <SessionType xmlns="http://siebel.com/webservices">Stateless</SessionType>
   </soapenv:Header>
   <soapenv:Body>
      <cus:ATLFindLotInfoProcess_Input>
         <fin:FindLotInfo>
            <fin:findLotInfoReqData>
           ..................
         </fin:FindLotInfo>
      </cus:ATLFindLotInfoProcess_Input>
   </soapenv:Body>
</soapenv:Envelope>

SOAP RESPONSE:

<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
   <SOAP-ENV:Header>
      <siebel-header:SessionToken xmlns:siebel-header="http://siebel.com/webservices">y3dgzHgjMNDAroudyW3FdqDjRzjMJN.cHyU6rOlrsSVJvLrgcCEioOo29u502bo4HSnV3k9s4HhVNCuOP6oXaaUVSUbTaaxpVcNx2eks55Uvk0LCJzVvSBw5AkGUfs-b95OYNVHRGw7SGc49tOpjCRorlqabXXLmhqhnL1y8haqLLZDnZ5ORvQNWj8Q-p1oPG6LhYg1UQWeUf.-GwrR.WN7yLlr8v0kWjXTynLJao3ogQKJytT5ymzAnhJLIrYs8m18McEwFVv09i5K-B1-RvlXhq2t38g3vb3fbCmKyaFoJgy1jP0CcsA__</siebel-header:SessionToken>
   </SOAP-ENV:Header>
   <SOAP-ENV:Body>
      <ns:ATLFindLotInfoProcess_Output xmlns:ns="http://siebel.com/CustomUI">
         <FindLotInfoResponse xmlns="http://www.siebel.com/xml/FindLotInfoResponse">
            <findLotInfoReplyData>
             .......................
         </FindLotInfoResponse>
      </ns:ATLFindLotInfoProcess_Output>
   </SOAP-ENV:Body>
</SOAP-ENV:Envelope>
  • as per above sample Request /Resonse(using soaUI Tool) - I need to add the Header along with Request Body and I need to Parse the Header in Reponse as well.

    Please guide me on this.

  • am using the wcfRequestChannels.cs file which I took from Rebex sample http projects

where we adding header as below

    string action = message.Headers.Action;

    request.Method = "POST";
    request.Headers.Add("SOAPAction", '"' + action + '"');
    request.Headers.Add("Content-Type", "text/xml; charset=utf-8");
  • I need to add further information on this.

Regards
Raj

Applies to: Rebex HTTPS

2 Answers

0 votes
by (72.7k points)
 
Best answer

I have uploaded new version of RebexWcfBinding with support for custom SOAP headers.

It is available at here.

It introduces new WcfMessageObserver class, which can be used like this:

    var binding = new Rebex.Samples.WcfBinding();
    // configure RequestCreator if necessary
    // binding.RequestCreator.Settings...

    // create service
    var client = new DemoWebServiceSoapClient(binding,
        new EndpointAddress("http://test.rebex.net/demowebservice.asmx"));

    // attach observer for next service call(s)
    using (var observer = new Rebex.Samples.WcfMessageObserver(binding))
    {
        // add some custom headers to outgoing SOAP message(s)
        observer.OutgoingHeaders.Add(new Rebex.Samples.WcfMessageHeader("A", "NS", "Temp1"));
        observer.OutgoingHeaders.Add(new Rebex.Samples.WcfMessageHeader("B", "NS", "Temp2"));

        // call the service
        var response = client.HelloWorld();

        // read SOAP headers of the most recent response
        foreach (var h in observer.IncomingHeaders)
        {
            // h.Name, h.Value, ...
        }
    }

It is also possible to create own IWcfMessageObserver implementation and attach it to WcfBinding.MessageObservers manually.

0 votes
by (72.7k points)

The request.Headers.Add() method adds HTTP headers (not SOAP message headers).

To add SOAP message headers, just simply add them to message.Headers collection after line 'message.Headers.Clear();' like this:

message.Headers.Clear();
message.Headers.Add(MessageHeader.CreateHeader("UsernameToken", "http://siebel.com/webservices", "a user name"));
message.Headers.Add(MessageHeader.CreateHeader("PasswordText", "http://siebel.com/webservices", "a password"));
message.Headers.Add(MessageHeader.CreateHeader("SessionType", "http://siebel.com/webservices", "Stateless"));

To read them, just read from responseMessage.Headers collection.

by (110 points)
edited by
Thank You Lukas, I will ask server team to look in this  - I mean while I will check to implement the device.
by (110 points)
http://forum.rebex.net/message/Lukas+Matyska
This is follow up - above discussion.
Hi Lukas,
  I have checked in other components
  we are not calling  -  Register() method for system binding  - we will comment the Rebex wcf and collect the logs.
by (72.7k points)
I was not talking about Register() method for system binding, I was talking about Register() method for Rebex binding. Very probably: Rebex.Samples.WcfBinding.RequestCreator.Register()

Just look in your whole solution for "Register" method, and if it is called on instance of Rebex.Net.HttpRequestCreator comment it out .
by (110 points)
Hi Lukas,
  Thanks for the suggestion - I have commented the Register method while creating the Binding for Rebex.
After This also
1.Call  Rebex Call -   No issue
2.Call System Http  binding call  - Get Webrequest
   - I will convert all system http bingding call to Rebex and try out an update the status. Please let me know  even without header also will also we need to call rebex under observer - my understanding is correct?

using (var observer = new Rebex.Samples.WcfMessageObserver(binding))
                {
client call....


}
by (72.7k points)
If you don't need to access headers, you don't need to use observer at all.
...