當前位置:首頁 » 編程語言 » python解析wsdl

python解析wsdl

發布時間: 2023-01-01 08:10:02

⑴ 在解析本地的wsdl文件時遇到如下問題,怎麼解決

一、在VS提供的命令提示符中編譯WSDL文件。
給個例子:
Wsdl /language:CS /n:mynamespace /out:myProxyClass.cs C:/myProject/wsdl/WEBservice.wsdl
最後一個參數是本地的絕對路徑,是一個文件,也可以是一個網路路徑。
二、在項目右鍵中添加WEB引用,輸入本地的WSDL的絕對路徑。
注意:用VS引用生成的代理類名稱為Reference.cs,可以在項目目錄下找到

⑵ 怎麼解析WSDL文件中的ComplexType

客戶端需要定義一個代理類PhotoItemProxy(名字隨你取),這個類的數據成員和PhotoItem應該是一樣的,
然後把這個xml讀取到代理類PhotoItemProxy里,
客戶端使用的時候,只使用代理類PhotoItemProxy,就如同使用PhotoItem類一樣,

.net web server就是這么做的,

python怎麼獲取介面返回報文

#!/usr/bin/envpython
#-*-coding:utf-8-*-
importsys,os
importhttplib
defsendSoapDataByHttp(strWsdl,strInterfaceName,strSoapDataFile
):
ifnot
os.path.isfile(strSoapDataFile):
return-1,"ArgumentError,SoapData:%sinvalid."%
strSoapDataFile
try:
f=open(strSoapDataFile,'r')
except
IOError,e:
return-1,"Failtoopenthefile:%s."%strSoapDataFile
lines=
f.readlines()
f.close()
SoapMessage=''' '''+''.join(lines)
##http://192.168.1.100:7654/services/abcMgntService?wsdl
pos=
strWsdl.find('/',7)
strHost=
strWsdl[7:pos]
strPostval=
strWsdl[pos:len(strWsdl)-5]
webservice=httplib.HTTP(strHost)
webservice.putrequest("POST",strPostval)
webservice.putheader("Host",strHost)
webservice.putheader("User-Agent","PythonPost")
webservice.putheader("Content-type","text/xml;
charset="UTF-8"")
webservice.putheader("Content-length","%d"%
len(SoapMessage))
webservice.endheaders()
webservice.send(SoapMessage)
#getthe
response
statuscode,statusmessage,header=webservice.getreply()
msg='
Response:%d%s headers:%s %s'%
(statuscode,statusmessage,header,webservice.getfile().read())
if
statuscode==200:
return0,msg
else:
return1,msg

defmain():
retCode,msg
=
sendSoapDataByHttp("http://192.168.1.100:7654/services/abcMgntService?wsdl
","do_interface_func","./soap_data.xml")
print
"Returncode:",retCode
print
msg
if__name__=='__main__':
main()

⑷ python 怎樣生成wsdl

.如果wsdl比較復雜,比如有多個service和port,使用client.service[service][port].getBank(),
如果不指定,默認是第一service的第一個port的第一個method
下面的就可以寫成這樣
client.service['OtherBLZService']['soap'].getBank()
client.service[1][0].getBank()

Suds - version: 0.3.7 build: (beta) R550-20090820

Service (BLZService) tns="
Prefixes (1)
ns0 = "
Ports (2):
(soap)
Methods (1):
getBank(xs:string blz, )
(soap12)
Methods (1):
getBank(xs:string blz, )
Types (5):
getBankType
getBankResponseType
getBankType
getBankResponseType
detailsType

Service (OtherBLZService) tns="
Prefixes (1)
ns0 = "
Ports (2):
(soap)
Methods (1):
getBank(xs:string blz, )
(soap12)
Methods (1):
getBank(xs:string blz, )
Types (5):
getBankType
getBankResponseType
getBankType
getBankResponseType
detailsType

⑸ 用java 調用python webservice 是怎麼調的

這次出差,我接觸最多的是spss,由於項目基於j2ee開發,而java又不能直接取得spss統計結果,好在spss對python的支持還行,最終成功實現了這個模塊。感謝前輩們做出的貢獻,沒有你們,我就不能這樣迅速、順利的完成項目,且別說寫這篇文章了。
在前期准備中,我摸索、嘗試了三種實現:jython,http,soap,在網上查了很多相關資料,都是只言片語,自己看了還要結合其他的資料才能弄個明白。當然,在這探索的過程中,我是幸運的,每天都讓我充滿驚喜,每天都有新的收獲。
jython是java版本的python,也就是java的完全實現。java代碼中,可以調用python的方法,缺點是,jython中導入第三方python mole時,不是那麼回事。因為spss的python api主要是一個.pyd的二進制文件,jython導包是按照java的位元組碼來導入的,所以當在jython中導入spss的python api時會出錯,這個想法徹底破滅。
http實現是在現有的B/S交互實現上突發奇想的,python中實現一個簡單的web server只要幾十行代碼,java使用apache的httpclient訪問,現在想來確實有點大材小用,自己寫一個http socket來請求和響應也寫不了多少代碼。最後還是實現了,支持spss中文,但是數據封包都要自己來實現,還是有嫌麻煩。
soap實現最簡單,server端幾十行代碼搞定。由於我把spss命令都封裝到一個方法中執行了,所以就沒有用wsdl來生成java代碼了,我使用了較底層的java的http socket,手動對SOAP-ENV打包,並向server端請求,手動解析響應數據。缺點是:SOAP對中文的支持,無論怎麼轉碼,不是python解析SOAP-ENV報錯,就是python執行spss命令報錯。

⑹ eclipse解析wsdl文件 怎麼獲取wsdl信息

一個WSDL文檔通常包含7個重要的元素,即types、import、message、portType、operation、binding、 service元素。
這些元素嵌套在definitions元素中,
(1) Definitions是WSDL文檔的根元素。對應於這個類: org.eclipse.wst.wsdl.Definition 其他的對象都可以通過這個對象獲得
(2) Types - 數據類型定義的容器,它使用某種類型系統(一般地使用XML Schema中的類型系統)。
(3) Message - 通信消息的數據結構的抽象類型化定義。使用Types所定義的類型來定義整個消息的數據結構。
(4) PortType - 對於某個訪問入口點類型所支持的操作的抽象集合,這些操作可以由一個或多個服務訪問點來支持。
(子節點) Operation - 對服務中所支持的操作的抽象描述,一般單個Operation描述了一個訪問入口的請求/響應消息對。
(5) Binding - 特定埠類型的具體協議和數據格式規范的綁定。
(6) Service- 相關服務訪問點的集合。

(子節點) Port - 定義為協議/數據格式綁定與具體Web訪問地址組合的單個服務訪問點。

下面是代碼實例:
import java.io.File; import java.io.IOException; import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.Set; import javax.wsdl.Message; import javax.wsdl.Part; import javax.wsdl.PortType; import javax.xml.namespace.QName; import org.eclipse.emf.common.util.URI; import org.eclipse.emf.ecore.resource.Resource; import org.eclipse.emf.ecore.resource.ResourceSet; import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl; import org.eclipse.wst.wsdl.Definition; import org.eclipse.wst.wsdl.Types; import org.eclipse.wst.wsdl.internal.impl.PartImpl; import org.eclipse.wst.wsdl.internal.util.WSDLResourceFactoryImpl; import org.eclipse.wst.wsdl.util.WSDLResourceImpl; import org.eclipse.xsd.XSDElementDeclaration; import org.eclipse.xsd.XSDSchema; import org.eclipse.xsd.util.XSDResourceImpl; import org.junit.Test; import org.junit.Before; public class WSDLParserWithEclipse { Definition definition=null; String wsdlPathString="E:/HelloEclipse-EMF-WSDL-XSD/test.wsdl"; @Before public void setup(){ ResourceSet resourceSet = new ResourceSetImpl(); Resource.Factory.Registry registry = resourceSet.getResourceFactoryRegistry(); Map extensionToFactoryMap = registry.getExtensionToFactoryMap(); extensionToFactoryMap.put("wsdl", new WSDLResourceFactoryImpl()); File wsdlFile =new File(wsdlPathString); URI uri = URI.createFileURI(wsdlFile.getAbsolutePath()); // You can avoid this cast, but will have to cast anyway later to get the Definition out the resource contents WSDLResourceImpl wsdlResource = (WSDLResourceImpl) resourceSet.createResource(uri); try { wsdlResource.load(null); definition = wsdlResource.getDefinition(); }catch(Exception e){ e.printStackTrace(); } } @Test public void testTypes(){ Types types = definition.getETypes(); List schemas = types.getSchemas("http://www.xxxxx.com/problem"); XSDSchema schema = (XSDSchema) schemas.get(0); org.eclipse.xsd.util.XSDResourceImpl.serialize(System.out, schema.getElement()); } @Test public void testMessage(){ Map messages=definition.getMessages(); System.out.println("The message size is:"+messages.size()); Set setMessages=messages.keySet(); Iterator iteratorMessages=setMessages.iterator(); while(iteratorMessages.hasNext()){ QName key=(QName)iteratorMessages.next(); Message message=(Message)messages.get(key); //{http://www.xxxxx.com/problem}getKeysSoapIn //System.out.println("Message Name:"+message.getQName()); if(message.getQName().toString().indexOf("getKeysSoapIn")>0){ System.out.println("Message Name:"+message.getQName()); Map partsMap=message.getParts(); //org.eclipse.xsd.impl.XSDElementDeclarationImpl System.out.println("Message Part size for getKeysSoapIn message is:"+partsMap.size()); PartImpl part= (PartImpl)partsMap.get("problem"); XSDElementDeclaration xsdElementDeclaration=part.getElementDeclaration(); XSDResourceImpl.serialize(System.out, xsdElementDeclaration.getElement()); } } } @Test public void testPortType(){ Map portTypes=definition.getPortTypes(); System.out.println("Port Type size:"+portTypes.size()); if(portTypes!=null&&portTypes.size()>0){ Set set=portTypes.keySet(); Iterator iterator=set.iterator(); while(iterator.hasNext()){ QName object=(QName)iterator.next(); PortType portType=(PortType)portTypes.get(object); System.out.println("Port Type name:"+portType.getQName()); org.eclipse.xsd.util.XSDResourceImpl.serialize(System.out, portType.getDocumentationElement()); } } } }

⑺ 如何調用別人提供的webservice介面

在項目中選擇【控制台應用程序】,點擊項目右鍵,選擇添加->服務引用。在地址欄中輸入WebServie鏈接地址後回車,點擊確定後在代碼中就可以看到添加的服務應用了,詳細步驟:

1、首先打開VS2013,選擇文件->新建->項目。

⑻ wsdl4j 如何解析import的wsdl文件

請問如何解析WSDL文件中的復雜類型 ? 比如說服務端定義了一個類PhotoItem,客戶端需要定義一個代理類PhotoItemProxy(名字隨你取),這個類的數據成員和,Ivsspv

⑼ python suds wsdl 用戶么

最近做介面對接,遇到了.net開發的webservice介面,因為python第一次與webservice對接,連問帶查,最後使用suds庫來實現了
1.安裝suds
mac: sudo pip install suds
linux: easy_install suds
也可以通過去官網下載suds代碼,再本地安裝
2. 引用初始化

1 >>> from suds.client import Client
2 >>> url = ''
3 >>> client = Client(url)
4 >>> print client
5
6 Suds ( ) version: 0.4 GA build: R699-20100913
7
8 Service ( Kuaidi ) tns=""
9 Prefixes (1)
10 ns0 = ""
11 Ports (2):
12 (KuaidiSoap)
13 Methods (1):
14 KuaidiQuery(xs:string Compay, xs:string OrderNo, )
15 Types (1):
16 ApiSoapHeader
17 (KuaidiSoap12)
18 Methods (1):
19 KuaidiQuery(xs:string Compay, xs:string OrderNo, )
20 Types (1):
21 ApiSoapHeader
22 >>>

對url做一下說明,一般要確認給的wsdl地址是正常模式,地址打開一般為xml格式而有些服務是做成了html模式,這個會導致實例化或者調用方法的時候出現xml解析異常。
3. 方法調用
2中的client列印出來就可以知道,該webserviece服務定義了什麼方法,方法需要什麼參數,聲明了什麼信息等(如頭信息,ApiSoapHeader),方法可以通過client.serviece直接調用

>>> client.service.KuaidiQuery(Company='EMS', OrderNo='1111')
(KuaidiQueryResult){
API =
(API){
RESULTS = "0"
MESSAGE = "介面查詢成功"
}
}
>>>

而聲明的頭信息,則可以用factory的方式去實例化

>>> header = client.factory.create('ApiSoapHeader')
>>> print header
(ApiSoapHeader){
APICode = None
APIKey = None
}
>>> header.APICode = '123'
>>> header.APIKey = 'key123'
>>> print header
(ApiSoapHeader){
APICode = "123"
APIKey = "key123"
}
>>>

頭信息需要用set_options方法設置
>>>
>>> client.set_options(soapheaders=[header,])
>>>

⑽ soapui解析wsdl文件報錯,如何解決

這個問題,我剛才解決了:
是有一個證書認證,將tomcat中server.
xml文件
中clientAuth="
true
",改為clientAuth="
want"這樣就沒問題,add
wsdl路徑沒有問題。

熱點內容
存儲器的原理與工程 發布:2025-07-02 23:21:17 瀏覽:406
linuxsnmp安裝 發布:2025-07-02 23:07:08 瀏覽:650
北理c語言答案 發布:2025-07-02 23:05:57 瀏覽:304
sql同比 發布:2025-07-02 23:03:39 瀏覽:835
一個伺服器獲取多個ip 發布:2025-07-02 23:02:43 瀏覽:786
三星電腦wifi怎麼連接wifi密碼 發布:2025-07-02 22:55:00 瀏覽:712
安卓開發選哪個版本的SDK 發布:2025-07-02 22:19:07 瀏覽:486
未上傳圖片 發布:2025-07-02 22:14:01 瀏覽:599
安卓qq直播怎麼分享聲音 發布:2025-07-02 22:13:21 瀏覽:250
安卓系統怎麼刷機清除內存 發布:2025-07-02 22:08:19 瀏覽:697