简体   繁体   English

PHP-使用SOAP WSDL连接Web服务API

[英]PHP - Connecting with webservice API using SOAP WSDL

One of my customers recently asked me to integrate his webservice with some external companies API. 我的一位客户最近要求我将其Web服务与一些外部公司的API集成在一起。 I have to add integration controller in PHP as this is how his form is being processed. 我必须在PHP中添加集成控制器,因为这是处理他的表单的方式。

The company provided me with: 该公司为我提供了:

1) WSDL definition of web service, 1)Web服务的WSDL定义,

2) An example named contract.xml, 2)一个名为contract.xml的示例,

3) Two .xsd files that are to be used to data validation, 3)两个用于数据验证的.xsd文件,

4) Three .xml examples (of soap request, response-true and response-false) 4)三个.xml示例(soap请求,response-true和response-false)

I've never done anything like this and i'm wondering if there's any point trying, would be very grateful if anyone could provide me with some knowledge that would let me start thinking my own way on this subject. 我从来没有做过这样的事情,我想知道是否有任何尝试的地方,如果有人可以向我提供一些知识,让我开始思考这个问题,我将不胜感激。

What would be the schema like: setting 'blank' request as PHP var and updating it with forms input would be good solution? 这样的模式是什么样的:将“空白”请求设置为PHP var并使用表单输入进行更新将是一个好的解决方案? Or should i rather try to learn some more on XML parsing and go this way? 还是我应该尝试学习有关XML解析的更多知识并采用这种方式?

you don't need to parse any xml, if you have WSDL (web service documentation language) xml file or you have online access to the wsdl of the service with which you going to comunicate, all that you should do define the object 您不需要解析任何xml,如果您具有WSDL(Web服务文档语言)xml文件,或者可以在线访问要与之通信的服务的wsdl,那么您应该做的所有事情就是定义对象

$mySoapClient = new SoapClient("path/to/your/wsdl.xml", array("here you should write the params that required your soap service")); $ mySoapClient = new SoapClient(“ path / to / your / wsdl.xml”,array(“此处您应该编写需要您的soap服务的参数”));

also there might be user credential which you can set with 也可能有您可以设置的用户凭证

$soapClient = new SoapClient("https://soapserver.example.com/blahblah.asmx?wsdl"); 

// Prepare SoapHeader parameters 
$sh_param = array( 
            'Username'    =>    'username', 
            'Password'    =>    'password'); 
$headers = new SoapHeader('http://soapserver.example.com/webservices', 'UserCredentials', $sh_param); 

// Prepare Soap Client 
$soapClient->__setSoapHeaders(array($headers)); 

after connection you will use your $soapClient object to get access to all methods that provide your soap server like this 连接后,您将使用$ soapClient对象访问提供此类肥皂服务器的所有方法

$soapClient->someMethodThatProvideMySoapServer($someParams); $ soapClient-> someMethodThatProvideMySoapServer($ someParams);

this method someMethodThatProvideMySoapServer you don't have in your server this coming from soap server and you can use it for more detailes you can learn from here http://php.net/manual/en/book.soap.php http://php.net/manual/en/class.soapclient.php Creating a SOAP call using PHP with an XML body 这种方法someMethodThatProvideMySoapServer在您的服务器中没有,它来自soap服务器,您可以使用它来了解更多详细信息,您可以从这里学习http://php.net/manual/en/book.soap.php http:// php.net/manual/en/class.soapclient.php 使用带有XML主体的PHP创建SOAP调用

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

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