-
1. Re: Duplicate SOAP body/envelope tags in SOAP message
jopere Jun 6, 2007 6:47 PM (in response to jopere)I have determined that the problem is that I need to be able to clear the soap headers before calling the second web service. What's happening is that the second web service is being wrapped in the env/body tags from the first web service, which is why I am geeting multiple tags. I determined this by writing my own code that creates a SOAP message and sends it to the web service. The web service replies correctly.
Does anyone know how to clear the SOAP headers or in some other way to get this to work? -
2. Re: Duplicate SOAP body/envelope tags in SOAP message
jopere Jun 7, 2007 5:03 PM (in response to jopere)I succeeded in calling a web service, from a web service. However, I'd really like someone out there who knows what they are doing to show me how to do this correctly. I am sure there is a better way than what I did.
This is how I got it to work:
1. Create web service B as a stateless session bean web service using wstools to create artifacts (ejb 2.1). Deployed web service.
2. Create web service A as a stateless session bean using wscompile to generate web service artifacts. Copied WSDL from web service B and used wscompile to create client artifacts. However, I don't ever use the generated stub/service/serializer classes, because when I do, I get a SOAP message with duplicate body/envelope tags. What I do is create my own SOAP message using a SOAPMessageFactory. Then I added namespacese, attributes and elements to the message so it complies with the WSDL. Next I create a connection and call the web service. When the message returns I parse it, retrieve the return value and pass it back to the client.
3. Create a web client that calls web service A. Web service A calls web service B, which returns a value to A, which returns a value to the client.
So, web service A is both a server to the web client and a client to web service B. Web service A recieves the SOAP message from the web client and immediately calls web service B. Here is the code in web service A that calls web service B:
SOAPConnectionFactory scf = SOAPConnectionFactory.newInstance();
SOAPConnection connection = scf.createConnection();
MessageFactory msgFactory = MessageFactory.newInstance();
// Create a message
SOAPMessage msg = msgFactory.createMessage();
// Create an envelope in the message
SOAPEnvelope envelope = msg.getSOAPPart().getEnvelope();
// Bind ns0 namespace
envelope.addNamespaceDeclaration("ns0","http://aaa/bbb/1.0");
// Get hold of the the body
SOAPBody body = envelope.getBody();
body.addChildElement(envelope.createName("ns0:getGreeting", "", ""))
.addAttribute(envelope.createName("ns0"), "http://aaa/bbb/1.0");
URL endpoint = new URL("http://localhost:8082/ws/getGreeting");
msg.saveChanges();
// Make call to web service
SOAPMessage soapMessage = connection.call(msg, "http://localhost:8082/ws/getGreeting");
soapMessage.writeTo(System.out);
// The return value is in the grandchild element to the body tag.
Iterator it = soapMessage.getSOAPBody().getChildElements();
SOAPElement child = it.next();
Iterator it2 = child.getChildElements();
SOAPElement result = it2.next();
responseMessage = result.getValue();
As I said, there has to be an easier way to do this. If someone could show me a simpler way to call a web service from a web service, I'd appreciate it. -
3. Re: Duplicate SOAP body/envelope tags in SOAP message
thomas.diesler Jun 18, 2007 4:28 PM (in response to jopere)Have a look at the JAXWS client API
http://jbws.dyndns.org/mediawiki/index.php/JAX-WS_User_Guide#Web_Service_Clients