在做一个php + soap 的例子时出现了问题 。。

prof_zhaoyebin 2007-03-10 12:32:28
无法显示 XML 页。
使用 样式表无法查看 XML 输入。请更正错误然后单击 刷新按钮,或以后重试。


--------------------------------------------------------------------------------

文档的顶层无效。处理资源 'http://localhost/client.php?name=DzSoft PHP Editor&email=support@dzsoft.com' 时出错。第 1 行,位置: 1

PHP Fatal error: Uncaught SoapFault exception: [HTTP] Unable to parse URL in E:\program\php\soap\client.php:4
^

下面是我的程序
client.php
<?php
$client = new SoapClient("test.wsdl");
try {
$result = $client->div(10,rand(0,5); // will cause a Soap Fault if divide by zero
print “The answer is: $result”;
} catch (SoapFault $exception) {
echo $exception;
}
?>
sever.php
<?php
/**
* A simple math utility class
* @author Zhao
*/
class math
{ /**
* Add two integers together
*
* @param integer $a The first integer of the addition
* @param integer $b The second integer of the addition
* @return integer The sum of the provided integers
*/
public function add($a,$b)
{
return $a+$b;
}
/**
* Subtract two integers from each other
*
* @param integer $a The first integer of the subtraction
* @param integer $b The second integer of the subtraction
* @return integer The difference of the provided integers
*/
public function sub($a,$b)
{
return $a-$b;
}
/**
* Divide two integers
*
* @param integer $a The first integer of the subtraction
* @param integer $b The second integer of the subtraction
* @return integer The difference of the provided integers
*/
public function div($a,$b)
{
if($b==0)
{
throw new SoapFault(-1,"Cannot divide by zero!");
}
return $a/$b;
}
}
$server = new SoapServer("test.wsdl",array('encoding'=>'GB2312'));
$server->addClass('math');
$server->handle();
?>
test.wsdl
<?xml version='1.0' encoding='UTF-8'?>
<!-- WSDL file generated by Zend Studio. -->
<definitions name="test" targetNamespace="urn:test" xmlns:typens="urn:test" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns="http://schemas.xmlsoap.org/wsdl/">
<message name="add">
<part name="a" type="xsd:integer"/>
<part name="b" type="xsd:integer"/>
</message>
<message name="addResponse">
<part name="addReturn" type="xsd:integer"/>
</message>
<message name="div">
<part name="a1" type="xsd:integer"/>
<part name="b1" type="xsd:integer"/>
</message>
<message name="divResponse">
<part name="divReturn" type="xsd:integer"/>
</message>
<message name="sub">
<part name="a2" type="xsd:integer"/>
<part name="b2" type="xsd:integer"/>
</message>
<message name="subResponse">
<part name="subReturn" type="xsd:integer"/>
</message>
<portType name="mathPortType">
<documentation>
A simple math utility class
</documentation>
<operation name="add">
<documentation>
Add two integers together
</documentation>
<input message="typens:add"/>
<output message="typens:addResponse"/>
</operation>
<operation name="div">
<documentation>
Divide two integers
</documentation>
<input message="typens:div"/>
<output message="typens:divResponse"/>
</operation>
<operation name="sub">
<documentation>
Subtract two integers from each other
</documentation>
<input message="typens:sub"/>
<output message="typens:subResponse"/>
</operation>
</portType>
<binding name="mathBinding" type="typens:mathPortType">
<soap:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http"/>
<operation name="add">
<soap:operation soapAction="urn:mathAction"/>
<input>
<soap:body namespace="urn:test" use="literal"/>
</input>
<output>
<soap:body namespace="urn:test" use="literal"/>
</output>
</operation>
<operation name="div">
<soap:operation soapAction="urn:mathAction"/>
<input>
<soap:body namespace="urn:test" use="literal"/>
</input>
<output>
<soap:body namespace="urn:test" use="literal"/>
</output>
</operation>
<operation name="sub">
<soap:operation soapAction="urn:mathAction"/>
<input>
<soap:body namespace="urn:test" use="literal"/>
</input>
<output>
<soap:body namespace="urn:test" use="literal"/>
</output>
</operation>
</binding>
<service name="testService">
<port name="mathPort" binding="typens:mathBinding">
<soap:address location="'http://localhost/server.php"/>
</port>
</service>
</definitions>
...全文
221 回复 打赏 收藏 转发到动态 举报
写回复
用AI写文章
回复
切换为时间正序
请发表友善的回复…
发表回复
gSOAP编译工具提供了一个SOAP/XML 关于C/C++ 语言的实现,从而让C/C++语言开发web服务或客户端程序的工作变得轻松了很多。绝大多数的C++web服务工具包提供一组API函数类库来处理特定的SOAP数据结构,这样就使得用户必须改变程序结构来适应相关的类库。与之相反,gSOAP利用编译器技术提供了一组透明化的SOAP API,并将与开发无关的SOAP实现细节相关的内容对用户隐藏起来。   gSOAP的编译器能够自动的将用户定义的本地化的C或C++数据类型转变为符合XML语法的数据结构,反之亦然。这样,只用一组简单的API就将用户从SOAP细节实现工作中解脱了出来,可以专注与应用程序逻辑的实现工作了。gSOAP编译器可以集成C/C++和Fortran代码(通过一个Fortran到C的接口),嵌入式系统,其他SOAP程序提供的实软件的资源和信息;可以跨越多个操作系统,语言环境以及在防火墙后的不同组织。   gSOAP使编写web服务的工作最小化了。gSOAP编译器生成SOAP的代码来序列化或反序列化C/C++的数据结构。gSOAP包含一个WSDL生成器,用它   来为你的web服务生成web服务的解释。gSOAP的解释器及导入器可以使用户不需要分析web服务的细节就可以实现一个客户端或服务端程序。   下面是gSOAP的一些特点:   ×gSOAP编译器可以根据用户定义的C和C++数据结构自动生成符合SOAP的实例化代码。   ×gSOAP支持WSDL 1.1, SOAP 1.1, SOAP 1.2, SOAP RPC 编码方式以及 literal/document 方式.   ×gSOAP是少数完全支持SOAP1.1 RPC编码功能的工具包,包括多维数组及动态类型。比如,一个包含一个基类参数的远程方法可以接收客户端   传来的子类实例。子类实例通过动态绑定技术来保持一致性。   ×gSOAP 支持 MIME (SwA) 和 DIME 附件包。   ×gSOAP是唯一支持DIME附件传输的工具包。它允许你在保证XML可用性的同能够以最快的方式(流方式)传递近乎无大小限制的二进制数据   。   ×gSOAP 支持 SOAP-over-UDP。   ×gSOAP 支持 IPv4 and IPv6.   ×gSOAP 支持 Zlib deflate and gzip compression(for HTTP, TCP/IP, and XML file storage)。   ×gSOAP 支持 SSL (HTTPS)。   ×gSOAP 支持 HTTP/1.0, HTTP/1.1 保持连接, 分块传输及基本验证。   ×gSOAP 支持 SOAP 单向消息。   ×gSOAP 包含一个 WSDL 生成器,便于web服务的发布。   ×gSOAP 包含一个WSDL解析器(将WSDL转换为gSOAP头文件),可以自动化用户客户端及服务端的开发。   ×生成可以单独运行的web服务及客户端程序。   ×因为只需要很少内存空间,所以可以运行在类似Palm OS, Symbian, Pocket PC的小型设备中。   ×适用于以C或C++开发的web服务中。   ×跨平台:Windows, Unix, Linux, Mac OS X, Pocket PC, Palm OS, Symbian等。   ×支持序列化程序中的本地化C/C++数据结构。   ×可以使用输入和输出缓冲区来提高效率,但是不用完全消息缓冲来确定HTTP消息的长度。取而代之的是一个三相序列化方法。这样,像64位   编码的图像就可以在小内存设备(如PDA)中以DIME附件或其他方式传输。   ×支持C++单继承,动态绑定,重载,指针结构(列表、树、图、循环图,定长数组,动态数组,枚举,64位2进制编码及16进制编码)。   ×不需要重写现有的C/C++应用。但是,不能用unions,指针和空指针来作为远程方法调用参数的数据结构中元素。   ×三相编组:1)分析指针,引用,循环数据结构;2)确定HTTP消息长度;3)将数据序列化位SOAP1.1编码方式或用户定义的数据编码方式。   ×双相编组:1)SOAP解释及编码;2)分解“forward”指针(例如:分解SOAP中的href属性)。   ×完整可定制的SOAP错误处理机制。   ×可定制的SOAP消息头处理机制,可以用来保持状态信息   2 gSoap2.2版与gSOAP 2.1版(或以前版本)的不同   如果你是从2.1版升级到2.2或以后版本,请注意这些变化。   为了能够分离传输、内容编码、映射中的接收/发送设置,改变了运行选项及标志。这些标志分布再四个类中:传输(IO),内容编码(ENC   

21,882

社区成员

发帖
与我相关
我的任务
社区描述
从PHP安装配置,PHP入门,PHP基础到PHP应用
社区管理员
  • 基础编程社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧