Lot of time webservice host applications don’t define soapHeader specifications in WSDL. However applications require consumers (in this case wM) to send values at soapHeaders level. This post describes two different methods on how to add custom header to WSD consumer request.

There are two ways which I tested to get job done.

  1. Using handleRequestService and addHeaderBlock WmPublic services to add custom header.
  2. Using Dummy handler.

For this post purpose I will be adding three custom fields in soapHeader element.

Username

Password

AccountNumber

1.0     Using addHeaderblock

To achieve custom soapHeaders with add header block. Follow below steps.

1. Create an IS document which have desired fields defined. Set your desired namespace in Universal name property of document. Choose your local name carefully as this will be the name of header document added to connector.

1

 

2. Create a handler Request service which will invoke addHeaderBlock service to add header to request. Implementation of service is explained later. Just create an empty service for purpose of registering handler.

3. Create a service to register handler. Invoke pub.soap.handler:registerWmConsumer inside this to register handler.  Set descriptiveName, handleRequestService name created in previous step. QNameList is the name of local name and namespace used while creating header document. Don’t forget to create startup\shutdown services to register and unregister handler

2

4. Open web service consumer created from WSDL. Go to handler tab of consumer and right click –> Add handler. You will see name of handler registered using service in previous step. Select and add

5. Now go to operation tab and select operation where you want to add header document. Expand operation then request and select Header. Once you select Header add header icon will be enabled in top menu

3

 

Once add header is clicked another pop up will come

4

Select document.

Header document can’t be added if there is no registered handler available.

6. Save connector. Right click webservice consumer and select “Refresh Web Service Connectors” option.

7. Designerwill recreate connector with header document as input.

8. Now if you open connector operation where you added header. It will have a new document added to its input.

9. Next step is to generate headerDocument using service pub.soap.handler:generateDocumentTypesFromWSDL. This is very important step as addHeaderBlock require document generated from WSDL to add header to request. Provide input to service carefully.

10. Now there are two options. Either you setup header values in parent service where connector is invoked or set it inside request handler service. Depends on implementation. If header fields are dynamic then set in parent service otherwise set in request handler service.

11. If you set values in parent service then use pub.soap.handler:getServicePipeline service to access pipeline and header documents and use for creating header block.

12. Implementation of request handler service includes setting up headers and then mapping them to addHeaderBlock service. Screen shot below. I am using getServicePipeline as my requirement was to set dynamic values

5

In addHeaderBlock service invokation Set documentType value to refer to document generated using generateDocumentTypesFromWSDL previously.

13. Save everything and run your connector. It should be sending soapHeader values to receiving application.

2.0     Using Dummy handler and *body document

Using this way we can avoid creating handleRequest service and set headers straight in connector input. Follow below steps to use this method

  1. Create header document for per field basis. For current example where we have to set 3 fields in header. We need to create three documents. Add a field with name *body and Local name in Universal name property should be the name of field which needs to be set in header.

6

 

Similarly create documents for other fields.

  1. Follow step 3 from previous section to register a handler. Difference is you don’t need to provide handler Request service name as input to registerWmConsumer service.
  2. Follow step through 4-8 explained in previous section.
  3. Next is invoke connector in your service and setup header values in PipelineIn option and you should be good to go.

PS – If you don’t have access to host application then use Designer TCP\IP monitor to log soap request.

I tested this with V8.2 and procedure explained above should work with 8.2 and higher version.

Hope this post will help you guys. Comments and suggestions are most welcome.

Please use contact us page, if you need further assistance.

11 Responses

  1. In the very first step while creating document what should be the namespace ? Is it the same as original documents namespace or a new for defining this xml structure.

    1. Namespace needs to be provided by webservice host application. ask them how do they want soapheader to be formed and if they have namespace defined and use that namespace.

      Let me know if you face any issue.

  2. Hi, thanx for solution. I’m new to this product. I dont understand how to do step nine and after.

  3. Can you please provide the sample package for the same.
    in step 3, Set descriptiveName. What the is descriptive name to be set

Leave a Reply

Your email address will not be published. Required fields are marked *