Seite 1 von 1

SOAPpy und WSDL

Verfasst: Mittwoch 21. Juni 2006, 10:54
von tobias.vdk
Hallo!

Ich habe folgendes Problem: Ich weiß nicht, wie ich einen Web-Service aufrufen kann...

Service.py:

Code: Alles auswählen

#!/usr/bin/env python

import SOAPpy

def GetString():
    string = 'Hello World'
    return string

server = SOAPpy.SOAPServer(("localhost", 8081))
server.registerFunction(GetString)
try:
  server.serve_forever()
except KeyboardInterrupt:
  pass
Client:

Code: Alles auswählen

#!/usr/bin/env python
import cherrypy
import SOAPpy as SOAP
from SOAPpy import WSDL


SOAP.Config.debug = 1

class Index(object):
    def __init__(self):
        self.wsdlFile = 'http://localhost:80/wsdl/GetString.wsdl'
        self.server = WSDL.Proxy(self.wsdlFile)

    def index(self):
        '''Show String'''
        formular = '''<form action="showString" method="GET">
                        <input type="submit"/>
                      </form>'''
        return formular
        
    index.exposed = True
    
    def showString(self):
        string = self.server.GetString()
        return string
        
    showString.exposed = True


if __name__ == '__main__':
    cherrypy.config.update({'server.socketPort' : 8080,
                            'server.threadPool' : 10,
                            'server.environment' : 'production'})
    cherrypy.root = Index()
    cherrypy.server.start()
WSDL:

Code: Alles auswählen

<?xml version="1.0" encoding="UTF-8"?>
<definitions name="GetString"
    targetNamespace="http://localhost:80/wsdl/GetString.wsdl"
    xmlns:tns="http://localhost:80/wsdl/GetString.wsdl"
    xmlns:xsd="http://www.w3.org/2001/XMLSchema"
    xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
    xmlns="http://schemas.xmlsoap.org/wsdl/">

  
  <message name="GetStringResponse">
    <part name="Response" type="xsd:string"/>
  </message>

  <portType name="GetStringPortType">
    <operation name="GetString">   
      <output message="tns:GetStringResponse"/>
    </operation>
  </portType>
  
  <binding name="GetStringSoapBinding" type="tns:GetStringPortType">
    <soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
    <operation name="GetString">
      <soap:operation soapAction="http://localhost:8081/GetString"/>
      <!--<input>
        <soap:body use="encoded" namespace="GetString"
                   encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
      </input>-->
      <output>
        <soap:body use="encoded" namespace="GetString"
                   encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
      </output>
    </operation>
  </binding>
  
  <service name="GetStringService">
    <documentation>Get a sring</documentation>
    <port name="GetString" binding="tns:GetStringSoapBinding">
      <soap:address location="http://localhost:8081/GetString"/>
    </port>
  </service>
  
</definitions>
Es ist als Test ein einfaches Formular mit einem Button. Wenn ich den drücke, soll die Funktion GetString() auf dem SOAPpy-Server aufgerufen werden. Leider kommt immer die Fehlermeldung :(
<faultcode>SOAP-ENV:Client</faultcode>
<faultstring>Method Not Found</faultstring>
<detail xsi:type="xsd:string">GetString:GetString : exceptions.KeyError u'GetString' <traceback object at 0xb7b44aa4></detail>
Ich weiß leider nicht, od das WSDL-File so stimmt.

Vielleicht kann mir ja jemand helfen!
Schon mal vielen Dank dafür, dass ihr bis hier her gelesen habt!

Tschau Tobias

Re: SOAPpy und WSDL

Verfasst: Mittwoch 21. Juni 2006, 14:48
von BlackJack
tobias.vdk hat geschrieben:

Code: Alles auswählen

  <service name="GetStringService">
    <documentation>Get a sring</documentation>
    <port name="GetString" binding="tns:GetStringSoapBinding">
      <soap:address location="http://localhost:8081/GetString"/>
    </port>
  </service>
Es ist als Test ein einfaches Formular mit einem Button. Wenn ich den drücke, soll die Funktion GetString() auf dem SOAPpy-Server aufgerufen werden. Leider kommt immer die Fehlermeldung :(

Code: Alles auswählen

<faultcode>SOAP-ENV:Client</faultcode>
<faultstring>Method Not Found</faultstring>
<detail xsi:type="xsd:string">GetString:GetString : exceptions.KeyError u'GetString' <traceback object at 0xb7b44aa4></detail>
Ich kenne mich nicht mit WSDL aus, aber der Fehler ist wohl, das auf eine Funktion `GetString.GetString` zugegriffen wird, die es so nicht gibt. Da ist ein `GetString` zuviel. Das taucht in dem Schnipsel, den ich zitiert habe zweimal auf, einmal bei `port name` und dann nochmal in der URL bei `address location`. Aus der URL könntest Du es mal probeweise rausnehmen.

Fehler gefunden

Verfasst: Donnerstag 22. Juni 2006, 09:42
von tobias.vdk
Ich habe jetzt den Fehler gefunden.
So muss es richtig heißen:

Code: Alles auswählen

<?xml version="1.0" encoding="UTF-8"?>
<definitions name="GetString"
    targetNamespace="http://localhost:80/wsdl/GetString.wsdl"
    xmlns:tns="http://localhost:80/wsdl/GetString.wsdl"
    xmlns:xsd="http://www.w3.org/2001/XMLSchema"
    xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
    xmlns="http://schemas.xmlsoap.org/wsdl/">

  
  <message name="GetStringResponse">
    <part name="Response" type="xsd:string"/>
  </message>

  <portType name="GetStringPortType">
    <operation name="GetString">   
      <output message="tns:GetStringResponse"/>
    </operation>
  </portType>
  
  <binding name="GetStringSoapBinding" type="tns:GetStringPortType">
    <soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
    <operation name="GetString">
      <soap:operation soapAction="GetString"/>
      <output>
        <soap:body use="literal" encodingStyle="http://schemas.xmlsoap.org/soap/literal/"/>
      </output>
    </operation>
  </binding>
  
  <service name="GetStringService">
    <documentation>Get a sring</documentation>
    <port name="GetString" binding="tns:GetStringSoapBinding">
      <soap:address location="localhost:8081"/>
    </port>
  </service>
  
</definitions>