【dinghao】delphi对.net2.0webservice封装问题

 delphi调用WebService一直发生500错误,可是同样的Service用.net调用,xmlspy调用都没有问题。因此估计Delphi对Service的封装有问题。
    跟踪发现:竟然没有参数传递给Webservice,参数或者是null或者是初始值。通过查看Post的数据包:
 
None.gif                xml version="1.0" ?>
None.gif              
< SOAP-ENV:Envelope  xmlns:SOAP-ENV ="http://schemas.xmlsoap.org/soap/envelope/"  xm
None.gif              lns:xsd
="http://www.w3.org/2001/XMLSchema"  xmlns:xsi ="http://www.w3.org/2001/XML
None.gif              Schema-instance"
 xmlns:SOAP-ENC ="http://schemas.xmlsoap.org/soap/encoding/" >
None.gif                
< SOAP-ENV:Body  SOAP-ENV:encodingStyle ="http://schemas.xmlsoap.org/soap/encodin
None.gif              g/"
 xmlns:NS2 ="http://microsoft.com/wsdl/types/" >
None.gif                  
< NS1:GetServiceInfo  xmlns:NS1 ="http://goldentek.biz/" >
None.gif                    
< passport  xsi:type ="xsd:string" > xxx@im.chinabubble.com passport >
None.gif                    
< oem  xsi:type ="NS2:guid" > {xxxxxxxx-8456-550a-8bb9-65d484f8bc3b} oem >
None.gif                    
< codePage  xsi:type ="xsd:int" > 936 codePage >
None.gif                  
NS1:GetServiceInfo >
None.gif                
SOAP-ENV:Body >
None.gif              
SOAP-ENV:Envelope >
None.gif
发现以下部分不正确:
None.gif                    < NS1:GetServiceInfo  xmlns:NS1 ="http://goldentek.biz/" >
None.gif                    
< passport  xsi:type ="xsd:string" > monkeyking@im.chinabubble.com passport >
None.gif                    
< oem  xsi:type ="NS2:guid" > {341a4fbb-8456-550a-8bb9-65d484f8bc3b} oem >
None.gif                    
< codePage  xsi:type ="xsd:int" > 936 codePage >
None.gif                  
NS1:GetServiceInfo >
None.gif
    问题已经确定是Delphi的封装问题。进一步测试发现,在2005下的Service,如果有参数delphi都不能正确封装。难道只有把服务转到2003?或者自己封装Webservie调用?这两个方法都要很多工作量。
    下面先看一下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、
None.gif                xml version="1.0" ?>
None.gif              
< SOAP-ENV:Envelope  xmlns:SOAP-ENV ="http://schemas.xmlsoap.org/soap/envelope/"  xm
None.gif              lns:xsd
="http://www.w3.org/2001/XMLSchema"  xmlns:xsi ="http://www.w3.org/2001/XML
None.gif              Schema-instance"
>
None.gif                
< SOAP-ENV:Body >
None.gif                  
< GetServiceInfo  xmlns ="http://goldentek.biz/" >
None.gif                    
< passport > xxxxx@im.chinabubble.com passport >
None.gif                    
< oem > {xxxxxxxx-8456-550a-8bb9-65d484f8bc3b} oem >
None.gif                    
< codePage > 936 codePage >
None.gif                  
GetServiceInfo >
None.gif                
SOAP-ENV:Body >
None.gif              
SOAP-ENV:Envelope >
None.gif
2、
None.gif < 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" >
None.gif    
< SOAP-ENV:Body >
None.gif        
< m:GetServiceInfo  xmlns:m ="http://goldentek.biz/" >
None.gif            
< m:passport > monkeyking@im.chinabubble.com m:passport >
None.gif            
< m:oem > 341a4fbb-8456-550a-8bb9-65d484f8bc3b m:oem >
None.gif            
< m:codePage > 936 m:codePage >
None.gif        
m:GetServiceInfo >
None.gif    
SOAP-ENV:Body >
None.gif
SOAP-ENV:Envelope >

wsdl规范:
http://www.w3.org/TR/2004/WD-wsdl20-primer-20041221/

下面是1.1和2.0的wsdl,webmethod是:

ContractedBlock.gif ExpandedBlockStart.gif
<!--

Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/

--&gtNone.gif [WebMethod]
None.gif    public string HelloWorld(string s) {
None.gif        string t = s;
None.gif        return "Hello World";
None.gif    }



.net1.1生成的wsdl:

ContractedBlock.gif ExpandedBlockStart.gif
<!--

Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/

--&gtNone.gif  xml version="1.0" encoding="utf-8" ?> 
None.gif
<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/">
None.gif
<wsdl:types>
None.gif
<s:schema elementFormDefault="qualified" targetNamespace="http://tempuri.org/">
None.gif
<s:element name="HelloWorld">
None.gif
<s:complexType>
None.gif
<s:sequence>
None.gif  
<s:element minOccurs="0" maxOccurs="1" name="s" type="s:string" /> 
None.gif  
s:sequence>
None.gif  
s:complexType>
None.gif  
s:element>
None.gif
<s:element name="HelloWorldResponse">
None.gif
<s:complexType>
None.gif
<s:sequence>
None.gif  
<s:element minOccurs="0" maxOccurs="1" name="HelloWorldResult" type="s:string" /> 
None.gif  
s:sequence>
None.gif  
s:complexType>
None.gif  
s:element>
None.gif  
s:schema>
None.gif  
wsdl:types>
None.gif
<wsdl:message name="HelloWorldSoapIn">
None.gif  
<wsdl:part name="parameters" element="tns:HelloWorld" /> 
None.gif  
wsdl:message>
None.gif
<wsdl:message name="HelloWorldSoapOut">
None.gif  
<wsdl:part name="parameters" element="tns:HelloWorldResponse" /> 
None.gif  
wsdl:message>
None.gif
<wsdl:portType name="Service1Soap">
None.gif
<wsdl:operation name="HelloWorld">
None.gif  
<wsdl:input message="tns:HelloWorldSoapIn" /> 
None.gif  
<wsdl:output message="tns:HelloWorldSoapOut" /> 
None.gif  
wsdl:operation>
None.gif  
wsdl:portType>
None.gif
<wsdl:binding name="Service1Soap" type="tns:Service1Soap">
None.gif  
<soap:binding transport="http://schemas.xmlsoap.org/soap/http" style="document" /> 
None.gif
<wsdl:operation name="HelloWorld">
None.gif  
<soap:operation soapAction="http://tempuri.org/HelloWorld" style="document" /> 
None.gif
<wsdl:input>
None.gif  
<soap:body use="literal" /> 
None.gif  
wsdl:input>
None.gif
<wsdl:output>
None.gif  
<soap:body use="literal" /> 
None.gif  
wsdl:output>
None.gif  
wsdl:operation>
None.gif  
wsdl:binding>
None.gif
<wsdl:service name="Service1">
None.gif  
<documentation xmlns="http://schemas.xmlsoap.org/wsdl/" /> 
None.gif
<wsdl:port name="Service1Soap" binding="tns:Service1Soap">
None.gif  
<soap:address location="http://localhost/WebService1/Service1.asmx" /> 
None.gif  
wsdl:port>
None.gif  
wsdl:service>
None.gif  
wsdl:definitions>


.net2.0生成的wsdl:

ContractedBlock.gif ExpandedBlockStart.gif
<!--

Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/

--&gtNone.gif  xml version="1.0" encoding="utf-8" ?> 
None.gif
<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/">
None.gif
<wsdl:types>
None.gif
<s:schema elementFormDefault="qualified" targetNamespace="http://tempuri.org/">
None.gif
<s:element name="HelloWorld">
None.gif
<s:complexType>
None.gif
<s:sequence>
None.gif  
<s:element minOccurs="0" maxOccurs="1" name="s" type="s:string" /> 
None.gif  
s:sequence>
None.gif  
s:complexType>
None.gif  
s:element>
None.gif
<s:element name="HelloWorldResponse">
None.gif
<s:complexType>
None.gif
<s:sequence>
None.gif  
<s:element minOccurs="0" maxOccurs="1" name="HelloWorldResult" type="s:string" /> 
None.gif  
s:sequence>
None.gif  
s:complexType>
None.gif  
s:element>
None.gif  
s:schema>
None.gif  
wsdl:types>
None.gif
<wsdl:message name="HelloWorldSoapIn">
None.gif  
<wsdl:part name="parameters" element="tns:HelloWorld" /> 
None.gif  
wsdl:message>
None.gif
<wsdl:message name="HelloWorldSoapOut">
None.gif  
<wsdl:part name="parameters" element="tns:HelloWorldResponse" /> 
None.gif  
wsdl:message>
None.gif
<wsdl:portType name="ServiceSoap">
None.gif
<wsdl:operation name="HelloWorld">
None.gif  
<wsdl:input message="tns:HelloWorldSoapIn" /> 
None.gif  
<wsdl:output message="tns:HelloWorldSoapOut" /> 
None.gif  
wsdl:operation>
None.gif  
wsdl:portType>
None.gif
<wsdl:binding name="ServiceSoap" type="tns:ServiceSoap">
None.gif  
<soap:binding transport="http://schemas.xmlsoap.org/soap/http" /> 
None.gif
<wsdl:operation name="HelloWorld">
None.gif  
<soap:operation soapAction="http://tempuri.org/HelloWorld" style="document" /> 
None.gif
<wsdl:input>
None.gif  
<soap:body use="literal" /> 
None.gif  
wsdl:input>
None.gif
<wsdl:output>
None.gif  
<soap:body use="literal" /> 
None.gif  
wsdl:output>
None.gif  
wsdl:operation>
None.gif  
wsdl:binding>
None.gif
<wsdl:binding name="ServiceSoap12" type="tns:ServiceSoap">
None.gif  
<soap12:binding transport="http://schemas.xmlsoap.org/soap/http" /> 
None.gif
<wsdl:operation name="HelloWorld">
None.gif  
<soap12:operation soapAction="http://tempuri.org/HelloWorld" style="document" /> 
None.gif
<wsdl:input>
None.gif  
<soap12:body use="literal" /> 
None.gif  
wsdl:input>
None.gif
<wsdl:output>
None.gif  
<soap12:body use="literal" /> 
None.gif  
wsdl:output>
None.gif  
wsdl:operation>
None.gif  
wsdl:binding>
None.gif
<wsdl:service name="Service">
None.gif
<wsdl:port 

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/12639172/viewspace-332350/,如需转载,请注明出处,否则将追究法律责任。

转载于:http://blog.itpub.net/12639172/viewspace-332350/

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值