.net webservice教程 怎么封装

续:如何解决《ASP.NET Webservice部署失败》
续:如何解决《ASP.NET Webservice部署失败》
[摘要:今天,我们终究将那个题目给办理。题目的本源是因为Windows Server 2008(R2)的Service Pack1引发的。详细的疑息,请参考以下两篇文章。 /kb/2520479 http://www.shanmcarthur.net/]
昨天,我们终于将这个问题给解决。问题的根源是由于Windows Server 2008(R2)的Service Pack1引起的。具体的信息,请参考以下两篇文章。
/kb/2520479
http://www.shanmcarthur.net/Default.aspx?DN=7d0cd525-bbc5-46c3-27aeea
在这里,我主要是讲述一下我们当时是如何去考虑这个问题的。
首先,客户投诉我们的安装程序有问题。根据他们提供的信息:1)服务器是新买的;2)NET Framework 和 IIS是新安装的且已经检测过没有问题;3)使用我们提供的安装程序进行安装,没有任何的定制化;4)在其他地方使用相同安装程序安装的站点没有此问题。
当时,我们的第一反应式:我们的安装程序是经过测试的,而且使用此安装程序的其他用户并不存在此问题,所以很可能是配置问题。那么,哪个地方出现了配置问题呢?如何去寻找线索和证据来证明那个配置问题?
第一个来回:按照正常流程检查用户的配置
1、站点所关联的NET Framework版本,结论是:NET Framework版本关联正确,并且他们又将NET Framework注册到IIS,并且重启了IIS
2、检查IIS中的Http Request Handler: WebServiceHandlerFactory-ISAPI及其配置,结论是:Http Request Hanlder的配置也是正确的
3、检查从客户端是否能访问WebService文件,结论是:依然不能通过在Webservice.aspx后面加/jsdebug访问到Net Framework 生成的JS文件
第二个来回:在IIS里面进行检测能否访问WebService件以及可能的错误信息。
1、直接用IIS Manager 里面访问WebService文件
注意:以下三幅图只是一个试验,我已经将WebServiceHandlerFactory-ISAPI-4.0_32bit 和 WebServiceHandlerFactory-ISAPI-4.0_64bit 删除,以此模拟处理WebService的Handler已经被破坏。
650) this.width=650;" style="border-bottom: 0 border-left: 0 border-top: 0 border-right: 0px" title="image" border="0" alt="image" height="342" src="/uploads/u/a2/d0/a2d0acd88dd0d6de65483.png" />
650) this.width=650;" style="border-bottom: 0 border-left: 0 border-top: 0 border-right: 0px" title="image" border="0" alt="image" height="408" src="/uploads/u/25/09/2ccd3beea0c9.png" />
650) this.width=650;" style="border-bottom: 0 border-left: 0 border-top: 0 border-right: 0px" title="image" border="0" alt="image" height="357" src="/uploads/u/2c/21/2cd546e040f9.png" />
结论是:在客户的服务器里面,错误信息是不一样的,依然是无法找到那个文件。
第三个来回:为什么IIS没有生成JS文件
当时我给大家的分析是这样的:到底是IIS没有接收对.asmx文件的请求呢?还是Http Request Handler没有正常处理呢?如果是前者,那么在IIS Log里面一定没有对.asmx文件的日志记录;如果是后者,在System Event里面一定有相应的Log,肯定是我们忽略了什么东西。当然,我们也怀疑过可能是权限导致的。
1、检查IIS中的所有关于权限的设置,结论是正常的。
2、检查IIS Log,结论是IIS正常接收对.asmx文件的请求,并且记录在日志文件中
3、检查System Event Log,无意中发现相关的信息,如下图。因为之前见过这个错误信息&Server cannot append header after HTTP headers have been sent.&很多次,也知道原因,所以一直没有太在意。实在找不到原因,我们就做出了一个假设:假设这个问题是由于那个Http Module引起的,那么我们不使用那么HttpModule之后,问题是否还会存在呢?结论是:问题消失。
650) this.width=650;" style="border-bottom: 0 border-left: 0 border-top: 0 border-right: 0px" title="image" border="0" alt="image" height="427" src="/uploads/u/9f/ed/9fed29168dcc8c761ef1d.png" />
第四个来回:问题的根源真的是由于我们使用的那个特别的Http Module类吗?那么为什么我们本地相同的环境不能重现?
1、检查服务器的操作系统版本,结论是:本地是Windows Web Server 2008 plus sp1,不存在类似问题;IST服务器是Windows Server 2008 R2 plus SP1,不存在类似问题;存在问题的服务器是Windows Server 2008 R2 plus sp1.
2、本地安装相同的服务器操作系统和补丁,重新测试。结论是:问题还是不存在。换句话说,并不是我们所采用的Http Module引起的。那是什么原因呢?大家请看我之前写的一篇文章《已解问题:ASP.NET Webservice部署失败》中的最后一张图片,因为我们在每一次安装后,都会习惯性的将ExtensionlessUrlHandler-ISAPI-4.0_32bit 和 ExtensionlessUrlHandler-ISAPI-4.0_64bit 删除。如果我们没有删掉,这个问题就可以重现了。接下来,经过验证和测试,证明的确和那里有关系,于是我们开始思考我们为什么每次都会习惯性的将这两个ExtensionlessUrlHandler-ISAPI-4.0_32bit 和 ExtensionlessUrlHandler-ISAPI-4.0_64bit& 删掉的原因,主要是为了解决缺省主页的问题。也就说,不确定和我们目前所遇到的问题是否存在关系,于是寻找资料,发现以下两篇文章。
/kb/2520479
http://www.shanmcarthur.net/Default.aspx?DN=7d0cd525-bbc5-46c3-27aeea
1、为什么我们需要经历这么多的来回交流?
2、为什么我们没有在本地重现?本文出自 “CTO-360” 博客,请务必保留此出处http://penzhaohui./418
感谢关注 Ithao123NET频道,是专门为互联网人打造的学习交流平台,全面满足互联网人工作与学习需求,更多互联网资讯尽在 IThao123!
Laravel是一套简洁、优雅的PHP Web开发框架(PHP Web Framework)。它可以让你从面条一样杂乱的代码中解脱出来;它可以帮你构建一个完美的网络APP,而且每行代码都可以简洁、富于表达力。
产品设计是互联网产品经理的核心能力,一个好的产品经理一定在产品设计方面有扎实的功底,本专题将从互联网产品设计的几个方面谈谈产品设计
随着国内互联网的发展,产品经理岗位需求大幅增加,在国内,从事产品工作的大部分岗位为产品经理,其实现实中,很多从事产品工作的岗位是不能称为产品经理,主要原因是对产品经理的职责不明确,那产品经理的职责有哪些,本专题将详细介绍产品经理的主要职责
PHP(外文名:PHP: Hypertext Preprocessor,中文名:“超文本预处理器”)是一种通用开源脚本语言。语法吸收了C语言、Java和Perl的特点,利于学习,使用广泛,主要适用于Web开发领域。PHP 独特的语法混合了C、Java、Perl以及PHP自创的语法。它可以比CGI或者Perl更快速地执行动态网页。用PHP做出的动态页面与其他的编程语言相比,PHP是将程序嵌入到HTML(标准通用标记语言下的一个应用)文档中去执行,执行效率比完全生成HTML标记的CGI要高许多;PHP还可以执行编译后代码,编译可以达到加密和优化代码运行,使代码运行更快。
IThao123周刊您所在的位置: &
总结WebService的一些封装技巧
总结WebService的一些封装技巧
讨论一下WebService的一些封装技巧,也就是会碰到的常见问题的解决,希望能给大家以后在用WebService时一点帮助和启发吧。
今天早上起来,想谈谈.NET中的WebService,当然我不想讲什么是WebService,或者怎么用WebService,因为那个大家随便Google一下前100页都能找到答案。今天我想来分享一下我在用WebService中的一些技巧(至少我认为是技巧,还有点成就感),希望能给大家以后在用WebService时一点帮助和启发吧。
一、问题诞生 -- 大部分解决方案的背后总是一些头痛的问题
很早以前就用过传说中的WebService,但一直是用常规的思路在用:创建WebService项目--&写Web服务方法--& 在项目中添加Web引用--&调用Web方法。这样貌似很好,非常符合规范,在一段时间内效果也还可以,但渐渐的随着项目的扩大和同时参与项目的人员增多,就越来越觉得这种常规的方法很是不爽,为什么呢?我每次修改WebService端(添加、删除Web方法,以及修改方法名称),在引用端我都要更新WebService引用,其实是就是更新WSDL文件,很是烦人。
二、化分为合 -- 传说分久必合,合久必分
好吧,既然增加、删除、修改web方法名都会引起WSDL的更新,那么我们索性用一个统一的方法来作为webservice的访问入口吧,然后内部用switch case来区分调用哪个方法,先贴代码吧,再来简单讲讲:
统一访问接口IRemoteCall:
public&interface&IRemoteCall{&&&& &byte[]&GeneralCall(string&methodName,&params&byte[]&param);}&
然后定义一个WebService并实现以上接口(以前还没真在webservice上实现过接口,哈哈):
[WebService(Namespace&=&)][WebServiceBinding(ConformsTo&=& &WsiProfiles.BasicProfile1_1)][ToolboxItem(false)]public&class&BlogService&:&System.Web.Services.WebService,&IRemoteCall{&&&& &[WebMethod(EnableSession&=&true)]&&& &&public&byte[]&GeneralCall(string&methodName,&params&byte[]&param)&&&&{&&&&&&&& &switch&(methodName)&&&&&&& &&{&&&&&&&&&& &&&case&&LoadBlog&:&&&&&&&&&& &&&&&&{&&&&&&&&&&&&&&& &&&&&long&blogId&=&Serializer.DeserializeToObject&long&(param);&&&&&&&&&&&&&&&&& &&&BLLBlogArtical&ba&=&new&AppBlog().LoadBlog(blogId);&&&&&&&&&&&&&&& &&&&&return&Serializer.SerializeToBinary(ba);&&&&&&&&&& &&&&&&}&&&&&&&&& &&&&case&&DeleteBlog&:&&&&&&&& &&&&&&&&{&&&&&&&&&&&&&& &&&&&&&&&&&&&&&&&&&&return&null;&&&&&&&& &&&&&&&&}&& &&&&&&&&}&&&&&}}&
这里为什么要定义接口IRemoteCall呢,主要是为接下来统一调用webservice服务的,所有实现这个接口的webservice类都可以通过GeneralCall来完成调用,待会将webservice访问器的时候会具体讲到,这里主要讲讲这个switch case。
这里我们定义了一个统一的访问入口
byte[]&GeneralCall(string&methodName,params&byte[]&param)&
意思是:传入要调用的方法名称以及序列化后的参数,返回序列化后的结果。这里为了统一数据,我们均对参数和返回值都序列化成byte数组,即用Serializer.SerializeToBinary(object)来实现,这样所有调用就都统一了格式。
有人可能会提出质疑,这样方法名称都已字符串形式是不是会显得难看,而且字符串容易出错,还没有智能提示?那也好解决,我们可以把方法名称定义成const常量就可以了。这里我对webservice的一个态度是:webservice层就是完成转接和调度工作的,它仅仅起到承接的作用,用了他可以将服务任意分布,所以里面是没有任何逻辑的(逻辑都是被封装在其他dll中的),最多是一些数据转换,所以我采用了这种模糊接口的方式。
三、自定义webservice访问器
上面我们完成了webservice端的工作,接下来就来实现客户端对webservice的灵活调用,这里上面定义的那个IRemoteCall就起到作用了,首先我们定义一个webservice访问器类RemoteCaller,代码如下:
using&Susing& &System.Collections.Gusing& &System.Tusing& &System.Cusing&System.Web.Services.P &using&SharedLib_403;& &namespace&ITIvy.Shared.RemoteCaller{&&&& &&&&&&&&&&&&public&class&RemoteCaller&& &&&{&&&& &&&&&private&string&_MethodN&&& &&&&&&private&byte[]&_ParamB&&&& &&&&&private&IRemoteCall&_C&&&&& &&&&private&ArrayList&_P&&&&& &&&&&&&&&&&&&&&&public&ArrayList&Params&&&& &&&&&{&&&&&&&&& &&&&get&{&return&_P&}&&&&&&&&&& &&&set&{&_Params&=&&}&&&& &&&&&} &&&&&&&&&&&&&&&&&&&&&public&byte[]&ParamByte&&&&& &&&&{&&&&&& &&&&&&&get&{&return&_ParamB&}&&&& &&&&&&&&&set&{&_ParamByte&=&&}&&&&& &&&&}&&&&&&&&&&&&&&&&&&&&public&string&MethodName&& &&&&&&&{&&&&&& &&&&&&&get&{&return&_MethodN&}&&&&&& &&&&&&&set&{&_MethodName&=&&}&&&&& &&&&}&&&&&&&&&&&&&&&&&&&&&&public&IRemoteCall&Caller&& &&&&&&&{&&&&&&&& &&&&&get&{&return&_C&}&&&& &&&&&&&&&set&{&_Caller&=&&}&& &&&&&&&}&&&&&&&& &&&&&&&&&&&&&&&&&&public&RemoteCaller(IRemoteCall&caller)&&&&&&&&{&&&&&&&&&&& &&_Caller&=&&&&&&&&&&& &&&_Params&=&new&ArrayList();&&&& &&&&&}&&&&& &&&&&&&&&&&&&&&&&&&&&&&&&&&&&public&byte[]&Call(string&methodName,&object&param)&&&&&&&&{&&&&&&&&& &&&&try&&&&&&&&&&&&{&&&&&&& &&&&&&&&&&_MethodName&=&methodN&&&&&&&&&&&&&&&&_ParamByte&=&Serializer.SerializeToBinary(param);&&&&&&& &&&&&&&&&&return&_Caller.GeneralCall(_MethodName,&_ParamByte);&&&&&&&& &&&&&}&&& &&&&&&&&&&catch&(Exception&ex)&&&&&&&&&&&&{&&&&&&&&&&&&&& &&&if&(ex&is&SoapException)&&&&&&&&&&&&&& &throw&new&Exception(((SoapException)ex).Detail[&Message&].InnerText);&&&&&&&&&&&&&&&&else&&&&&&&&&&&&&&&&& &&&&throw&&&&&&&&& &&&&&}&&&&&&&&}&&&&&& &&&&&&&&&&&&&&&&&&&&&&&&&public&byte[]&Call(string&methodName,&ArrayList&param)&&&&& &&&&{&&&&&&&&&& &&&try&&&&&&&&&& &&&{&&&&&& &&&&&&&&&&&_MethodName&=&methodN&&&&&&&&&&&&&&&&_Params&=&&&&&& &&&&&&&&&&&&_ParamByte&=&Serializer.SerializeToBinary(_Params);&&&&&&&&& &&&&&&&&return&_Caller.GeneralCall(_MethodName,&_ParamByte);&&&&&&& &&&&&&}&&&&&&&& &&&&&catch&(Exception&ex)&&&&&& &&&&&&&{&&&&&&&&&&&&&& &&&if&(ex&is&SoapException)&&&&&&&&&&&&&&& &&throw&new&Exception(((SoapException)ex).Detail[&Message&].InnerText);&&&&&&&&& &&&&&&&&else&&&&&&&&&&&&& &&&&&&&&throw&&&&&&&&&&&&&}& &&&&&&&&}&&&&&&& &&&&&&&&&&&&&&&&&&&&&&&&&&&&public&byte[]&Call(string&methodName,&params&object[]&param)& &&&&&&&&{&&&&&&& &&&&&&try&&&&&&&& &&&&&{&&&&&& &&&&&&&&&&&foreach&(object&obj&in&param)&&&&&&& &&&&&&&&&&&&&&_Params.Add(obj);&&&&&&&&&&&&&&&&_MethodName&=&methodN&&&&& &&&&&&&&&&&&_ParamByte&=&Serializer.SerializeToBinary(_Params);&&&&&&&&&&&&& &&&&return&_Caller.GeneralCall(_MethodName,&_ParamByte);&&&&&&&&& &&&&}&&&&& &&&&&&&&catch&(Exception&ex)&&&&&&&&& &&&&{&&&&&&&&&&&&&& &&&if&(ex&is&SoapException)&&&&&&&&&&&&&&& &&&&&&throw&new&Exception(((SoapException)ex).Detail[&Message&].InnerText);&&&&&&&&&&&&&&&&else&&&&&&&&&&&&&&&&& &&&&throw&&&&&&&&&&&&&}&& &&&&&&&}&&&&&&&&& &&&&&&&&&&&&&&&&&&&&&&&&public&byte[]&Call()&&&&& &&&&{&&&&&&&&&&&&try&&&&&&&& &&&&&{&&&&&&&&&&& &&&&&&if&(string.IsNullOrEmpty(_MethodName))&&&&&&&&&&&&&&& &&&&&&throw&new&Exception(&远程方法不能为空!&);&&&&&&&&&&&&&& &&&return&_Caller.GeneralCall(_MethodName,&_ParamByte);&&&&&&&&&&&&}&& &&&&&&&&&&&catch&(Exception&ex)&&&& &&&&&&&&&{&&&&&&&&&&&&&& &&&if&(ex&is&SoapException)&&&&&&&& &&&&&&&&&&&&&throw&new&Exception(((SoapException)ex).Detail[&Message&].InnerText);&&&&&&&&&&&&&&&&else&&&&&&&&&&&&&&& &&&&&&throw&&&&&&&& &&&&&&}&&&&&&&&}&&&&&&& &&&&&&&&&&&&&&&&&&&{&&&&&&&&&&&&byte[]&resultByte&=&Call();&&&&&&&&&&&&return&Serializer.DeserializeToObject&T&(resultByte);&&&&&&&&}&&& &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&public&T&Call&T&(string&methodName,&ArrayList&param)& &&&&&&&&{&&&&&&&&&& &&&byte[]&resultByte&=&Call(methodName,&param);&&&&&&&&&& &&&return&Serializer.DeserializeToObject&T&(resultByte);&&&&&& &&&}&&& &&&&&&&public&T&Call&T&(string&methodName,&object&param)&&&&&&&&{&&&&&&&& &&&&&try&&&&&&&&&&&&{&&&&&&&&&& &&&&&&&_MethodName&=&methodN&&&&&&&&&&&& &&&&&_ParamByte&=&Serializer.SerializeToBinary(param);&&&&&&&&&&&&&& &&&byte[]&resultByte&=&_Caller.GeneralCall(_MethodName,&_ParamByte);&&&&&&&& && &&&&&&&&return&Serializer.DeserializeToObject&T&(resultByte);&&&&&&&& &&&&&}&&&&&&&&&&&&catch&(Exception&ex)&&&&&&&&& &&&&{&&&&&& &&&&&&&&&&&if&(ex&is&SoapException)&&&&&&&&&&&&&&&&&&&&throw&new&Exception(((SoapException)ex).Detail[&Message&].InnerText);&&&&&&&&&&&&&&&&else&&&&&&&&&&&&&&&& &&&&&throw&&&&&&&&& &&&&&}&&&&&&&&}&&&&&&& &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&public&T&Call&T&(string&methodName,&params&object[]&param)&&&&&& &&&{&&&&&&&& &&&&&byte[]&resultByte&=&Call(methodName,&param);&&&&&&&&& &&&&return&Serializer.DeserializeToObject&T&(resultByte);&&&&& &&&&}&&&&}} &&
这个访问器主要是定义了一系列访问接口的重载,利用了c#的泛型更加使接口简单了。哈哈,这个类就能让我们实现一句话调用webservice,相当简洁。注意里面的IRemoteCall属性,就是只要传入实现了该接口的类,就都可以通过该访问器来访问webservice。如何使用该类呢,下面给一个例子吧:
IRemoteCall Caller = new BlogService.BlogService();BLLBlogArtical bllArtical = new RemoteCaller(Caller).Call&BLLBlogArtical&(&LoadBlog&, id);
抱歉,说错了,要两句话来调用,但是这里少去了很多数据转换的工作,因为有了泛型,呵呵,而且我可以在RemoteCaller这个访问器类中做很多工作,比如异常处理,权限验证等等。
四、总结 -- 写了这么多不总结可不行
这个实现方法的核心在于用IRemoteCall接口来规范webservice类的实现方式均为统一GenerateCall,然后 webservice类中通过switch case来将所有方法整合在一起,避免频繁更新WSDL的麻烦,最后客户端利用IRemoteCall定义一个webservice访问器类 RemoteCaller来提供统一的webservice访问。
原文链接:/sxwgf/archive//something-about-webservice.html
【编辑推荐】
【责任编辑: TEL:(010)】
关于的更多文章
IE浏览器不支持很多CSS属性是出了名的,即便在支持的部分中,也
作为移动开发者,WOT2016移动互联网技术峰会,绝对有你不得不来的理由。
互联网一大真理便是,有痛点的地方就有机会。现在最想
Eclipse 是一个开源的、可扩展的集成开发环境。平台本
这个架构是从我近期在做的一个项目中剥离出来的,这个
本书从计算机网络安全的概念入手,分析了单机节点、单一网络、互联网络和开放互联网络的基本安全问题,并对计算机网络安全体系架
51CTO旗下网站博客访问: 4547932
博文数量: 3420
注册时间:
IT168企业级官微
微信号:IT168qiye
系统架构师大会
微信号:SACC2013
分类: Linux
&delphi调用WebService一直发生500错误,可是同样的Service用.net调用,xmlspy调用都没有问题。因此估计Delphi对Service的封装有问题。&&&&跟踪发现:竟然没有参数传递给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="/wsdl/types/">&&&&&&&&&&&&&&&&&&<NS1:GetServiceInfo&xmlns:NS1="http://goldentek.biz/">&&&&&&&&&&&&&&&&&&&&<passport&xsi:type="xsd:string">xxx@</passport>&&&&&&&&&&&&&&&&&&&&<oem&xsi:type="NS2:guid">{xxxxxxxx-bb9-65d484f8bc3b}</oem>&&&&&&&&&&&&&&&&&&&&<codePage&xsi:type="xsd:int"><SPAN style="COLOR: #6</codePage>&&&&&&&&&&&&&&&&&&</NS1:GetServiceInfo>&&&&&&&&&&&&&&&&</SOAP-ENV:Body>&&&&&&&&&&&&&&</SOAP-ENV:Envelope>发现以下部分不正确:
&&&&&&&&&&&&&&&&&&<NS1:GetServiceInfo&xmlns:NS1="http://goldentek.biz/">&&&&&&&&&&&&&&&&&&&&<passport&xsi:type="xsd:string">monkeyking@</passport>&&&&&&&&&&&&&&&&&&&&<oem&xsi:type="NS2:guid">{341a4fbb-bb9-65d484f8bc3b}</oem>&&&&&&&&&&&&&&&&&&&&<codePage&xsi:type="xsd:int"><SPAN style="COLOR: #6</codePage>&&&&&&&&&&&&&&&&&&</NS1:GetServiceInfo>&&& 问题已经确定是Delphi的封装问题。进一步测试发现,在2005下的Service,如果有参数delphi都不能正确封装。难道只有把服务转到2003?或者自己封装Webservie调用?这两个方法都要很多工作量。&&&&下面先看一下生成的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@</passport>&&&&&&&&&&&&&&&&&&&&<oem>{xxxxxxxx-bb9-65d484f8bc3b}</oem>&&&&&&&&&&&&&&&&&&&&<codePage><SPAN style="COLOR: #6</codePage>&&&&&&&&&&&&&&&&&&</GetServiceInfo>&&&&&&&&&&&&&&&&</SOAP-ENV:Body>&&&&&&&&&&&&&&</SOAP-ENV:Envelope>2、
<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@</m:passport>&&&&&&&&&&&&<m:oem><SPAN style="COLOR: #1a4fbb-bb9-65d484f8bc3b</m:oem>&&&&&&&&&&&&<m:codePage><SPAN style="COLOR: #6</m:codePage>&&&&&&&&</m:GetServiceInfo>&&&&</SOAP-ENV:Body></SOAP-ENV:Envelope>
wsdl规范:
下面是1.1和2.0的wsdl,webmethod是:
&[WebMethod]&&&&public&string&HelloWorld(string&s)&{&&&&&&&&string&t&=&s;&&&&&&&&return&"Hello&World";&&&&}
.net1.1生成的wsdl:
&&<?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="/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:
&&<?xml&version="1.0"&encoding="utf-8"&?>&-&<wsdl:definitions&xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"&xmlns:tm="/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&<SPAN style="COLOR: #ff
阅读(610) | 评论(0) | 转发(0) |
相关热门文章
给主人留下些什么吧!~~
请登录后评论。

我要回帖

更多关于 .net webservice教程 的文章

 

随机推荐