如何为返回多个类型的 PHP 函数声明 WSDL?
我正在编写一个 PHP Web 服务和一个函数。我想用 PHP 设置 Web 服务。我需要生成此 Web 服务的 WSDL 描述,以便可以从 Ie Visual Studio 访问它。它将文档/搜索字符串作为输入,并推荐类似的文档作为输出。我返回一个数组,其第一个元素 resultCode (int) 显示操作是成功 (1) 还是失败 (0)。然而,第二个元素可以是告诉用户出了什么问题的错误消息(字符串),也可以是复杂的返回类型,例如具有不同匹配文章的子元素的数组,即 array( array("标题"=>"文章标题", "articleId"=>12345, "text"=>"文章正文"), array( ... ), ... ).我需要知道如何为该返回类型生成/编写 WSDL,或者如何在 NuSOAP 中执行此操作。你会怎么做?
这是我当前用于设置服务的一些代码。
$server->wsdl->addComplexType(
'returnStructBase',
'complexType',
'struct',
'all',
'',
array('resultCode' => array('name'=>'resultCode', 'type'=>'xsd:int'),
'resultData' => array('name'=>'resultData', 'type'=>'xsd:anyType')
)
);
$server->wsdl->addComplexType(
'returnStructArray',
'complexType',
'array',
'',
'SOAP-ENC:Array',
array(),
array(
array('ref' => 'SOAP-ENC:arrayType',
'wsdl:arrayType' => 'tns:returnStructBase[]'
)
),
'tns:returnStructArray'
);
$server->register("GetRecommendations", array('username'=>'xsd:string', 'password'=>'xsd:string','articleId'=>'xsd:string',
'text'=>'xsd:string', 'returnText'=>'xsd:boolean'), array('return'=>'tns:returnStructArray'), $namespace, $namespace . '#getRecommendations', 'rpc', 'encoded', ' ... ');
也许 PHP 的松散类型使我对返回类型使用了糟糕的设计,而我需要使用其他东西?
欢迎任何建议。
I'm writing a PHP web service and one function. I want to set up a web service in PHP. I need to generate the WSDL description for this web service so it's accessible from I.e. visual studio. It takes documents / search strings as inputs and recommends similar documents as output. I return an array with a first element resultCode (int) which shows if the operation was a success (1) or a failure (0). The second element, however, could either be an error message (string) which tells the user what went wrong, or a complex return type like an array with subelements for the different matching articles, i.e.
array( array("heading"=>"article heading", "articleId"=>12345, "text"=>"body text of article"), array( ... ), ... ). I need to know how to generate/write the WSDL for that return type or how to do that in NuSOAP. How would you do that?
This is some of the code that I'm currently using to set up the service.
$server->wsdl->addComplexType(
'returnStructBase',
'complexType',
'struct',
'all',
'',
array('resultCode' => array('name'=>'resultCode', 'type'=>'xsd:int'),
'resultData' => array('name'=>'resultData', 'type'=>'xsd:anyType')
)
);
$server->wsdl->addComplexType(
'returnStructArray',
'complexType',
'array',
'',
'SOAP-ENC:Array',
array(),
array(
array('ref' => 'SOAP-ENC:arrayType',
'wsdl:arrayType' => 'tns:returnStructBase[]'
)
),
'tns:returnStructArray'
);
$server->register("GetRecommendations", array('username'=>'xsd:string', 'password'=>'xsd:string','articleId'=>'xsd:string',
'text'=>'xsd:string', 'returnText'=>'xsd:boolean'), array('return'=>'tns:returnStructArray'), $namespace, $namespace . '#getRecommendations', 'rpc', 'encoded', ' ... ');
Maybe PHP's loose typing made me use a bad design for a return type and I need to use something else?
Any recommendations welcome.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可以使用
xsd:anytype
。事实上,我不推荐它,因为基于类型的环境(例如 .NET 和 Java)将无法处理您的 wsdl。为了得到一个干净的解决方案,我会重新考虑设计 php 引诱你......;)
You could use
xsd:anytype
. In fact I'd not recomend it, since type based environments like .NET and Java will not be able to handle your wsdl.To get a clean solution I'd rethink that design php seduced you to... ;)
您可以返回
You can return
您应该始终返回相同的结构。如果发生故障,您应该像正常使用 SOAP 错误一样使用异常:
http://www.ibm.com/developerworks/webservices/库/ws-tip-jaxrpc.html
You should always return the same structure. In the case of a failure you should use exceptions just like in normal usage by using SOAP faults:
http://www.ibm.com/developerworks/webservices/library/ws-tip-jaxrpc.html