Python Suds soap client for WCF. WS-reliable messageing - python

I have WCF service which uses WS-reliable messaging. I would like to write some python scripts that connect to this service using suds soap client but it seems that suds doesn't support reliable messaging out of the box. Does anybody tried to use suds with reliable messaging? Do I have to write some logic for handshaking like CreateSequence,TerminateSequece and so on? Or maybe there are another python soap clients which support WS-reliable messageing?
Thanks in advance.

Related

How to send request to a public web service with Python?

i need a guide to establish a connection to a public web service, send request to it and get response back. for example this web service:
http://webservices.oorsprong.org/websamples.countryinfo/CountryInfoService.wso?WSDL
i've tried to test this API with SoapUI application. this API has a bunch of methods such as sending you a country's capital by getting it's ISO name (send IR as request and get Tehran as respond). now somehow i want to do this through Python. i want to have access to all it's methods and send requests. only by connecting to API's address or any other way (maybe by loading each method's XML code and running it in Python? idk). is it possible? any guide?
I'd recommend checking out this library:
https://requests.readthedocs.io/en/latest/
You can send HTTP requests to URL endpoints, parse out data, etc. Hope this helps!
I have successfully used suds and SOAPpy in the past. I see people recommend Zeep nowadays but I haven't used it.

python 3.x SOAP library for writing serverless webservice on AWS

I need to convert some legacy Java code that implements a SOAP server - I need to convert it from java to python 3.x and I need to deploy the SOAP webservices on AWS Lambda. There is plenty of documentation on how to create REST web services on AWS Lambda in python, but I'm finding it really hard to find any information on writing a SOAP service. There are some client libraries for python SOAP, but I can't seem to find any server-side libraries or examples of how one would do this on AWS Lambda. I found zeep, which is meant to be a client library, and pysimplesoap, but in neither case is it clear how to use these on AWS Lambda. Any suggestions?
UPDATE: So I discovered that SOAP over HTTP is simply a call to HTTP POST which passes the SOAP request message as the HTTP body. (Of course there are headers in the HTTP request too that indicate that the body is a soap/xml message). So, to deploy to AWS Lambda, I basically need to deploy an HTTP PSOT webservice, which is easy enough using Zappa and Flask (or Django). The only tricky part is inside the post() function. Inside that function I would have to:
Get the request.body (SOAP/XML)
Use some python library to extract the items of interest from the SOAP message, perhaps parsing the entire message using a python XML parser
Execute the business logic code that creates a result, say a dictionary
Use some python library to convert that result dictionary to a SOAP response and let AWS Lambda send that SOAP response back
It is parts 2 and 4 that I am not quite sure how to do. I can use xml.etree.ElementTree to parse the XML, but I suspect there might be a better/faster/simpler way. For the output, is there a way I can use something like zeep to take a dictionary of inputs and create a SOAP response message? The zeep library is meant to read the WSDL document and create request SOAP messages, not response SOAP messages, so I'm not exactly sure how to create a SOAP response message using zeep. Has anyone else done this or know of a better way to do it?

Is it possible to use GCM with a python GAE backend?

I have a python GAE service, and I want to push notifications from the server to devices. The tutorial available for GCM is written for Java, and runs on ant+Tomcat/Jetty+JAE. I was under the impression that GCM would be a language-agnostic web service, and that I would be able to send push notifications regarding of my server-side platform.
Was I mistaken about GCM being compatible with my python GAE
backend?
If I CAN use it with my existing server, what instructions
can I follow (or adapt) to get started with sending notifications to
a mobile client?
Sure you can. GCM has a JSON REST API that you can work against. First you need to register you project here: http://developer.android.com/google/gcm/gs.html.
You basically do this:
Acquire you API key from http://developer.android.com/google/gcm/gs.html#access-key
Construct your payload, a dict containing registration_ids, data etc
Using url.fetch https://developers.google.com/appengine/docs/python/urlfetch/ to send the data as a JSON string to the GCM API
Here's another question with some code. Google Cloud Messaging HTTP Error 400: Bad Request and a blogpost (in not english, i think spanish. but there some sample code) http://pforray.wordpress.com/2012/07/05/ejemplo-gcm-en-appengine-python/
Use gcm-client
pip install gcm-client
Reference:
https://pypi.python.org/pypi/gcm-client/
Here you can find a module for Python interface for sending push notifications via Pushwoosh.
https://github.com/dbtsai/python-pushwoosh
You can use it for sending messages via Pushwoosh (it's free) or adapt it for your needs.

JSON-RPC server via Python

I need to implement a JSON-RPC server like this:
http://pasha.cdemo.applicationcraft.com/service/json
This server will be accessed from jQuery and I have to use Python for writing it.
What library should I use? Can you also give me an example of using that library?
Thanks.
I found cherrypy very easy to use (doesn't come with a predefined template engine or a database model, so it's IMO better than others when your server is producing json and is not a typical database).
Coupled with nginx and memcached can also be quite performant...
Python 2.6 comes with json module in the standard library which allows you to effective convert Python data structures to JSON responses.
For HTTP communications and request handling, you can use Python web frameworks like Pyramid, Django or HTTP server software like Tornado. It really much depends what do you need to process in your JSON-RPC calls.

XML differences between WCF and Python SUDS for inheritance?

I have a question regarding the different ways inheritance are represented between WCF and SUDS (Python). I have a C++/CLI WCF server (.NET 3.5 SP1) and I'm trying to communicate with it. I've used a C# (WCF also) client and it work fine, but there are problems when using a SUDS client (Python 2.6.4, SUDS 0.3.8). It's mostly fine, but for inherited types, and the difference seems to be in the way the two represent inheritance in the SOAP XML. When I look at the messages that the server logs, I get results similar to the following:
C# Client:
<ns:DerivedType>
...
</ns:DerivedType>
Python Client:
<ns:BaseType xsi:type="ns:DerivedType">
...
</ns:BaseType>
Is it possible to change the WCF server to accept the Python style? Or to change the Python SUDS client to send the WCF style? Which one is correct?
Don't know about the python side but there are couple of options on the WCF side. The more straight foward option is to create a message inspector to detect and convert the python generated soap to something more palatable to the WCF service.
The more difficult but "purer" option is to determine how to shape the WSDL generated by the WCF service so it allows the python client to produce the aforementioned palatable soap. Once you find the required tweaks, you would use the MessageContract classes in place of the DataContract to make the service produce the tweaked WSDL. The .NET clients should handle this tweaked WSDL without complaint.
You could use the data contract serializer to control how the xml is created and read. See: http://msdn.microsoft.com/en-us/library/ms731073.aspx

Categories