如何从PHP发布SOAP请求 [英] How to post SOAP Request from PHP

查看:65
本文介绍了如何从PHP发布SOAP请求的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

任何人都知道如何从PHP发布SOAP请求吗?

Anyone know how can I post a SOAP Request from PHP?

推荐答案

以我的经验,这并不是那么简单.内置的 PHP SOAP客户端不适用于.NET我们必须使用的基于SOAP的服务器.它抱怨模式定义无效.即使.NET客户端可以在该服务器上正常工作.顺便说一下,让我声称SOAP互操作性是一个神话.

In my experience, it's not quite that simple. The built-in PHP SOAP client didn't work with the .NET-based SOAP server we had to use. It complained about an invalid schema definition. Even though .NET client worked with that server just fine. By the way, let me claim that SOAP interoperability is a myth.

下一步是 NuSOAP .这工作了一段时间.顺便说一下,看在上帝的份上,别忘了缓存WSDL!但是,即使使用WSDL缓存的用户也抱怨该死的东西很慢.

The next step was NuSOAP. This worked for quite a while. By the way, for God's sake, don't forget to cache WSDL! But even with WSDL cached users complained the damn thing is slow.

然后,我们决定使用纯HTTP,组装请求并使用SimpleXMLElemnt读取响应,如下所示:

Then, we decided to go bare HTTP, assembling the requests and reading the responses with SimpleXMLElemnt, like this:

$request_info = array();

$full_response = @http_post_data(
    'http://example.com/OTA_WS.asmx',
    $REQUEST_BODY,
    array(
        'headers' => array(
            'Content-Type' => 'text/xml; charset=UTF-8',
            'SOAPAction'   => 'HotelAvail',
        ),
        'timeout' => 60,

    ),
    $request_info
);

$response_xml = new SimpleXMLElement(strstr($full_response, '<?xml'));

foreach ($response_xml->xpath('//@HotelName') as $HotelName) {
    echo strval($HotelName) . "\n";
}

请注意,在PHP 5.2中,您需要pecl_http,因为(surprise-surpise!)没有内置的HTTP客户端.

Note that in PHP 5.2 you'll need pecl_http, as far as (surprise-surpise!) there's no HTTP client built in.

使用裸HTTP可以使我们的SOAP请求时间超过30%.从那时起,我们将所有性能投诉重定向到服务器端.

Going to bare HTTP gained us over 30% in SOAP request times. And from then on we redirect all the performance complains to the server guys.

最后,我建议使用后一种方法,而不是因为性能.我认为,总的来说,在像PHP这样的动态语言中,所有WSDL/type-control都没有好处.您不需要花哨的库就可以读取和写入XML,并具有所有的存根生成和动态代理.您的语言已经是动态的,并且SimpleXMLElement可以正常工作,并且易于使用.另外,您将获得更少的代码,这总是很好.

In the end, I'd recommend this latter approach, and not because of the performance. I think that, in general, in a dynamic language like PHP there's no benefit from all that WSDL/type-control. You don't need a fancy library to read and write XML, with all that stubs generation and dynamic proxies. Your language is already dynamic, and SimpleXMLElement works just fine, and is so easy to use. Also, you'll have less code, which is always good.

这篇关于如何从PHP发布SOAP请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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