Meaningless Drivel is fun!*
The moose likes Web Services and the fly likes wsdl stubs adding own namespace around soap message Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Web Services
Bookmark "wsdl stubs adding own namespace around soap message" Watch "wsdl stubs adding own namespace around soap message" New topic
Author

wsdl stubs adding own namespace around soap message

Soumya Singh
Greenhorn

Joined: Mar 14, 2008
Posts: 2
Hi,

I am using axis2 and I created a test service and client. I used the wsdl file generated from the service and used the emitted classes to create the client. I am trying to send xml in soap messages, both in the request and response, but what is happening is, the stub is adding its own element with ns1 namespace around my soap elements.

This is the soap request I am supposed to send:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Body>
<soap:search xmlns:soap="http://example1.org/example1">
<soap:SSN>123</soap:SSN>
<soap:FirstName>ABC</soap:FirstName>
<soap:LastName>DEF</soap:LastName>
</soap:search>
</soapenv:Body>
</soapenv:Envelope>

but this is how it is sending it when I call the search method in the Stub

<soapenv:Envelope xmlns:soapenv="http://www.w3.org/2003/05/soap-envelope">
<soapenv:Body>
<ns1:search xmlns:ns1="http://com/xsd">
<ns1:search>
<soap:search xmlns:soap="http://example1.org/example1">
<soap:SSN>123</soap:SSN>
<soap:FirstName>ABC</soap:FirstName>
<soap:LastName>DEF</soap:LastName>
</soap:search>
</ns1:search>
</ns1:search>
</soapenv:Body>
</soapenv:Envelope>

It is adding its own <ns1:search> elements around my message. So obviously when i am trying to extract the elements from the message I am getting the wrong values.

Can you please tell me how I can avoid this?

My service looks something like this:

public class SampleService {

private HashMap<String, String> searchMap = new HashMap<String, String>();

public OMElement search(OMElement element)
throws XMLStreamException {


element.build();
element.detach();

String rootName = element.getLocalName();
System.out.println("Reading "+ rootName+ " element");


Iterator allChildren = element.getChildElements();
while (allChildren.hasNext()) {
OMElement omElement = (OMElement) allChildren.next();
String attr = omElement.getLocalName();
System.out.println("This is the Key element of search:" + attr);
System.out.println("");
String value = omElement.getText();
System.out.println("This is the Value element of search:" + value);
System.out.println("");
searchMap.put(attr, value);
}

System.out.println("The value for key SSN :" + searchMap.get("SSN"));
System.out.println("The value for key FirstName :" + searchMap.get("FirstName"));
System.out.println("The value for key LastName :" + searchMap.get("LastName"));


OMFactory fac = OMAbstractFactory.getOMFactory();
OMNamespace omNs = fac.createOMNamespace(
"http://example1.org/example1", "soap");
OMElement method = fac.createOMElement("searchResults", omNs);

return method;
}


}

My Client looks like this

public class SampleClient {

private static final String EPR = "http://localhost:9080/axis2/services/SOAPAPI";
private static EndpointReference targetEPR =
new EndpointReference("http://localhost:9080/axis2/services/SOAPAPI");

public static OMElement searchRequest() {
OMFactory fac = OMAbstractFactory.getOMFactory();
OMNamespace omNs = fac.createOMNamespace("http://example1.org/example1", "soap");
OMElement method = fac.createOMElement("search", omNs);


OMElement sv = fac.createOMElement("SSN", omNs);
sv.addChild(fac.createOMText(sv, "123"));

method.addChild(sv);

OMElement sv2 = fac.createOMElement("FirstName", omNs);
sv2.addChild(fac.createOMText(sv2, "ABC"));

method.addChild(sv2);

OMElement sv3 = fac.createOMElement("LastName", omNs);
sv3.addChild(fac.createOMText(sv3, "DEF"));

method.addChild(sv3);

return method;
}



public static void main(String[] args) {
try {
OMElement request = SampleClient.searchRequest();
SOAPAPIStub stub = new SOAPAPIStub(EPR);
stub._getServiceClient().getOptions().setTransportInProtocol(Constants.TRANSPORT_HTTP);
Search search = new Search();
search.setSearch(request);
SearchResponse response = stub.search(search);
OMElement element = response.get_return();


} catch (Exception e) { //(XMLStreamException e) {
// e.printStackTrace();
System.out.println(e.toString());
}
}

}

Please let me know if you need more information.

Thanks!
Soumya Singh
Greenhorn

Joined: Mar 14, 2008
Posts: 2
Could somebody please help me with this problem. Has anyone else come across this problem before? Or if you could send me a sample client code generated using wsdl stubs, I would appreciate your help.

Thanks!!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: wsdl stubs adding own namespace around soap message
 
Similar Threads
Creating Service and Client using AXIOM
javax.xml.stream.XMLStreamException: Undeclared prefix 'soapenv' for element <soapenv:Envelope>
Invoking Live Search Web Service - via Axis Client -error AxisFault connection abort
Adding payload to SOAP body
org.apache.axis2.AxisFault: Transport error 500 . Error Message is ..