2014-04-03 13 views
0

我已經檢查了其他類似的問題,並且我沒有看到相同的問題。我將發佈這個問題的泡沫和pysimplesoap。我不在乎哪一個人能夠工作,但我需要儘快讓他們中的一個工作。我認爲這個問題可能是因爲.NET中創建的服務產生了WSDL,因爲我遇到了pysimplesoap和我試過的其他每個python soap客戶端的問題。我已經嘗試了這兩個泡沫和泡沫jurko具有相同的結果。我對這個SOAP的東西不太好(我寧願使用JSON的簡單RESTful服務),所以任何幫助都會非常感謝。我做出了積極的態度,並將我接受的解決方案標記爲我的問題。泡沫WebFault最有可能不正確SOAPAction

Here is the WSDL file

這裏是我的代碼:

from suds.client import Client 
client = Client('http://url-for-my-service?wsdl') 
result = client.service.StartSession('userid','passwd') 

下面是錯誤消息我得到:

ERROR:suds.client:<suds.sax.document.Document instance at 0x28fcbd8> 
Traceback (most recent call last): 
    File "<stdin>", line 1, in <module> 
    File "/home/rksmith/Projects/soap/venv/local/lib/python2.7/site-packages/suds/client.py", line 521, in __call__ 
    return client.invoke(args, kwargs) 
    File "/home/rksmith/Projects/soap/venv/local/lib/python2.7/site-packages/suds/client.py", line 581, in invoke 
    result = self.send(soapenv) 
    File "/home/rksmith/Projects/soap/venv/local/lib/python2.7/site-packages/suds/client.py", line 619, in send 
    description=tostr(e), original_soapenv=original_soapenv) 
    File "/home/rksmith/Projects/soap/venv/local/lib/python2.7/site-packages/suds/client.py", line 670, in process_reply 
    raise WebFault(fault, replyroot) 
suds.WebFault 

我還挺喜歡泡好,因爲我可以啓用logging.DEBUG和獲取更多信息:

DEBUG:suds.client:sending to (http://cpldevweb001:3691/Invoke?Handler=CSSoapService) 
message: 
<?xml version="1.0" encoding="UTF-8"?> 
<SOAP-ENV:Envelope xmlns:ns3="http://www.w3.org/2001/XMLSchema" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:ns0="http://schemas.xmlsoap.org/soap/encoding/" xmlns:ns1="urn:CSSoapService" xmlns:ns2="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:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"> 
    <SOAP-ENV:Header/> 
    <ns2:Body> 
     <ns1:StartSession> 
     <user xsi:type="ns3:string">userid</user> 
     <pass xsi:type="ns3:string">passwd</pass> 
     </ns1:StartSession> 
    </ns2:Body> 
</SOAP-ENV:Envelope> 
DEBUG:suds.client:headers = {'SOAPAction': '"#StartSession"', 'Content-Type': 'text/xml; charset=utf-8'} 
DEBUG:suds.client:HTTP failed - 500 - Internal Server Error: 
<SOAP:Envelope xmlns:SOAP="http://schemas.xmlsoap.org/soap/envelope/"> 
    <SOAP:Body> 
    <SOAP:Fault> 
    <faultcode>SOAP:Client</faultcode> 
    <faultcode>Invalid Request</faultcode> 
    <detail>Invalid SOAP Request, most probable incorrect SOAPAction</detail> 
    </SOAP:Fault> 
    </SOAP:Body> 
</SOAP:Envelope> 

回答

0

供應商提供了一個工作樣本客戶端,我可以使用TcpMon運行並比較正在發送的XML和由suds生成的內容。原來問題是空的<SOAP-ENV:Header/>標籤。

我創建了一個消息插件,在發送階段過濾掉空的Header,現在它工作。以下是更新後的代碼:

import re 

from suds.client import Client 
from suds.plugin import MessagePlugin 

class HeaderFilter(MessagePlugin): 

    def sending(self, context): 
     context.envelope = re.sub(r'<[A-Za-z0-9_\-:]*Header/>', '', context.envelope) 
     return context 

client = Client('http://url-for-my-service?wsdl', plugins=[HeaderFilter()]) 
result = client.service.StartSession('userid','passwd') 

我可能是更具體的,而不是使用正則表達式,但我不知道這是否會一直使用SOAP-ENV前綴或沒有。