`

Web Service难道又是一个美丽的童话?

 
阅读更多
<iframe align="top" marginwidth="0" marginheight="0" src="http://www.zealware.com/csdnblog01.html" frameborder="0" width="728" scrolling="no" height="90"></iframe>

Web Service用了这么多年了,相信没有人会怀疑其跨平台性。无论是MS的WS还是J2EE的WS,自己和自己平台的交互一般都不会有什么配置问题。可是,当我们想要用一种平台去访问另一种平台的WS的时候,一个矛盾出现了,就是对WSML的解释存在差异性。

我做了一个例子,在VB中用MSSoap访问PHP Pear SOAP生成的WS,众所周知WSDL一般都不是人写的。

假设有一个发送短消息的函数

PHP生成Web Service有三种主要的方法:

1 用自带的soap函数

function send($address, $content, $key) {}

$server = new SoapServer(null, array('urn' => "SmsSender"));
$server->addFunction("send");
$server->handle();

这种方法无法生成wsdl

2 用Pear的SOAP

class SmsSender {
function send($address, $content, $key) {
}
}

$server = new SOAP_Server();
$webservice = new SmsSender();
$server->addObjectMap($webservice,'urn:SmsSender');
$server->service($HTTP_RAW_POST_DATA);

该类库可以自动生成WSDL如下:

<?xml version="1.0"?><definitions name="SmsSender" targetnamespace="urn:SmsSender" xmlns:wsdl="&lt;a href=" http:>http://schemas.xmlsoap.org/wsdl/" xmlns:soap="<a href="http://schemas.xmlsoap.org/wsdl/soap/">http://schemas.xmlsoap.org/wsdl/soap/</a>" xmlns:tns="urn:SmsSender" xmlns:xsd="<a href="http://www.w3.org/2001/XMLSchema">http://www.w3.org/2001/XMLSchema</a>" xmlns:SOAP-ENC="<a href="http://schemas.xmlsoap.org/soap/encoding/">http://schemas.xmlsoap.org/soap/encoding/</a>" xmlns="<a href="http://schemas.xmlsoap.org/wsdl/">http://schemas.xmlsoap.org/wsdl/</a>"&gt;<br><types xmlns="&lt;a href=" http:>http://schemas.xmlsoap.org/wsdl/"&gt;<br></types><br><porttype name="SmsSenderPort"></porttype><br><binding name="SmsSenderBinding" type="tns:SmsSenderPort"><br><binding style="rpc" transport="&lt;a href=" http:>http://schemas.xmlsoap.org/soap/http" /&gt;<br></binding></binding><br><service name="SmsSenderService"><br><documentation></documentation><br><port name="SmsSenderPort" binding="tns:SmsSenderBinding"><br><address location="&lt;a href=" http:>http://202.195.160.145/sms/ws.php" /&gt;<br> </address></port><br></service><br></definitions>

3 使用nusoap,不过由于最新版本有bug,所以我懒得用。

下面我们用VB调用上面的第二个WS

Dim client
Set client = CreateObject("MSSOAP.SOAPClient30")
client.ClientProperty("ServerHTTPRequest") = True

On Error Resume Next

Call client.MSSoapInit("http://host/sms/ws.php?wsdl", "SmsSenderService", "SmsSenderPort")
If Err 0 Then
Debug.Print "initialization failed" + Err.Description
End If


strg = client.send("12345678", "test", "key")
If Err 0 Then
Debug.Print Err.Description
Debug.Print "faultcode=" + client.FaultCode
Debug.Print "faultstring=" + client.FaultString
Debug.Print "FaultActor=" + client.FaultActor
Debug.Print "Detail=" + client.Detail
End If

MSSoap居然返回错误:

initialization failedWSDLPort:Port SmsSenderPort has no operations HRESULT=0x1: 函数不正确。
- WSDLService:Processing service SmsSenderService found no port definitions HRESULT=0x80070057: 参数不正确。
- WSDLReader:Analyzing the WSDL file failed HRESULT=0x80070057: 参数不正确。
- Client:One of the parameters supplied is invalid. HRESULT=0x80070057: 参数不正确。

那是不是WSDL的确错误呢?我继续用PHP的Pear的SOAP客户端来调用这个WS

$client = new SOAP_Client("http://host/sms/ws.php");
$client->send("12345677", "test", "key");

我甚至没有指定WSDL,也能顺利的执行。

还有Axis的WS如果给.net调用,经常也会存在一些莫名奇妙的错误。

如果我用一种平台的工具生成WSDL,然后让另一种平台用这个WSDL反向生成代码,这种代码的可读性会大大下降。

问题的症结似乎在于WSDL的过度复杂和设计之初,没有考虑手写代码的便捷性和可行性,HTML就是一个完全可以手写的代码。

难道Web Servcie就和EJB一样,所谓的一次部署只是一个美丽的童话?各家厂商为了自己的利益,无法使得WSDL变得完全中立?

或者是否应该有一个第三方的工具,独立与任何语言的工具来定义WS,然后通过可定制的模板,自动生成各家语言的各种框架所需的配置文件?如果有的话,可能会火!

欢迎大家参与讨论,你的WS最佳实践是什么?

没想到这个问题引发了不少朋友的激烈讨论。首先我声明的是,我选用了REST的Web Service,因为我觉得它比SOAP在解决我遇到的这个问题上更方便,快捷。其次,我觉得这个问题比较搞的点在于,M$在测试MSSOAP的时候,并没有找几个PHP的WS来做测试。同样Pear SOAP在做测试的时候,也没有用MSSOAP来测试。每个厂商似乎都只要保证自己的平台能够顺利的联通就可以了。同样对于Axis,Xfire也存在这样的问题。就像Xhtml,CSS的很多标准,虽然好,但是每个浏览器也不是都完全支持所有的标准。



Trackback: http://tb.blog.csdn.net/TrackBack.aspx?PostId=1799303


分享到:
评论

相关推荐

    C#Web Service C#Web Service C#Web Service

    C#Web Service C#Web Service C#Web Service

    service now web service

    service now web service guide

    XML Web Service 开发XML Web Service 开发

    XML Web Service 开发XML Web Service 开发XML Web Service 开发XML Web Service 开发XML Web Service 开发最好不要下

    web service 教程

    就是一个应用程序它向外界暴露出一个能够通过Web进行调用的API。这就是说你能 够用编程的方法通过Web来调用这个应用程序。 对Web service 更精确的解释 Web services是建立可互操作的分布式应用程序的新...

    Web Service Web Service

    Web ServiceWeb ServiceWeb Service

    D6 SOAP_WEB SERVICE程序设计.part1.rar

    第一章 SOAP和Web Service的概念 第二章 组件模型、Internet/Intranet和SOAP 第三章 开发Web Service 第四章 什么是SOAP 第五章 SOAP和数据封装 第六章 SOAP和远程调用 第七章 Web Service和UDDI 第八章 处理复杂...

    Spring Web Service实例

    Spring Web Service是Spring社区基于Spring提供的一个关注于创建”文档驱动”的Web Service的模块, 它的主要目标是方便基于”契约优先”(Contract-First)的SOAP服务的开发. 好像没有多少人讨论, 大多数的话题都是...

    论文研究-Web Service和Grid Service研究 .pdf

    Web Service和Grid Service研究,郭璇,,本文分析并比较了两种主流的Web服务技术,Web Service技术和Grid Service技术。首先介绍Web Service 的系统架构和核心技术,并深入探讨Web Servic

    D6 SOAP_WEB SERVICE

    D6 SOAP_WEB SERVICE 使用delphi来开发 webservice 使用soap

    web service 天气预报 web service 天气预报

    web service 天气预报web service 天气预报web service 天气预报web service 天气预报web service 天气预报web service 天气预报

    web service课件

    西北某高等院校研究生的web service课件,英文版的,总共7个ppt,比较简练,适合想快速了解学习web service的学生下载学习,分别是Web Services(ch3.1)、Web Services(ch3.2)、Web Services(ch3.3)、Web Services(ch...

    Web Service

    3.XFire 是 codeHaus 組織提供的一個開源框架,它構建了 POJO 和 SOA 之間的橋樑,主要特性就是支持將 POJO 通過非常簡單的方式發佈成 Web 服務,這種處理方式不僅充分發揮了 POJO 的作用,簡化了 Java 應用轉化為 ...

    Web Service Discovery–A Reality Check

    web service discovery

    Query as a Web Service 指南

    Query as a Web Service 指南

    Web Service Architecture

    Web Service

    编写一个简单的Web Service

    编写一个简单的Web Service下面是写的步骤: 一、打开VS。NET的集成开发环境,FILE菜单上选择New,新建一个C#的ASP.NET Web Service工程,工程名为WebServiceDemo(完整的是http://localhost/WebServiceDemo)。这...

    web Service 实例教程

    Web Service 简单实例,JAVA中的Web服务规范等,完整的客户端于服务端的开发流程。

    globus web service 编程实例(详见描述)

    里面有三个文件,一个是描述文字,按照描述即可一步一步的运行例子。 一个是globus的程序,功能不全,只供运行例子用。 另一个是例子的源代码,有注释。 这是个很好的学习globus web service编程的例子。

    Web Service详解

    Web Service架构 Web Service vs. CORBA/DCOM/EJB Web Service是使用Web的新模式 通过程序自动启动和处理商务事务,而并非...能够在一个分布式的计算环境中动态地描述、发布、发现和调用 支持基于Web Service的新型应用

    yahoo web service-2.11.zip

    yahoo web service-2.11.zip;

Global site tag (gtag.js) - Google Analytics