How to add headers for a Java WS Client?
0 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Balaji_Kithiganahalli
Posted On:   Monday, August 11, 2003 12:42 PM

I have a .Net based Webservice for which I am trying to create a Java based client. I am using IBM WSTK 3.3 and Tomcat. The problem I am having is to add a header to the soap request. When I add a header, .Net Webservice is not able to get the values that are being passed. where as when I create a .Net client, it works fine without any problem. The following is the code I am using for Java Client. //Code Begins try { Service service = new com.ibm.wstk.axis.client.WSTKService(session); Call call = (Call) service.createCall(); DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); DocumentBuilder builder = factory.newDocumentBuilder(); Document do   More>>

I have a .Net based Webservice for which I am trying to create a Java based client. I am using IBM WSTK 3.3 and Tomcat. The problem I am having is to add a header to the soap request. When I add a header,
.Net Webservice is not able to get the values that are being passed. where as when I create a .Net client, it works fine without any problem. The following is the code I am using for Java Client.

//Code Begins

			
try
{

Service service = new com.ibm.wstk.axis.client.WSTKService(session);
Call call = (Call) service.createCall();

DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
DocumentBuilder builder = factory.newDocumentBuilder();

Document doc = builder.newDocument();
Element elem = doc.createElementNS("http://tempuri.org","AuthHeader");
Element username = doc.createElement("UserName");
username.appendChild(doc.createTextNode("itsme"));
elem.appendChild(username);
Element password = doc.createElement("Password");
password.appendChild(doc.createTextNode("hellothere"));
elem.appendChild(password);

call.setTargetEndpointAddress(new URL("http://localhost/ComplexTypeWS/AddWS.asmx"));

SOAPHeaderElement he = new SOAPHeaderElement(elem);
call.addHeader(he);
call.addParameter(new javax.xml.namespace.QName("http://tempuri.org", "x"), new javax.xml.namespace.QName("http://www.w3.org/2001/XMLSchema", "double"), double.class, javax.xml.rpc.ParameterMode.IN);
call.addParameter(new javax.xml.namespace.QName("http://tempuri.org", "y"), new javax.xml.namespace.QName("http://www.w3.org/2001/XMLSchema", "double"), double.class, javax.xml.rpc.ParameterMode.IN);
call.setReturnType(new javax.xml.namespace.QName("http://www.w3.org/2001/XMLSchema", "double"), double.class);
call.setUseSOAPAction(true);
call.setSOAPActionURI("http://tempuri.org/Divide");
call.setOperationName(new javax.xml.namespace.QName("http://tempuri.org", "Divide"));

ret = (Double)call.invoke( new Object[] {number1,number2});

out.println("Result is "+ret);
}
catch (Exception e)
{
out.println(e);
}

//Code Ends

I am logging the soap messages and both looks alike. Here are the Soap Requests
//.Net Client Soap Request
-----SoapRequest at 8/11/2003 10:59:40 AM

<?xml version="1.0" encoding="utf-8"?> itsme hellothere 10 2

//Java Client Soap Request

-----SoapRequest at 8/11/2003 11:03:54 AM

<?xml version="1.0" encoding="utf-8"?>

itsme hellothere


20.0
10.0




Anybody got a clue what I am missing on Java Client

Thanks    <<Less
About | Sitemap | Contact