【dinghao】delphi對.net2.0webservice封裝問題
delphi呼叫WebService一直髮生500錯誤,可是同樣的Service用.net呼叫,xmlspy呼叫都沒有問題。因此估計Delphi對Service的封裝有問題。
跟蹤發現:竟然沒有引數傳遞給Webservice,引數或者是null或者是初始值。通過檢視Post的資料包:
下面先看一下2003和2005生成的wsdl的不同點(完整wsdl看附錄):
1、2005增加了對soap1.2的支援
2、2005如果沒有描述會沒有<documentation xmlns="http://schemas.xmlsoap.org/wsdl/" /> 標記。
3、2005沒有顯式設定styly,而採用的是預設值 <soap12:binding transport="http://schemas.xmlsoap.org/soap/http" />
第二個可以排除,它不會產生這樣的錯誤,最有可能的是第一條,delphi對soap1.2支援不好。而且發現:“User-Agent: Borland SOAP 1.2”,證明delphi確實用的是Soap1.2。手動修改Wsdl,去掉對1.2的支援重新生成代理類,測試扔出現問題。
是第三個?可是省略style也是符合wsdl規範的。修改wsdl加上style,測試成功。真是沒有想到會是這裡的問題,修改起來竟是如此簡單!
後面還發現delphi不能正確解析nil如: ,這樣在.net中就不能用nullable值了,如:int?
總結:
可以看出delphi對webservie的封裝還是很有問題的,規範都沒有實現!對xml的支援也不完善。
因此在webservice的開發中不要用高階的特性,因為某些語言對service的封裝還是不好。
還真是懷疑wse的前途,還是因為某些語言呼叫起來很麻煩。
附:
正確的Post格式
1、
<!--
Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/
--> [WebMethod]
public string HelloWorld(string s) {
string t = s;
return "Hello World";
}
<!--
Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/
--> xml version="1.0" encoding="utf-8" ?>
- <wsdl:definitions xmlns:http="http://schemas.xmlsoap.org/wsdl/http/" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:s="http://www.w3.org/2001/XMLSchema" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:tns="http://tempuri.org/" xmlns:tm="http://microsoft.com/wsdl/mime/textMatching/" xmlns:mime="http://schemas.xmlsoap.org/wsdl/mime/" targetNamespace="http://tempuri.org/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/">
- <wsdl:types>
- <s:schema elementFormDefault="qualified" targetNamespace="http://tempuri.org/">
- <s:element name="HelloWorld">
- <s:complexType>
- <s:sequence>
<s:element minOccurs="0" maxOccurs="1" name="s" type="s:string" />
s:sequence>
s:complexType>
s:element>
- <s:element name="HelloWorldResponse">
- <s:complexType>
- <s:sequence>
<s:element minOccurs="0" maxOccurs="1" name="HelloWorldResult" type="s:string" />
s:sequence>
s:complexType>
s:element>
s:schema>
wsdl:types>
- <wsdl:message name="HelloWorldSoapIn">
<wsdl:part name="parameters" element="tns:HelloWorld" />
wsdl:message>
- <wsdl:message name="HelloWorldSoapOut">
<wsdl:part name="parameters" element="tns:HelloWorldResponse" />
wsdl:message>
- <wsdl:portType name="Service1Soap">
- <wsdl:operation name="HelloWorld">
<wsdl:input message="tns:HelloWorldSoapIn" />
<wsdl:output message="tns:HelloWorldSoapOut" />
wsdl:operation>
wsdl:portType>
- <wsdl:binding name="Service1Soap" type="tns:Service1Soap">
<soap:binding transport="http://schemas.xmlsoap.org/soap/http" style="document" />
+ <wsdl:operation name="HelloWorld">
<soap:operation soapAction="http://tempuri.org/HelloWorld" style="document" />
- <wsdl:input>
<soap:body use="literal" />
wsdl:input>
- <wsdl:output>
<soap:body use="literal" />
wsdl:output>
wsdl:operation>
wsdl:binding>
- <wsdl:service name="Service1">
<documentation xmlns="http://schemas.xmlsoap.org/wsdl/" />
- <wsdl:port name="Service1Soap" binding="tns:Service1Soap">
<soap:address location="http://localhost/WebService1/Service1.asmx" />
wsdl:port>
wsdl:service>
wsdl:definitions>
<!--
Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/
--> xml version="1.0" encoding="utf-8" ?>
- <wsdl:definitions xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:tm="http://microsoft.com/wsdl/mime/textMatching/" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:mime="http://schemas.xmlsoap.org/wsdl/mime/" xmlns:tns="http://tempuri.org/" xmlns:s="http://www.w3.org/2001/XMLSchema" xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/" xmlns:http="http://schemas.xmlsoap.org/wsdl/http/" targetNamespace="http://tempuri.org/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/">
- <wsdl:types>
- <s:schema elementFormDefault="qualified" targetNamespace="http://tempuri.org/">
- <s:element name="HelloWorld">
- <s:complexType>
- <s:sequence>
<s:element minOccurs="0" maxOccurs="1" name="s" type="s:string" />
s:sequence>
s:complexType>
s:element>
- <s:element name="HelloWorldResponse">
- <s:complexType>
- <s:sequence>
<s:element minOccurs="0" maxOccurs="1" name="HelloWorldResult" type="s:string" />
s:sequence>
s:complexType>
s:element>
s:schema>
wsdl:types>
- <wsdl:message name="HelloWorldSoapIn">
<wsdl:part name="parameters" element="tns:HelloWorld" />
wsdl:message>
- <wsdl:message name="HelloWorldSoapOut">
<wsdl:part name="parameters" element="tns:HelloWorldResponse" />
wsdl:message>
- <wsdl:portType name="ServiceSoap">
- <wsdl:operation name="HelloWorld">
<wsdl:input message="tns:HelloWorldSoapIn" />
<wsdl:output message="tns:HelloWorldSoapOut" />
wsdl:operation>
wsdl:portType>
- <wsdl:binding name="ServiceSoap" type="tns:ServiceSoap">
<soap:binding transport="http://schemas.xmlsoap.org/soap/http" />
- <wsdl:operation name="HelloWorld">
<soap:operation soapAction="http://tempuri.org/HelloWorld" style="document" />
- <wsdl:input>
<soap:body use="literal" />
wsdl:input>
- <wsdl:output>
<soap:body use="literal" />
wsdl:output>
wsdl:operation>
wsdl:binding>
- <wsdl:binding name="ServiceSoap12" type="tns:ServiceSoap">
<soap12:binding transport="http://schemas.xmlsoap.org/soap/http" />
- <wsdl:operation name="HelloWorld">
<soap12:operation soapAction="http://tempuri.org/HelloWorld" style="document" />
- <wsdl:input>
<soap12:body use="literal" />
wsdl:input>
- <wsdl:output>
<soap12:body use="literal" />
wsdl:output>
wsdl:operation>
wsdl:binding>
- <wsdl:service name="Service">
- <wsdl:port
跟蹤發現:竟然沒有引數傳遞給Webservice,引數或者是null或者是初始值。通過檢視Post的資料包:
xml version="1.0"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xm
lns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XML
Schema-instance" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/">
<SOAP-ENV:Body SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encodin
g/" xmlns:NS2="http://microsoft.com/wsdl/types/">
<NS1:GetServiceInfo xmlns:NS1="http://goldentek.biz/">
<passport xsi:type="xsd:string">xxx@im.chinabubble.compassport>
<oem xsi:type="NS2:guid">{xxxxxxxx-8456-550a-8bb9-65d484f8bc3b}oem>
<codePage xsi:type="xsd:int">936codePage>
NS1:GetServiceInfo>
SOAP-ENV:Body>
SOAP-ENV:Envelope>
發現以下部分不正確:
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xm
lns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XML
Schema-instance" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/">
<SOAP-ENV:Body SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encodin
g/" xmlns:NS2="http://microsoft.com/wsdl/types/">
<NS1:GetServiceInfo xmlns:NS1="http://goldentek.biz/">
<passport xsi:type="xsd:string">xxx@im.chinabubble.compassport>
<oem xsi:type="NS2:guid">{xxxxxxxx-8456-550a-8bb9-65d484f8bc3b}oem>
<codePage xsi:type="xsd:int">936codePage>
NS1:GetServiceInfo>
SOAP-ENV:Body>
SOAP-ENV:Envelope>
<NS1:GetServiceInfo xmlns:NS1="http://goldentek.biz/">
<passport xsi:type="xsd:string">monkeyking@im.chinabubble.compassport>
<oem xsi:type="NS2:guid">{341a4fbb-8456-550a-8bb9-65d484f8bc3b}oem>
<codePage xsi:type="xsd:int">936codePage>
NS1:GetServiceInfo>
問題已經確定是Delphi的封裝問題。進一步測試發現,在2005下的Service,如果有引數delphi都不能正確封裝。難道只有把服務轉到2003?或者自己封裝Webservie呼叫?這兩個方法都要很多工作量。<passport xsi:type="xsd:string">monkeyking@im.chinabubble.compassport>
<oem xsi:type="NS2:guid">{341a4fbb-8456-550a-8bb9-65d484f8bc3b}oem>
<codePage xsi:type="xsd:int">936codePage>
NS1:GetServiceInfo>
下面先看一下2003和2005生成的wsdl的不同點(完整wsdl看附錄):
1、2005增加了對soap1.2的支援
2、2005如果沒有描述會沒有<documentation xmlns="http://schemas.xmlsoap.org/wsdl/" /> 標記。
3、2005沒有顯式設定styly,而採用的是預設值 <soap12:binding transport="http://schemas.xmlsoap.org/soap/http" />
第二個可以排除,它不會產生這樣的錯誤,最有可能的是第一條,delphi對soap1.2支援不好。而且發現:“User-Agent: Borland SOAP 1.2”,證明delphi確實用的是Soap1.2。手動修改Wsdl,去掉對1.2的支援重新生成代理類,測試扔出現問題。
是第三個?可是省略style也是符合wsdl規範的。修改wsdl加上style,測試成功。真是沒有想到會是這裡的問題,修改起來竟是如此簡單!
後面還發現delphi不能正確解析nil如:
總結:
可以看出delphi對webservie的封裝還是很有問題的,規範都沒有實現!對xml的支援也不完善。
因此在webservice的開發中不要用高階的特性,因為某些語言對service的封裝還是不好。
還真是懷疑wse的前途,還是因為某些語言呼叫起來很麻煩。
附:
正確的Post格式
1、
xml version="1.0"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xm
lns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XML
Schema-instance">
<SOAP-ENV:Body>
<GetServiceInfo xmlns="http://goldentek.biz/">
<passport>xxxxx@im.chinabubble.compassport>
<oem>{xxxxxxxx-8456-550a-8bb9-65d484f8bc3b}oem>
<codePage>936codePage>
GetServiceInfo>
SOAP-ENV:Body>
SOAP-ENV:Envelope>
2、<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xm
lns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XML
Schema-instance">
<SOAP-ENV:Body>
<GetServiceInfo xmlns="http://goldentek.biz/">
<passport>xxxxx@im.chinabubble.compassport>
<oem>{xxxxxxxx-8456-550a-8bb9-65d484f8bc3b}oem>
<codePage>936codePage>
GetServiceInfo>
SOAP-ENV:Body>
SOAP-ENV:Envelope>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<SOAP-ENV:Body>
<m:GetServiceInfo xmlns:m="http://goldentek.biz/">
<m:passport>monkeyking@im.chinabubble.comm:passport>
<m:oem>341a4fbb-8456-550a-8bb9-65d484f8bc3bm:oem>
<m:codePage>936m:codePage>
m:GetServiceInfo>
SOAP-ENV:Body>
SOAP-ENV:Envelope>
<SOAP-ENV:Body>
<m:GetServiceInfo xmlns:m="http://goldentek.biz/">
<m:passport>monkeyking@im.chinabubble.comm:passport>
<m:oem>341a4fbb-8456-550a-8bb9-65d484f8bc3bm:oem>
<m:codePage>936m:codePage>
m:GetServiceInfo>
SOAP-ENV:Body>
SOAP-ENV:Envelope>
wsdl規範:
http://www.w3.org/TR/2004/WD-wsdl20-primer-20041221/
下面是1.1和2.0的wsdl,webmethod是:
<!--
Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/
--> [WebMethod]
public string HelloWorld(string s) {
string t = s;
return "Hello World";
}
.net1.1生成的wsdl:
<!--
Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/
--> xml version="1.0" encoding="utf-8" ?>
- <wsdl:definitions xmlns:http="http://schemas.xmlsoap.org/wsdl/http/" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:s="http://www.w3.org/2001/XMLSchema" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:tns="http://tempuri.org/" xmlns:tm="http://microsoft.com/wsdl/mime/textMatching/" xmlns:mime="http://schemas.xmlsoap.org/wsdl/mime/" targetNamespace="http://tempuri.org/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/">
- <wsdl:types>
- <s:schema elementFormDefault="qualified" targetNamespace="http://tempuri.org/">
- <s:element name="HelloWorld">
- <s:complexType>
- <s:sequence>
<s:element minOccurs="0" maxOccurs="1" name="s" type="s:string" />
s:sequence>
s:complexType>
s:element>
- <s:element name="HelloWorldResponse">
- <s:complexType>
- <s:sequence>
<s:element minOccurs="0" maxOccurs="1" name="HelloWorldResult" type="s:string" />
s:sequence>
s:complexType>
s:element>
s:schema>
wsdl:types>
- <wsdl:message name="HelloWorldSoapIn">
<wsdl:part name="parameters" element="tns:HelloWorld" />
wsdl:message>
- <wsdl:message name="HelloWorldSoapOut">
<wsdl:part name="parameters" element="tns:HelloWorldResponse" />
wsdl:message>
- <wsdl:portType name="Service1Soap">
- <wsdl:operation name="HelloWorld">
<wsdl:input message="tns:HelloWorldSoapIn" />
<wsdl:output message="tns:HelloWorldSoapOut" />
wsdl:operation>
wsdl:portType>
- <wsdl:binding name="Service1Soap" type="tns:Service1Soap">
<soap:binding transport="http://schemas.xmlsoap.org/soap/http" style="document" />
+ <wsdl:operation name="HelloWorld">
<soap:operation soapAction="http://tempuri.org/HelloWorld" style="document" />
- <wsdl:input>
<soap:body use="literal" />
wsdl:input>
- <wsdl:output>
<soap:body use="literal" />
wsdl:output>
wsdl:operation>
wsdl:binding>
- <wsdl:service name="Service1">
<documentation xmlns="http://schemas.xmlsoap.org/wsdl/" />
- <wsdl:port name="Service1Soap" binding="tns:Service1Soap">
<soap:address location="http://localhost/WebService1/Service1.asmx" />
wsdl:port>
wsdl:service>
wsdl:definitions>
.net2.0生成的wsdl:
<!--
Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/
--> xml version="1.0" encoding="utf-8" ?>
- <wsdl:definitions xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:tm="http://microsoft.com/wsdl/mime/textMatching/" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:mime="http://schemas.xmlsoap.org/wsdl/mime/" xmlns:tns="http://tempuri.org/" xmlns:s="http://www.w3.org/2001/XMLSchema" xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/" xmlns:http="http://schemas.xmlsoap.org/wsdl/http/" targetNamespace="http://tempuri.org/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/">
- <wsdl:types>
- <s:schema elementFormDefault="qualified" targetNamespace="http://tempuri.org/">
- <s:element name="HelloWorld">
- <s:complexType>
- <s:sequence>
<s:element minOccurs="0" maxOccurs="1" name="s" type="s:string" />
s:sequence>
s:complexType>
s:element>
- <s:element name="HelloWorldResponse">
- <s:complexType>
- <s:sequence>
<s:element minOccurs="0" maxOccurs="1" name="HelloWorldResult" type="s:string" />
s:sequence>
s:complexType>
s:element>
s:schema>
wsdl:types>
- <wsdl:message name="HelloWorldSoapIn">
<wsdl:part name="parameters" element="tns:HelloWorld" />
wsdl:message>
- <wsdl:message name="HelloWorldSoapOut">
<wsdl:part name="parameters" element="tns:HelloWorldResponse" />
wsdl:message>
- <wsdl:portType name="ServiceSoap">
- <wsdl:operation name="HelloWorld">
<wsdl:input message="tns:HelloWorldSoapIn" />
<wsdl:output message="tns:HelloWorldSoapOut" />
wsdl:operation>
wsdl:portType>
- <wsdl:binding name="ServiceSoap" type="tns:ServiceSoap">
<soap:binding transport="http://schemas.xmlsoap.org/soap/http" />
- <wsdl:operation name="HelloWorld">
<soap:operation soapAction="http://tempuri.org/HelloWorld" style="document" />
- <wsdl:input>
<soap:body use="literal" />
wsdl:input>
- <wsdl:output>
<soap:body use="literal" />
wsdl:output>
wsdl:operation>
wsdl:binding>
- <wsdl:binding name="ServiceSoap12" type="tns:ServiceSoap">
<soap12:binding transport="http://schemas.xmlsoap.org/soap/http" />
- <wsdl:operation name="HelloWorld">
<soap12:operation soapAction="http://tempuri.org/HelloWorld" style="document" />
- <wsdl:input>
<soap12:body use="literal" />
wsdl:input>
- <wsdl:output>
<soap12:body use="literal" />
wsdl:output>
wsdl:operation>
wsdl:binding>
- <wsdl:service name="Service">
- <wsdl:port
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/12639172/viewspace-332350/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- 簡單問題,封裝和框架!封裝框架
- ESP32系列晶片涉及封裝問題晶片封裝
- 重學前端(8)封裝ajax,http,跨域問題前端封裝HTTP跨域
- LFI、RFI、PHP封裝協議安全問題學習PHP封裝協議
- 聊聊redisTemplate對lettuce的封裝Redis封裝
- 對FMDB物件導向封裝物件封裝
- DELPHI四捨五入問題解決
- jsp呼叫javabean封裝資料庫的問題,急!JSJavaBean封裝資料庫
- jsp呼叫javabean,javabean封裝資料庫的問題JSJavaBean封裝資料庫
- Delphi 根據資料庫表生成Record型別,並封裝CRUD資料庫型別封裝
- go對get、post請求封裝Go封裝
- 對getElementsByTagName()方法簡單封裝封裝
- Delphi連線mysql中文字元問題MySql字元
- DELPHI開發Web程式常見問題 (轉)Web
- MySQL JDBC常用知識,封裝工具類,時區問題配置,SQL隱碼攻擊問題MySqlJDBC封裝
- 刨根問底ajax原理與封裝封裝
- 對Flutter路由管理庫Fluro的封裝Flutter路由封裝
- Golang 對MongoDB的操作簡單封裝GolangMongoDB封裝
- vue-cli 3.0 + 對 axios 封裝VueiOS封裝
- vue中對axios進行封裝VueiOS封裝
- android常用對話方塊封裝Android封裝
- 無依賴開發中的碰到的問題——封裝DOM操作封裝
- banq老師,關於將ResultSet封裝成List返回的問題封裝
- 對 Observer進行包裝,遇到一些問題Server
- 【封裝那些事】 缺失封裝封裝
- js ajax請求封裝及解決node請求跨域問題JS封裝跨域
- 關於Delphi中TRttiContext.FindType失效的問題Context
- c#封裝、訪問修飾符C#封裝
- 通過JNI對C++進行封裝C++封裝
- 對AlamofireObjectMapper進行二次封裝ObjectAPP封裝
- 對策問題
- 元件化封裝之標題欄Toolbar元件化封裝
- 封裝封裝
- 對api請求封裝的探索和總結API封裝
- 對於封裝react元件的一些思考封裝React元件
- 在RN專案上對axios的封裝iOS封裝
- 原生javascript對ajax的封裝程式碼例項JavaScript封裝
- 對友盟分享(Umeng-Share)的功能封裝封裝