[BangPypers] Writing a Python Client to access a web service.

Heshan Suriyaarachchi heshan.suri at gmail.com
Tue Jun 3 11:07:38 CEST 2008


Hi,
    I have written a web service and have deployed it using Apache Axis2.
What I want to do is to invoke this service using a python script. Can
anyone point me in the direction of how to do this. I will be grateful If
anyone can give me a web reference to a code sample.I can do this with java.
To give you an idea of what kind of a thing I want to do , I am attaching my
java client code below.

import org.apache.axis2.addressing.EndpointReference;
import org.apache.axis2.client.ServiceClient;
import org.apache.axis2.client.Options;
import org.apache.axiom.om.OMElement;
import org.apache.axiom.om.OMFactory;
import org.apache.axiom.om.OMAbstractFactory;
import org.apache.axiom.om.impl.builder.StAXOMBuilder;
import javax.xml.stream.XMLStreamException;
import java.io.ByteArrayInputStream;

public class myClient {
    private static EndpointReference targetEPR =
            new EndpointReference("
http://localhost:8070/axis2/services/annotationScript/deduct");
    //http://localhost:8080/axis2/services/annotationScript/f

    public static OMElement getPayload() throws XMLStreamException {
        String str1 = "<f><a>4</a></f>";
        String str2 =
"<deduct><var1>1.8</var1><var2>4.87594</var2></deduct>";
        String str3 =  "<add><var1>1.8</var1><var2>4.87594</var2></add>";
        StAXOMBuilder builder = new StAXOMBuilder(new
ByteArrayInputStream(str2.getBytes()));
        return builder.getDocumentElement();
    }

    public static void main(String[] args) throws Exception {
        ServiceClient sender = new ServiceClient();
        Options op = new Options();
        op.setTo(targetEPR);
        sender.setOptions(op);
        OMElement response = sender.sendReceive(getPayload());
        System.out.println(response);
    }
}


Thanx in advance

-- 
Regards,
Heshan Suriyaarachchi
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/bangpypers/attachments/20080603/cbd8cfb9/attachment.htm>


More information about the BangPypers mailing list