Archiv verlassen und diese Seite im Standarddesign anzeigen : SOAPpy und WSDL
tobias.vdk
21-06-2006, 08:14
Hallo!
Ich habe folgendes Problem: Ich weiß nicht, wie ich einen Web-Service aufrufen kann...
Service.py:
#!/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:
#!/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:
<?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
Waxolunist
21-06-2006, 08:37
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/tutorials/Server-Side-Coding/Python/python-soap-libraries/page1.html
tobias.vdk
21-06-2006, 09:07
Ich denke, dass es am WSDL-File liegt, denn wenn ich mit
self.server = SOAP.SOAPProxy("http://localhost:8081/") den Server bestimme, dann funktionert alles.:confused:
Vielleicht ist es hier doch das falsche Forum?!
Tschau Tobias
tobias.vdk
21-06-2006, 15:06
Habe jetzt durch den Vergleich der SOAP-Nachrichten einige Fehler gefunden.
Hier die Nachrichten mit erfolgreicher Ausführung:
*** 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:
*** 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' <traceback object at 0xb7c1c2d4></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' <traceback object at 0xb7c1c2d4></detail>
</SOAP-ENV:Fault>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
************************************************** **********************
Hier das aktualisierte WSDL File:
<?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:
*** 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:
*** 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
tobias.vdk
22-06-2006, 09:39
So, habe jetzt den Fehler gefunden ... Hier die richtige Datei:
<?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>
Powered by vBulletin® Version 4.2.5 Copyright ©2024 Adduco Digital e.K. und vBulletin Solutions, Inc. Alle Rechte vorbehalten.