Writing a Python Client to access a Web Service

Thread Solved

Join Date: Apr 2008
Posts: 10
Reputation: heshan is an unknown quantity at this point 
Solved Threads: 0
heshan heshan is offline Offline
Newbie Poster

Writing a Python Client to access a Web Service

 
0
  #1
Jun 3rd, 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.

  1. import org.apache.axis2.addressing.EndpointReference;
  2. import org.apache.axis2.client.ServiceClient;
  3. import org.apache.axis2.client.Options;
  4. import org.apache.axiom.om.OMElement;
  5. import org.apache.axiom.om.OMFactory;
  6. import org.apache.axiom.om.OMAbstractFactory;
  7. import org.apache.axiom.om.impl.builder.StAXOMBuilder;
  8. import javax.xml.stream.XMLStreamException;
  9. import java.io.ByteArrayInputStream;
  10.  
  11. public class myClient {
  12. private static EndpointReference targetEPR =
  13. new EndpointReference("http://localhost:8080/axis2/services/annotationScript/deduct");
  14.  
  15.  
  16. public static OMElement getPayload() throws XMLStreamException {
  17. String str1 = "<f><a>4</a></f>";
  18. String str2 = "<deduct><var1>1.8</var1><var2>4.87594</var2></deduct>";
  19. String str3 = "<add><var1>1.8</var1><var2>4.87594</var2></add>";
  20. StAXOMBuilder builder = new StAXOMBuilder(new ByteArrayInputStream (str2.getBytes()));
  21. return builder.getDocumentElement();
  22. }
  23.  
  24. public static void main(String[] args) throws Exception {
  25. ServiceClient sender = new ServiceClient();
  26. Options op = new Options();
  27. op.setTo(targetEPR);
  28. sender.setOptions(op);
  29. OMElement response = sender.sendReceive(getPayload());
  30. System.out.println(response);
  31. }
  32. }
Reply With Quote Quick reply to this message  
Join Date: Jul 2007
Posts: 1
Reputation: martinEchols is an unknown quantity at this point 
Solved Threads: 1
martinEchols martinEchols is offline Offline
Newbie Poster

Re: Writing a Python Client to access a Web Service

 
0
  #2
Jun 4th, 2008
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

  1. [language=python]
  2. import SOAP
  3. import time
  4.  
  5. class ENotebook(object):
  6. def __init__(self):
  7. pass
  8.  
  9. def SendToENotebook(self,):
  10.  
  11. SERVICE_PROXY = "http://server/location/AppName.asmx"
  12.  
  13. SERVICE_NAMESPACE = "http://server/WebServiceName/Data"
  14.  
  15. SERVICE_SOAP_ACTION = "http://WebServiceName/Data/MethodToCall"
  16.  
  17. YourInformation = "Your Message to the Web Service"
  18.  
  19. #Make sure we are at the start of the buffer
  20. Info.PDF_Mail_container.seek(0)
  21. #Create the SOAP message
  22. 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'
  23. soapMsg = soapMsg + ' <soap:Body>\n'
  24. soapMsg = soapMsg + ' <Inbox_Inbound xmlns="http://WebServiceName/Data">\n'
  25. soapMsg = soapMsg + ' <Information>' + YourInfomation + '</Information>\n'
  26. soapMsg = soapMsg + ' </Inbox_Inbound>\n'
  27. soapMsg = soapMsg + ' </soap:Body>\n'
  28. soapMsg = soapMsg + '</soap:Envelope>\n'
  29.  
  30.  
  31. server = SOAP.SOAPProxy(proxy=SERVICE_PROXY,namespace = SERVICE_NAMESPACE, soapaction=SERVICE_SOAP_ACTION)
  32.  
  33. #Send the soap command, get back True or False
  34.  
  35.  
  36. #Send the SOAP message
  37. bResult = server.Inbox_Inbound(soapMsg)
  38.  
  39. return bResult
Reply With Quote Quick reply to this message  
Join Date: Apr 2008
Posts: 10
Reputation: heshan is an unknown quantity at this point 
Solved Threads: 0
heshan heshan is offline Offline
Newbie Poster

Re: Writing a Python Client to access a Web Service

 
0
  #3
Jun 9th, 2008
Originally Posted by martinEchols View Post
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]
Hi Martin,
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
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:



Other Threads in the Python Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC