Привет, я довольно новичок в Python и в веб-сервисах, и я начал работу, пытаясь использовать методы веб-сервисов в WSDL через Python.Теперь, когда я запускаю следующий код, я получаю значение "".Я стремлюсь получить возвращаемое значение метода GetMessage (простой Hello World), но вместо этого получить этот идентификатор для метода.Есть ли способ получить это возвращаемое значение?
import logging
import sys
from suds.client import Client
sys.setrecursionlimit(2000)
url='http://localhost:50774/HostDevServer/HelloWorldService.svc?wsdl'
client = Client(url)
example = client.service.GetMessage
print example
Я также попробовал следующий код
import logging
import sys
from suds.client import Client
sys.setrecursionlimit(2000)
url='http://localhost:50774/HostDevServer/HelloWorldService.svc?wsdl'
client = Client(url)
example = client.service.GetMessage()
print example
, и это возвращает следующее сообщение об ошибке:
No handlers could be found for logger "suds.client"
Traceback (most recent call last):
File "C:\Python27\exampleForSuds.py", line 7, in <module>
example = client.service.GetMessage()
File "build\bdist.win32\egg\suds\client.py", line 542, in __call__
return client.invoke(args, kwargs)
File "build\bdist.win32\egg\suds\client.py", line 602, in invoke
result = self.send(soapenv)
File "build\bdist.win32\egg\suds\client.py", line 649, in send
result = self.failed(binding, e)
File "build\bdist.win32\egg\suds\client.py", line 708, in failed
raise Exception((status, reason))
Exception: (415, u'Unsupported Media Type')
Я могу обойти первую замеченную ошибку отсутствия обработчиков, добавив:
logging.getLogger('suds.client').setLevel(logging.CRITICAL)
Но остальная часть сообщения об ошибке останется.Я что-то упускаю?Я искал несколько часов и не могу найти ничего похожего на проблему.
ОБНОВЛЕНИЕ:
Это то, что напечатано в первом сегменте кода:
<suds.client.Method instance at 0x02D9FC38>
Я попробовал идею Себастьяна, и я получил следующее:
Traceback (most recent call last):
File "C:\Python27\exampleForSuds.py", line 10, in <module>
example = client.service.GetMessage()
File "build\bdist.win32\egg\suds\client.py", line 542, in __call__
return client.invoke(args, kwargs)
File "build\bdist.win32\egg\suds\client.py", line 602, in invoke
result = self.send(soapenv)
File "build\bdist.win32\egg\suds\client.py", line 649, in send
result = self.failed(binding, e)
File "build\bdist.win32\egg\suds\client.py", line 708, in failed
raise Exception((status, reason))
Exception: (400, u'Bad Request')
Значение клиента для идеи Себастьяна следующее:
Suds ( https://fedorahosted.org/suds/ ) version: 0.4 GA build: R699-20100913
Service ( HelloWorldService ) tns="http://tempuri.org/"
Prefixes (1)
ns0 = "http://schemas.microsoft.com/2003/10/Serialization/"
Ports (1):
(WSHttpBinding_IHelloWorldService)
Methods (1):
GetMessage()
Types (3):
ns0:char
ns0:duration
ns0:guid
Update2:Регистрация по запросу Себастьяна
DEBUG:suds.transport.http:sending:
URL:http://localhost:50774/HostDevServer/HelloWorldService.svc
HEADERS: {'SOAPAction': u'"http://tempuri.org/IHelloWorldService/GetMessage"', 'Content-Type': 'application/soap+xml; charset="UTF-8"', 'Content-type': 'application/soap+xml; charset="UTF-8"', 'Soapaction': u'"http://tempuri.org/IHelloWorldService/GetMessage"'}
MESSAGE:
<?xml version="1.0" encoding="UTF-8"?><SOAP-ENV:Envelope xmlns:ns0="http://tempuri.org/" xmlns:ns1="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"><SOAP-ENV:Header/><ns1:Body><ns0:GetMessage/></ns1:Body></SOAP-ENV:Envelope>
ERROR:suds.client:<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:ns0="http://tempuri.org/" xmlns:ns1="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
<SOAP-ENV:Header/>
<ns1:Body>
<ns0:GetMessage/>
</ns1:Body>
</SOAP-ENV:Envelope>
Traceback (most recent call last):
File "C:\Python27\exampleForSuds.py", line 11, in <module>
example = client.service.GetMessage()
File "build\bdist.win32\egg\suds\client.py", line 542, in __call__
return client.invoke(args, kwargs)
File "build\bdist.win32\egg\suds\client.py", line 602, in invoke
result = self.send(soapenv)
File "build\bdist.win32\egg\suds\client.py", line 649, in send
result = self.failed(binding, e)
File "build\bdist.win32\egg\suds\client.py", line 708, in failed
raise Exception((status, reason))
Exception: (400, u'Bad Request')
Код также для этой ошибки:
import logging
import sys
logging.basicConfig(level=logging.INFO)
logging.getLogger('suds.transport.http').setLevel(logging.DEBUG)
from suds.client import Client
sys.setrecursionlimit(2000)
url='http://localhost:50774/HostDevServer/HelloWorldService.svc?wsdl'
headers = {'Content-Type': 'application/soap+xml; charset="UTF-8"'}
client = Client(url,headers=headers)
print client
example = client.service.GetMessage()
print example
Окончательное обновление:
Оказалось, что решение проблемы найденопроблема не имела ничего общего с кодом Python, кроме web.config для веб-службы.Нужно использовать basicHttpBinding