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

<iframe align="center" marginwidth="0" marginheight="0" src="http://www.zealware.com/csdnblog336280.html" frameborder="0" width="336" scrolling="no" height="280"></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的很多标准,虽然好,但是每个浏览器也不是都完全支持所有的标准。




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的很多标准,虽然好,但是每个浏览器也不是都完全支持所有的标准。




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的很多标准,虽然好,但是每个浏览器也不是都完全支持所有的标准。




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的很多标准,虽然好,但是每个浏览器也不是都完全支持所有的标准。




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的很多标准,虽然好,但是每个浏览器也不是都完全支持所有的标准。




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的很多标准,虽然好,但是每个浏览器也不是都完全支持所有的标准。




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的很多标准,虽然好,但是每个浏览器也不是都完全支持所有的标准。




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的很多标准,虽然好,但是每个浏览器也不是都完全支持所有的标准。




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的很多标准,虽然好,但是每个浏览器也不是都完全支持所有的标准。




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的很多标准,虽然好,但是每个浏览器也不是都完全支持所有的标准。




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的很多标准,虽然好,但是每个浏览器也不是都完全支持所有的标准。




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="SmsSender

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值