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:8080/axis2/services/annotationScript/deduct");


    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);
    }
}

Recommended Answers

All 2 Replies

Hi heshan,
I have implemented an application that hits on an ASP.NET XML web service. I cut the code fragment below out of my app and removed specific references. Maybe this will help. The SOAP.py module is the core piece of code.

Regards,
Martin

[language=python]
import SOAP
import time

class ENotebook(object):
    def __init__(self):
        pass
    
    def SendToENotebook(self,):

        SERVICE_PROXY = "http://server/location/AppName.asmx"

        SERVICE_NAMESPACE = "http://server/WebServiceName/Data"

        SERVICE_SOAP_ACTION = "http://WebServiceName/Data/MethodToCall"

        YourInformation = "Your Message to the Web Service"
       
        #Make sure we are at the start of the buffer
        Info.PDF_Mail_container.seek(0)
        #Create the SOAP message
        soapMsg = '<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">\n'
        soapMsg = soapMsg + '  <soap:Body>\n'
        soapMsg = soapMsg + '    <Inbox_Inbound xmlns="http://WebServiceName/Data">\n'
        soapMsg = soapMsg + '      <Information>' + YourInfomation + '</Information>\n'
        soapMsg = soapMsg + '    </Inbox_Inbound>\n'
        soapMsg = soapMsg + '  </soap:Body>\n'
        soapMsg = soapMsg + '</soap:Envelope>\n'


        server = SOAP.SOAPProxy(proxy=SERVICE_PROXY,namespace = SERVICE_NAMESPACE, soapaction=SERVICE_SOAP_ACTION)

        #Send the soap command, get back True or False


        #Send the SOAP message
        bResult = server.Inbox_Inbound(soapMsg)
            
        return bResult

Hi heshan,
I have implemented an application that hits on an ASP.NET XML web service. I cut the code fragment below out of my app and removed specific references. Maybe this will help. The SOAP.py module is the core piece of code.

Regards,
Martin

Hi Martin,
Thanx for your reply. Can you point me to a web reference on how to use SOAPpy , with some sample python code.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.