You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-dev@axis.apache.org by Bill Screen <we...@tta-online.org> on 2003/12/25 18:21:21 UTC

Axis message-style web services

Hello all and Merry Christmas,  
 
I'm working with Axis message-style web services and 
need some code snippets on how to invoke the following 
signatures via web service client. 
 
1.public Document method(Document body);
- The sample below runs w/o error, but returns and empty
SOAPBody, where I'm expecting the Document object
to be echoed back.
 
2.public void method(SOAPEnvelope req, SOAPEnvelope resp);
- Need a client code snippet.
 
Here is what I've have so far the Document service:
--------------------------------------------------
Web Service Client (Document body)
--------------------------------------------------
import java.util.Vector;
import javax.xml.namespace.QName;
import org.apache.axis.client.Service;
import org.apache.axis.client.Call;
import org.apache.axis.MessageContext;
import org.apache.axis.message.SOAPBodyElement;
import org.apache.axis.utils.XMLUtils;
import org.apache.axis.Message;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Text;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import org.apache.axis.message.SOAPEnvelope;
import javax.xml.parsers.*;
//import org.w3c.dom.*;
 
public class testClient {
 
public testClient()  throws Exception {
 
String endpointURL =
 "http://localhost:8080/axis/services/MessageService3";
Service service = new Service();
Call call = (Call) service.createCall();
call.setTargetEndpointAddress( endpointURL );
call.setOperationName(new QName(endpointURL, "myMethod"));
Object[] input = new Object[1];
 
Document doc = null;
Element element = null;
DocumentBuilderFactory factory =
 DocumentBuilderFactory.newInstance();
factory.setNamespaceAware(true);
DocumentBuilder builder =
 factory.newDocumentBuilder();
doc = builder.newDocument();
 
Element root = doc.createElementNS(
            "http://127.0.0.1/namespace","rootElement");
doc.appendChild(root);
 
input[0] = (org.w3c.dom.Document) doc;
Object result = call.invoke(input);
 
//Output SOAP result
System.out.println("------------------------------------------");
System.out.println("SOAP Envelope returned from MessageService");
System.out.println("------------------------------------------");
Message resultMsg = call.getResponseMessage();
resultMsg.writeTo( System.out );
System.out.println("");
}
 
public static void main (String args[]) throws Exception {
new testClient();
}
}
--------------------------------------------------
Web Service (Document body)
--------------------------------------------------
import org.w3c.dom.Document;
public Document method(Document body) {
 return body;
}
 
--------------------------------------------------
Web Service Client (SOAPEnvelope req/resp)
--------------------------------------------------
****
**** Please send code... ****
****
 
--------------------------------------------------
Web Service (SOAPEnvelope req/resp)
--------------------------------------------------
public void method(SOAPEnvelope req, SOAPEnvelope resp) {
 resp = req;
}
 
Thanks,
Screen