| | |
Writing a Python Client to access a Web Service
Thread Solved |
•
•
Join Date: Apr 2008
Posts: 10
Reputation:
Solved Threads: 0
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.
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.
Python Syntax (Toggle Plain Text)
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); } }
•
•
Join Date: Jul 2007
Posts: 1
Reputation:
Solved Threads: 1
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
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
Python Syntax (Toggle Plain Text)
[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
•
•
Join Date: Apr 2008
Posts: 10
Reputation:
Solved Threads: 0
•
•
•
•
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
[/code]
Thanx for your reply. Can you point me to a web reference on how to use SOAPpy , with some sample python code.
Regards,
Heshan
heshans.blogspot.com
![]() |
Other Threads in the Python Forum
- Previous Thread: Install Python 3.0a5 on Windows Vista System
- Next Thread: python string encoding
| Thread Tools | Search this Thread |
accessdenied advanced aliased argv beginner bits calling casino change changecolor clear command convert corners count csv cturtle cursor def definedlines dictionary digital dynamic dynamically enter event events external file float format frange function google homework i/o iframe import input jaunty java keyboard lapse line linux list lists loop matching microphone mouse multiple newb number numbers obexftp output parameters parsing path prime programming projects py py2exe pygame pyopengl python random rational raw_input recursion remote return scrolledtext signal singleton skinning sprite string strings syntax tails text threading time tlapse tuple tutorial ubuntu unicode urllib urllib2 valueerror variable voip web-scrape whileloop word wxpython





