WSDL 和 SOAP:返回带有方法的对象
有没有办法用肥皂的方法返回一个对象?如果我在 WSDL 中返回 xsd:struct,我只能获取对象的属性,但不能使用任何方法。
例如
class person
{
var $name = "My name";
public function getName()
{
return $this->name;
}
}
,在获取对象后:
$client = new SoapClient();
$person = $client->getPerson();
echo $person->getName(); // Return "My Name";
谢谢。
Is there a way to return in soap an object with his methods? If i return xsd:struct in WSDL i only get the properties of the object but i can't use any of the methods.
For example
class person
{
var $name = "My name";
public function getName()
{
return $this->name;
}
}
So after fetching the object:
$client = new SoapClient();
$person = $client->getPerson();
echo $person->getName(); // Return "My Name";
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您无法使用
SOAP
来做到这一点。基本上,您的 PHP 类被映射到由 XML 模式定义的 XML 数据结构。此映射仅包含属性,不能包含可执行代码。SOAP
是为互操作性而设计的,当然您不能在 PHP 和 Java 或 .NET 之间共享代码。在接收端,您的 XML 数据结构将转换为客户端编程语言的数据结构(如果您使用SoapClient
则为 PHP 类,如果您使用C#
类,则为C#
类)代码>C#)。由于 XML 数据结构仅携带属性信息,因此无法重建原始类的可执行部分。但是如果 SOAP 服务器和连接客户端都可以访问相同的代码库(这意味着相同的类),那么有一件事会有所帮助。您可以使用
classmap
在SoapClient
的构造函数中定义XML
类型和PHP
类之间的映射-选项。这允许 SoapClient 将传入的 XML 数据结构映射到真正的 PHP 类 - 考虑到服务器和客户端都可以访问相关的类定义。这允许您使用 SOAP 通信接收端的方法。WSDL
可能看起来像(从SoapClient
测试之一复制并进行修改):如果您在 PHP 中使用
SOAP
,那么 PHP 中的 SOAP 状态 可能会很有趣。You cannot do this with
SOAP
. Basically your PHP class is being mapped to an XML data structure that's defined by an XML schema. This mapping only includes properties and cannot include executable code.SOAP
is designed for interoperability and naturally you cannot share code between, let's say, PHP and Java or .NET. On the receiving side your XML data structure is being transformed into a data structure of the client's programming language (a PHP class if you useSoapClient
or aC#
class if you useC#
). As the XML data structure only carries property information the executable part of the originating class cannot be rebuilt.But there is one thing that can help if both the SOAP server and the connecting client have access to the same code base (which means the same classes). You can define a mapping between a
XML
type and aPHP
class in theSoapClient
's constructor using theclassmap
-option. This allowsSoapClient
to map incoming XML data structures to real PHP classes - given the fact that both the server and the client have access to the relevant class definition. This allows you to use methods on the receiving side of theSOAP
communication.The
WSDL
might look like (copied from one of theSoapClient
tests and adpated):The State of SOAP in PHP might be interesting if you're doing
SOAP
in PHP.