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.com passport >
< oem xsi:type ="NS2:guid" > {xxxxxxxx-8456-550a-8bb9-65d484f8bc3b} oem >
< codePage xsi:type ="xsd:int" > 936 codePage >
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.com passport >
< oem xsi:type ="NS2:guid" > {xxxxxxxx-8456-550a-8bb9-65d484f8bc3b} oem >
< codePage xsi:type ="xsd:int" > 936 codePage >
NS1:GetServiceInfo >
SOAP-ENV:Body >
SOAP-ENV:Envelope >
<
NS1:GetServiceInfo
xmlns:NS1
="http://goldentek.biz/"
>
< passport xsi:type ="xsd:string" > monkeyking@im.chinabubble.com passport >
< oem xsi:type ="NS2:guid" > {341a4fbb-8456-550a-8bb9-65d484f8bc3b} oem >
< codePage xsi:type ="xsd:int" > 936 codePage >
NS1:GetServiceInfo >
问题已经确定是Delphi的封装问题。进一步测试发现,在2005下的Service,如果有参数delphi都不能正确封装。难道只有把服务转到2003?或者自己封装Webservie调用?这两个方法都要很多工作量。
< passport xsi:type ="xsd:string" > monkeyking@im.chinabubble.com passport >
< oem xsi:type ="NS2:guid" > {341a4fbb-8456-550a-8bb9-65d484f8bc3b} oem >
< codePage xsi:type ="xsd:int" > 936 codePage >
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如:,这样在.net中就不能用nullable值了,如:int?
总结:
可以看出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.com passport >
< oem > {xxxxxxxx-8456-550a-8bb9-65d484f8bc3b} oem >
< codePage > 936 codePage >
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.com passport >
< oem > {xxxxxxxx-8456-550a-8bb9-65d484f8bc3b} oem >
< codePage > 936 codePage >
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.com m:passport >
< m:oem > 341a4fbb-8456-550a-8bb9-65d484f8bc3b m:oem >
< m:codePage > 936 m:codePage >
m:GetServiceInfo >
SOAP-ENV:Body >
SOAP-ENV:Envelope >
< SOAP-ENV:Body >
< m:GetServiceInfo xmlns:m ="http://goldentek.biz/" >
< m:passport > monkeyking@im.chinabubble.com m:passport >
< m:oem > 341a4fbb-8456-550a-8bb9-65d484f8bc3b m:oem >
< m:codePage > 936 m: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/,如需转载,请注明出处,否则将追究法律责任。
转载于:http://blog.itpub.net/12639172/viewspace-332350/