繁体   English   中英

PHP NuSoap中的复杂类型

[英]Complex type in PHP NuSoap

我正在使用PHP中的NuSoap库构建Web服务。 我的Web服务将充当客户端和供应商已经存在的Web服务之间的中间层。 因此,他们将连接到我的Web服务,而不是客户端直接连接到供应商,我的Web服务将连接到供应商并获取响应并将相同的响应发送回客户端。

我唯一的问题是我的供应商正在发送回stdclass对象(他们的Web服务是用.Net编写的),我必须接收该对象并将相同的对象发送回我的Webservice方法上的客户端。

我已经在Internet上进行了很多搜索,但是NuSoap库没有明确的方法来实现这一目标。 到目前为止,无论我读过什么,都必须指定必须使用复杂类型来实现此目的,但是我仍然不知道如何获取响应,然后将其转换为复杂类型并将其发送回客户端。

在此先感谢您的帮助。

您所写的内容称为代理

在线上有一些有关NuSoap服务器通过addComplexType方法发送复杂类型的addComplexType

//Create a complex type
$server->wsdl->addComplexType('MyComplexType','complexType','struct','all','',
array( 'ID' => array('name' => 'ID','type' => 'xsd:int'),
'YourName' => array('name' => 'YourName','type' => 'xsd:string')));

一种实现代理的方法是使用残存的数据构建服务,这样就不会真正与后端服务进行通信。 看看您是否可以使原始客户对代理人为的响应感到满意。 然后,一旦有了这些,使用真正的后端服务就变得微不足道了(根据我的经验,SOAP客户端操作比服务器操作更容易)。

另一种选择是考虑使用本机SoapServer类。 这里的第一个注释显示了如何创建复杂类型。

编辑

环顾四周后,这里有一个更好的例子

addComplextType (lib / class.wsdl.php)上的每个文档块中,有两种方法可以使用NuSoap注册复杂类型。

/**  
* adds an XML Schema complex type to the WSDL types
*
* @param string $name
* @param string $typeClass (complexType|simpleType|attribute)
* @param string $phpType currently supported are array and struct (php assoc array)
* @param string $compositor (all|sequence|choice)
* @param string $restrictionBase namespace:name (http://schemas.xmlsoap.org/soap/encoding/:Array)
* @param array $elements e.g. array ( name => array(name=>'',type=>'') )
* @param array $attrs e.g. array(array('ref'=>'SOAP-ENC:arrayType','wsdl:arrayType'=>'xsd:string[]'))
* @param string $arrayType as namespace:name (xsd:string)
* @see nusoap_xmlschema
* @access public
*/

在我发布的下一个示例中查看他的操作方式:

$server->wsdl->addComplexType('Contact',
    'complexType',
    'struct',
    'all',
    '',
    array(
            'id' => array('name' => 'id', 'type' => 'xsd:int'),
            'first_name' => array('name' => 'first_name', 'type' => 'xsd:string'),
            'last_name' => array('name' => 'last_name', 'type' => 'xsd:string'),
            'email' => array('name' => 'email', 'type' => 'xsd:string'),
            'phone_number' => array('name' => 'phone_number', 'type' => 'xsd:string')
    )
);

然后如何返回Contact复杂类型的响应:

function updateContact($in_contact) {
    $contact = new Contact($in_contact['id']);
    $contact->first_name=mysql_real_escape_string($in_contact['first_name']);
    $contact->last_name=mysql_real_escape_string($in_contact['last_name']);
    $contact->email=mysql_real_escape_string($in_contact['email']);
    $contact->phone_number=mysql_real_escape_string($in_contact['phone_number']);
    if ($contact->update()) return true;
}

您还可以在他的示例中看到如何使用数组变量。 对不起,答案很大!

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM