【问题标题】:How declare WSDL for PHP function that returns multiple TYPES?如何为返回多种类型的 PHP 函数声明 WSDL?
【发布时间】:2009-09-21 15:07:43
【问题描述】:

我正在编写一个 PHP Web 服务和一个函数。我想在 PHP 中建立一个 Web 服务。我需要为此 Web 服务生成 WSDL 描述,以便可以从 I.e. 访问它。视觉工作室。它将文档/搜索字符串作为输入,并推荐类似的文档作为输出。我返回一个带有第一个元素 resultCode (int) 的数组,它显示操作是成功 (1) 还是失败 (0)。然而,第二个元素可能是一个错误消息(字符串),它告诉用户出了什么问题,也可能是一个复杂的返回类型,比如一个包含不同匹配文章的子元素的数组,即 array( array("heading"=>"文章标题", "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 的松散类型使我对返回类型使用了糟糕的设计,而我需要使用其他东西?

欢迎任何建议。

【问题讨论】:

    标签: php web-services wsdl nusoap


    【解决方案1】:

    可以使用xsd:anytype。事实上,我不推荐它,因为 .NET 和 Java 等基于类型的环境将无法处理您的 wsdl。

    为了得到一个干净的解决方案,我会重新考虑设计 php 引诱你...... ;)

    【讨论】:

      【解决方案2】:

      你可以返回

      • 第一个元素:错误代码,0 = 错误,1 = 良好
      • 第二个元素:错误消息,如果我们很好,则为空
      • 第三个元素:你的复杂类型,如果我们不好,就空一个。

      【讨论】:

        【解决方案3】:

        您应该始终返回相同的结构。在失败的情况下,您应该通过使用 SOAP 错误来使用异常,就像在正常使用中一样: http://www.ibm.com/developerworks/webservices/library/ws-tip-jaxrpc.html

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2021-04-16
          • 2019-07-20
          • 2012-09-26
          • 1970-01-01
          • 1970-01-01
          • 2019-06-23
          相关资源
          最近更新 更多