复杂类型在PHP中的NuSOAP [英] Complex type in PHP NuSoap

查看:343
本文介绍了复杂类型在PHP中的NuSOAP的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我建立使用的NuSOAP库在PHP Web服务。我的web服务将作为由供应商的客户端和一个已经存在的网络服务之间的中间层。所以不是客户端连接到供应商的直接,它们将连接到我的web服务,我的网络服务连接到供应商和抓住响应,并发送相同的响应返回给客户端。

I am building a web service using NuSoap library in PHP. My webservice will act as a middle layer between client and an already existing web service by a vendor. So instead of client connecting to the vendor directly, they will connect to my web service, my web service connects to the vendor and grab the response and send the same response back to the client.

我唯一的问题是我的供应商正在发回stdClass的对象(他们的web服务.NET编写的),我不得不接收对象,并发送回同一个对象在客户端上我的web服务的方法。

My only problem is my vendor is sending back stdclass object (their webservice is written in .Net) and I have to receive that object and send back the same object to the client on my webservice method.

我有搜索在互联网上颇有几分,但没有明确的方式如何通过的NuSOAP库达致这事。无论我至今读,指定我必须使用复杂类型来达致这,但同样我不知道如何抓住响应,然后将其转化成复杂的类型,并将其发送给客户端。

I have searched quite a bit on Internet but there are no clear ways how to do acheive this by NuSoap library. Whatever I have read so far, specify that I have to use complex type to acheive this, but again I have no clue how to grab the response and then convert it to the complex type and send it back to the client.

在此先感谢您的帮助。

Thanks in advance for your help.

推荐答案

你所编写的被称为的代理

一些范例在线的NuSOAP服务器通过 addComplexType 方法发送复杂类型。

There are some examples online for NuSoap server sending complex types through the addComplexType method.

//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客户端操作比我的经验服务器让人更容易)。

One approach to implementing the proxy, is build your service with stubbed out data, such that it doesn't actually talk to the backend service first. See if you can get the original client satisfied with a contrived response from your proxy. Then once you have that, consuming the real backend service should be trivial (SOAP client operations are easier than server ones in my experience).

另一种方法是考虑本地 SoapServer的类代替。这里第一个评论展示了如何创建一个复杂类型。

Another alternative is to consider the native SoapServer class instead. The first comment here shows how to create a complex type.

修改

环视了一下后,使这里是一个的更好的例子

After looking around a bit more, here is a much better example.

有2种方式来注册一个复杂类型的NuSOAP,按照文档块上 addComplextType (LIB / class.wsdl.php)

There are 2 ways to register a complex type with NuSoap, per the docblock on addComplextType (lib/class.wsdl.php)

/**  
* 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
*/

看他是如何做对后面的例子我张贴:

See how he does it on the later example I posted:

$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')
    )
);

那么如何返回与联系的复杂类型的响应:

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;
}

您还可以看到如何使用数组变量在他的榜样。很抱歉的巨大答案!

You can also see how to use the array variant in his example. Sorry for the huge answer!

这篇关于复杂类型在PHP中的NuSOAP的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆