Anzeige:
Ergebnis 1 bis 5 von 5

Thema: SOAPpy und WSDL

  1. #1
    Registrierter Benutzer
    Registriert seit
    19.08.2004
    Beiträge
    142

    Question SOAPpy und WSDL

    Hallo!

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

    Service.py:
    Code:
    #!/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:
    #!/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:
    <?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
    Code:
    <faultcode>SOAP-ENV:Client</faultcode>
    <faultstring>Method Not Found</faultstring>
    <detail xsi:type="xsd:string">GetString:GetString : exceptions.KeyError u'GetString' &lt;traceback object at 0xb7b44aa4&gt;</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
    Geändert von tobias.vdk (21-06-2006 um 08:59 Uhr)

  2. #2
    Registrierter Benutzer Avatar von Waxolunist
    Registriert seit
    19.06.2006
    Ort
    Wien
    Beiträge
    485
    Wenns dir nur darum geht einmal Python und SOAP zum Laufen zu bringen, dann mach einmal ein gutes Tutorial durch.

    Hier z.B.

    http://www.opensourcetutorials.com/t...ies/page1.html

  3. #3
    Registrierter Benutzer
    Registriert seit
    19.08.2004
    Beiträge
    142
    Ich denke, dass es am WSDL-File liegt, denn wenn ich mit
    Code:
    self.server = SOAP.SOAPProxy("http://localhost:8081/")
    den Server bestimme, dann funktionert alles.

    Vielleicht ist es hier doch das falsche Forum?!

    Tschau Tobias

  4. #4
    Registrierter Benutzer
    Registriert seit
    19.08.2004
    Beiträge
    142
    Habe jetzt durch den Vergleich der SOAP-Nachrichten einige Fehler gefunden.
    Hier die Nachrichten mit erfolgreicher Ausführung:
    Code:
    *** Outgoing HTTP headers **********************************************
    POST / HTTP/1.0
    Host: localhost:8081
    User-agent: SOAPpy 0.12.0 (http://pywebsvcs.sf.net)
    Content-type: text/xml; charset="UTF-8"
    Content-length: 348
    SOAPAction: "GetString"
    ************************************************************************
    *** Outgoing SOAP ******************************************************
    <?xml version="1.0" encoding="UTF-8"?>
    <SOAP-ENV:Envelope
      SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"
      xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/"
      xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
    >
    <SOAP-ENV:Body>
    <GetString SOAP-ENC:root="1">
    </GetString>
    </SOAP-ENV:Body>
    </SOAP-ENV:Envelope>
    ************************************************************************
    code= 200
    msg= OK
    headers= Server: <a href="http://pywebsvcs.sf.net">SOAPpy 0.12.0</a> (Python 2.4.3)
    Date: Wed, 21 Jun 2006 13:44:54 GMT
    Content-type: text/xml; charset="UTF-8"
    Content-length: 518
    
    content-type= text/xml; charset="UTF-8"
    data= <?xml version="1.0" encoding="UTF-8"?>
    <SOAP-ENV:Envelope
      SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"
      xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/"
      xmlns:xsi="http://www.w3.org/1999/XMLSchema-instance"
      xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
      xmlns:xsd="http://www.w3.org/1999/XMLSchema"
    >
    <SOAP-ENV:Body>
    <GetStringResponse SOAP-ENC:root="1">
    <Result xsi:type="xsd:string">Hello World</Result>
    </GetStringResponse>
    </SOAP-ENV:Body>
    </SOAP-ENV:Envelope>
    
    *** Incoming HTTP headers **********************************************
    HTTP/1.? 200 OK
    Server: <a href="http://pywebsvcs.sf.net">SOAPpy 0.12.0</a> (Python 2.4.3)
    Date: Wed, 21 Jun 2006 13:44:54 GMT
    Content-type: text/xml; charset="UTF-8"
    Content-length: 518
    ************************************************************************
    *** Incoming SOAP ******************************************************
    <?xml version="1.0" encoding="UTF-8"?>
    <SOAP-ENV:Envelope
      SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"
      xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/"
      xmlns:xsi="http://www.w3.org/1999/XMLSchema-instance"
      xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
      xmlns:xsd="http://www.w3.org/1999/XMLSchema"
    >
    <SOAP-ENV:Body>
    <GetStringResponse SOAP-ENC:root="1">
    <Result xsi:type="xsd:string">Hello World</Result>
    </GetStringResponse>
    </SOAP-ENV:Body>
    </SOAP-ENV:Envelope>
    ************************************************************************
    Hier die Nachrichten mit negativer Ausführung:
    Code:
    *** Outgoing HTTP headers **********************************************
    POST / HTTP/1.0
    Host: localhost:8081
    User-agent: SOAPpy 0.12.0 (http://pywebsvcs.sf.net)
    Content-type: text/xml; charset="UTF-8"
    Content-length: 378
    SOAPAction: "GetString"
    ************************************************************************
    *** Outgoing SOAP ******************************************************
    <?xml version="1.0" encoding="UTF-8"?>
    <SOAP-ENV:Envelope
      SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"
      xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/"
      xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
    >
    <SOAP-ENV:Body>
    <ns1:GetString xmlns:ns1="GetString" SOAP-ENC:root="1">
    </ns1:GetString>
    </SOAP-ENV:Body>
    </SOAP-ENV:Envelope>
    ************************************************************************
    code= 500
    msg= Internal error
    headers= Server: <a href="http://pywebsvcs.sf.net">SOAPpy 0.12.0</a> (Python 2.4 .3)
    Date: Wed, 21 Jun 2006 13:52:14 GMT
    Content-type: text/xml; charset="UTF-8"
    Content-length: 677
    
    content-type= text/xml; charset="UTF-8"
    data= <?xml version="1.0" encoding="UTF-8"?>
    <SOAP-ENV:Envelope
      SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"
      xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/"
      xmlns:xsi="http://www.w3.org/1999/XMLSchema-instance"
      xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
      xmlns:xsd="http://www.w3.org/1999/XMLSchema"
    >
    <SOAP-ENV:Body>
    <SOAP-ENV:Fault SOAP-ENC:root="1">
    <faultcode>SOAP-ENV:Client</faultcode>
    <faultstring>Method Not Found</faultstring>
    <detail xsi:type="xsd:string">GetString:GetString : exceptions.KeyError u'GetStr ing' &lt;traceback object at 0xb7c1c2d4&gt;</detail>
    </SOAP-ENV:Fault>
    </SOAP-ENV:Body>
    </SOAP-ENV:Envelope>
    
    *** Incoming HTTP headers **********************************************
    HTTP/1.? 500 Internal error
    Server: <a href="http://pywebsvcs.sf.net">SOAPpy 0.12.0</a> (Python 2.4.3)
    Date: Wed, 21 Jun 2006 13:52:14 GMT
    Content-type: text/xml; charset="UTF-8"
    Content-length: 677
    ************************************************************************
    *** Incoming SOAP ******************************************************
    <?xml version="1.0" encoding="UTF-8"?>
    <SOAP-ENV:Envelope
      SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"
      xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/"
      xmlns:xsi="http://www.w3.org/1999/XMLSchema-instance"
      xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
      xmlns:xsd="http://www.w3.org/1999/XMLSchema"
    >
    <SOAP-ENV:Body>
    <SOAP-ENV:Fault SOAP-ENC:root="1">
    <faultcode>SOAP-ENV:Client</faultcode>
    <faultstring>Method Not Found</faultstring>
    <detail xsi:type="xsd:string">GetString:GetString : exceptions.KeyError u'GetStr ing' &lt;traceback object at 0xb7c1c2d4&gt;</detail>
    </SOAP-ENV:Fault>
    </SOAP-ENV:Body>
    </SOAP-ENV:Envelope>
    ************************************************************************
    Hier das aktualisierte WSDL File:
    Code:
    <?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"/>
          <!--<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="localhost:8081"/>
        </port>
      </service>
      
    </definitions>
    Der Unterschied in den Nachrichten ist noch die
    OK:
    Code:
    *** Outgoing SOAP ******************************************************
    <?xml version="1.0" encoding="UTF-8"?>
    <SOAP-ENV:Envelope
      SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"
      xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/"
      xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
    >
    <SOAP-ENV:Body>
    <GetString SOAP-ENC:root="1"> <-- HIER 
    </GetString>
    </SOAP-ENV:Body>
    </SOAP-ENV:Envelope>
    ************************************************************************
    Nicht OK:
    Code:
    *** Outgoing SOAP ******************************************************
    <?xml version="1.0" encoding="UTF-8"?>
    <SOAP-ENV:Envelope
      SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"
      xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/"
      xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
    >
    <SOAP-ENV:Body>
    <ns1:GetString xmlns:ns1="GetString" SOAP-ENC:root="1"> <-- HIER STIMMTS NICHT
    </ns1:GetString>
    </SOAP-ENV:Body>
    </SOAP-ENV:Envelope>
    ************************************************************************
    Weiß jemand, woran das liegt?

    Tschau Tobias

  5. #5
    Registrierter Benutzer
    Registriert seit
    19.08.2004
    Beiträge
    142

    Smile Fehler gefunden!

    So, habe jetzt den Fehler gefunden ... Hier die richtige Datei:

    Code:
    <?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>

Lesezeichen

Berechtigungen

  • Neue Themen erstellen: Nein
  • Themen beantworten: Nein
  • Anhänge hochladen: Nein
  • Beiträge bearbeiten: Nein
  •