简体   繁体   English

将CURL用于SOAP是一种不好的做法吗?

[英]Is using CURL for SOAP a bad practice?

There is a piece of software in my company connecting periodically with some webservices via SOAP protocol using curl in PHP. 我公司中有一个软件,使用PHP中的curl通过SOAP协议与一些Web服务定期连接。 From time to time this fails and the whole system is very unstable. 这有时会失败,并且整个系统非常不稳定。 I was a bit surprised seeing curl as a main tool talking to these webservices, because I thought there exist robust and mature high level libraries for most languages (including PHP and python) and curl is relatively low-level and doesn't provide any error handling. 我将curl作为与这些Web服务通信的主要工具感到有些惊讶,因为我认为对于大多数语言(包括PHP和python)都存在健壮且成熟的高级库,而curl是相对低级的,并且不提供任何错误处理。 Am I right? 我对吗? What is the best solution for communication via SOAP? 通过SOAP进行通信的最佳解决方案是什么? Is there some enterprise standard I can follow? 我可以遵循一些企业标准吗? Please help. 请帮忙。

PHPs build in SOAP Client is already very robust and abstracts many of the commonly needed stuff: 在SOAP Client中构建的PHP已经非常强大,并且抽象了许多常用的东西:

$this->soapClient = new SoapClient($wsdl_url);
// What interface is available, which function can you call?
var_dump($this->soapClient->__getFunctions());

// Call
$result = $this->soapClient->someMethodExposedByTheApi();

// Soap Elements (Tags in the XML) are available as properties:
echo $result->someProperty;

// Nested Tags are available as object chain:
echo $result->someNestedTags->nestedTag;

I could not imagine how it can be any simpler ... 我无法想象它怎么可能更简单...

If you need to setup a SOAP Service, you may want to use Zend_Soap, a stand alone component in the Zend Framework, that automatically builds a webservice based on a wsdl. 如果您需要设置SOAP服务,则可能要使用Zend_Soap,它是Zend Framework中的独立组件,它可以基于wsdl自动构建Web服务。 It also has a wrapper on top of PHP's SoapClient, but this is mainly used to converge naming and coding conventions to the Zend Framework and does not provide much additional functionality. 它在PHP的SoapClient之上也有一个包装器,但是它主要用于将命名和编码约定收敛到Zend框架,并且不提供太多附加功能。

However: Curl is ok if you have very specific requierements. 但是:如果您有非常具体的要求,则可以使用Curl。 If it fails from time to time and your system is unstable, than it's not a problem of curl. 如果它不时出现故障并且系统不稳定,那么这不是卷曲问题。 It may be a misconfiguration of the service or system. 这可能是服务或系统的配置错误。

Basically the SoapClient builds an XML based on the Standard. 基本上,SoapClient基于标准构建XML。 If you build the XML for yourself (for whatever reason), curl is ok. 如果您自己构建XML(无论出于何种原因),curl都是可以的。

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

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