解决php soap webservice 用c++ soap调用的问题
2008-03-30 00:07
561 查看
php是弱数据类型语言,而c++对语言又非常注重数据类型,因此,最近在研究php的soap webservice时遇到很大的问题,目前已经解决。
研究的目标是利用php 搭建webservice, 输入和输出参数都是array类型,元素为string类型。client为c++。
问题伊始,查阅了大量资料,这种模式貌似没有人使用。只有自己跟踪摸索,并且还有个php的bug(SOAP server return Procedure ' ' not present),还好,php team 在最新的5.2.5中已经修复了。
环境:winxp Apache/2.2.8 (Win32) PHP/5.2.5
程序如下:
PHP SOAP SERVER
<?php
class server {
/**
* run for webservice
*
* @param string[] $inputParam//
* @return string[]
*/
public function run($inputParam){
$Param=$inputParam->param->string;//关键点,获取stdClass对象内容
$obj=new stdClass;//关键点,设置stdClass对象内容作为返回参数
$obj->runResult->string=array($Param[0],'b','c','d','e');
return $obj;
}
}
$server = new SoapServer('ws.wsdl', array('soap_version' => SOAP_1_2,'encoding'=>'UTF-8'));
$server->setClass("server");
if (isset($HTTP_RAW_POST_DATA)) {
$request = $HTTP_RAW_POST_DATA;
} else {
$request = file_get_contents('php://input');
}
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$server->handle($request);
} else {
echo "This Webservice can handle following functions: <br>";
$functions = $server->getFunctions();
foreach($functions as $k=>$func) {
echo ($k+1).". ".$func . " <br>";
}
}
?>
WSDL
<?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="urn:some.com" 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="urn:some.com" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/">
<wsdl:types>
<s:schema elementFormDefault="qualified" targetNamespace="urn:some.com">
<s:complexType name="ArrayOfString">
<s:sequence>
<s:element minOccurs="0" maxOccurs="unbounded" name="string" nillable="true" type="s:string" />
</s:sequence>
</s:complexType>
<s:element name="run">
<s:complexType>
<s:sequence>
<s:element minOccurs="0" maxOccurs="1" name="param" type="tns:ArrayOfString" />
</s:sequence>
</s:complexType>
</s:element>
<s:element name="runResponse">
<s:complexType>
<s:sequence>
<s:element minOccurs="0" maxOccurs="1" name="runResult" type="tns:ArrayOfString" />
</s:sequence>
</s:complexType>
</s:element>
</s:schema>
</wsdl:types>
<wsdl:message name="runSoapIn">
<wsdl:part name="parameters" element="tns:run" />
</wsdl:message>
<wsdl:message name="runSoapOut">
<wsdl:part name="parameters" element="tns:runResponse"/>
</wsdl:message>
<wsdl:portType name="Service1Soap">
<wsdl:operation name="run">
<wsdl:input message="tns:runSoapIn" />
<wsdl:output message="tns:runSoapOut" />
</wsdl:operation>
</wsdl:portType>
<wsdl:binding name="Service1Soap" type="tns:Service1Soap">
<soap:binding transport="http://schemas.xmlsoap.org/soap/http" />
<wsdl:operation name="run">
<soap:operation soapAction="urn:some.com/run" 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="Service1Soap12" type="tns:Service1Soap">
<soap12:binding transport="http://schemas.xmlsoap.org/soap/http" />
<wsdl:operation name="run">
<soap12:operation soapAction="urn:some.com/run" 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="Service1">
<wsdl:port name="Service1Soap" binding="tns:Service1Soap">
<soap:address location="http://localhost/ws/server.php" />
</wsdl:port>
</wsdl:service>
</wsdl:definitions>
希望能给遇到此类问题的人有所帮助。
研究的目标是利用php 搭建webservice, 输入和输出参数都是array类型,元素为string类型。client为c++。
问题伊始,查阅了大量资料,这种模式貌似没有人使用。只有自己跟踪摸索,并且还有个php的bug(SOAP server return Procedure ' ' not present),还好,php team 在最新的5.2.5中已经修复了。
环境:winxp Apache/2.2.8 (Win32) PHP/5.2.5
程序如下:
PHP SOAP SERVER
<?php
class server {
/**
* run for webservice
*
* @param string[] $inputParam//
* @return string[]
*/
public function run($inputParam){
$Param=$inputParam->param->string;//关键点,获取stdClass对象内容
$obj=new stdClass;//关键点,设置stdClass对象内容作为返回参数
$obj->runResult->string=array($Param[0],'b','c','d','e');
return $obj;
}
}
$server = new SoapServer('ws.wsdl', array('soap_version' => SOAP_1_2,'encoding'=>'UTF-8'));
$server->setClass("server");
if (isset($HTTP_RAW_POST_DATA)) {
$request = $HTTP_RAW_POST_DATA;
} else {
$request = file_get_contents('php://input');
}
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$server->handle($request);
} else {
echo "This Webservice can handle following functions: <br>";
$functions = $server->getFunctions();
foreach($functions as $k=>$func) {
echo ($k+1).". ".$func . " <br>";
}
}
?>
WSDL
<?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="urn:some.com" 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="urn:some.com" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/">
<wsdl:types>
<s:schema elementFormDefault="qualified" targetNamespace="urn:some.com">
<s:complexType name="ArrayOfString">
<s:sequence>
<s:element minOccurs="0" maxOccurs="unbounded" name="string" nillable="true" type="s:string" />
</s:sequence>
</s:complexType>
<s:element name="run">
<s:complexType>
<s:sequence>
<s:element minOccurs="0" maxOccurs="1" name="param" type="tns:ArrayOfString" />
</s:sequence>
</s:complexType>
</s:element>
<s:element name="runResponse">
<s:complexType>
<s:sequence>
<s:element minOccurs="0" maxOccurs="1" name="runResult" type="tns:ArrayOfString" />
</s:sequence>
</s:complexType>
</s:element>
</s:schema>
</wsdl:types>
<wsdl:message name="runSoapIn">
<wsdl:part name="parameters" element="tns:run" />
</wsdl:message>
<wsdl:message name="runSoapOut">
<wsdl:part name="parameters" element="tns:runResponse"/>
</wsdl:message>
<wsdl:portType name="Service1Soap">
<wsdl:operation name="run">
<wsdl:input message="tns:runSoapIn" />
<wsdl:output message="tns:runSoapOut" />
</wsdl:operation>
</wsdl:portType>
<wsdl:binding name="Service1Soap" type="tns:Service1Soap">
<soap:binding transport="http://schemas.xmlsoap.org/soap/http" />
<wsdl:operation name="run">
<soap:operation soapAction="urn:some.com/run" 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="Service1Soap12" type="tns:Service1Soap">
<soap12:binding transport="http://schemas.xmlsoap.org/soap/http" />
<wsdl:operation name="run">
<soap12:operation soapAction="urn:some.com/run" 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="Service1">
<wsdl:port name="Service1Soap" binding="tns:Service1Soap">
<soap:address location="http://localhost/ws/server.php" />
</wsdl:port>
</wsdl:service>
</wsdl:definitions>
希望能给遇到此类问题的人有所帮助。
相关文章推荐
- 解决php soap webservice 用c++ soap调用的问题[转]
- 终于解决了PHP调用SOAP过程中的种种问题
- php调用java写的WebService不能传参问题解决
- c/c++中利用gsoap调用webservice服务的一个诡异问题解决方法
- PHP使用SOAP调用.net的WebService问题
- 关于 php 用webservice传输数据的问题(nosoap与.NET对接)此处一直困扰三天时间,终于解决
- 终于解决了PHP调用SOAP过程中的种种问题。(转)
- PHP使用SOAP调用.net的WebService问题
- PHP中GBK页面调用WebService的编码问题:XML error parsing SOAP payload on line 1
- 非托管C++调用 Webservice,如何解决状态保持的问题
- PHP使用SOAP调用.net的WebService问题
- PHP使用SOAP调用.net的WebService问题
- C++ 调用Python3 脚本中无法引入内建模块的问题 解决方法
- c++调用python链接问题及解决
- 关于 php 调用 其他语言写的Web Service SOAP 接口的参数传递问题
- cxf调用.net webservice 接口遇到的问题(尚未解决)
- (转)Delphi 调用C#编写的WebService 参数为Null解决方法 附中文乱码问题
- 如何有效解决C与C++的相互调用问题
- asp.net 调用(引用 Native dll 的)C++/CLI dll 的问题及解决
- 调用webservice超时问题的解决