Sunday, September 16, 2007

Python Soap Server and ASP.Net Web Services - Part 1

I had a soap server built in python with SOAPpy and I wanted to use it from an ASP.Net application using the visual studio 2005 built in web services tool. I encountered several problems:

  • Visual Studio wants to read the WSDL from the soap server;
  • Namespaces matter.

For the WSDL problem you have just to define a function like:

def wsdl(self):
  wsdl_text = ''
  f = open('service.wsdl', 'r')
  for l in f.readlines():
    wsdl_text += l f.close()
  return wsdl_text

for the namespece part, suppose you ns is 'http://localhost/MyServer/2007/09/Services/MyService/01', you server will be:

class MySoapServer(SOAPServer):
  def __init__(self, ip = "localhost", port = 8080):
  from SOAPpy import NS

  # visual studio want's the soap envelope defined as 's'
  NS.ENV_T = "s"
  self.ns = 'http://localhost/MyServer/2007/09/Services/MyService/01'
  SOAPServer.__init__(self, (ip, port))
  self.registerFunction('wsdl')
  self.registerFunction('soap_myFunction', 'myFunction', namespace = self.ns)

In this way Visual Studio will be able to correctly call your exposed methods. Later we will see how to let Visual Studio correctly understand your results.

Technorati Tags: , ,

1 comment:

Anonymous said...

So where is Part 2?