PHP - 使用 SOAP WSDL 连接网络服务 API
PHP - Connecting with webservice API using SOAP WSDL
我的一位客户最近要求我将他的网络服务与一些外部公司集成 API。我必须在 PHP 中添加集成控制器,因为这是处理他的表单的方式。
公司为我提供:
1) Web 服务的 WSDL 定义,
2) 一个名为 contract.xml,
的示例
3) 两个 .xsd 文件,用于数据验证,
4) 三个 .xml 示例(soap 请求、response-true 和 response-false)
我从来没有做过这样的事情,我想知道是否有任何尝试的意义,如果有人能为我提供一些知识,让我开始思考我自己的方式,我将不胜感激。
架构是什么样的:将 'blank' 请求设置为 PHP var
并使用表单输入更新它是一个很好的解决方案吗?还是我应该尝试学习更多关于 XML 解析的知识然后走这条路?
如果您有 WSDL(Web 服务文档语言)xml 文件或者您可以在线访问要使用的服务的 wsdl,则无需解析任何 xml沟通,所有你应该做的定义对象
$mySoapClient = new SoapClient("path/to/your/wsdl.xml", array("here you should write the params that required your soap service"));
也可能有用户凭据,您可以使用
进行设置
$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));
连接后,您将使用 $soapClient 对象访问所有提供 soap 服务器的方法
像这样
$soapClient->someMethodThatProvideMySoapServer($someParams);
您的服务器中没有此方法 someMethodThatProvideMySoapServer,它来自 soap 服务器,您可以使用它
有关更多详细信息,您可以从此处学习
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
我的一位客户最近要求我将他的网络服务与一些外部公司集成 API。我必须在 PHP 中添加集成控制器,因为这是处理他的表单的方式。
公司为我提供:
1) Web 服务的 WSDL 定义,
2) 一个名为 contract.xml,
的示例3) 两个 .xsd 文件,用于数据验证,
4) 三个 .xml 示例(soap 请求、response-true 和 response-false)
我从来没有做过这样的事情,我想知道是否有任何尝试的意义,如果有人能为我提供一些知识,让我开始思考我自己的方式,我将不胜感激。
架构是什么样的:将 'blank' 请求设置为 PHP var
并使用表单输入更新它是一个很好的解决方案吗?还是我应该尝试学习更多关于 XML 解析的知识然后走这条路?
如果您有 WSDL(Web 服务文档语言)xml 文件或者您可以在线访问要使用的服务的 wsdl,则无需解析任何 xml沟通,所有你应该做的定义对象
$mySoapClient = new SoapClient("path/to/your/wsdl.xml", array("here you should write the params that required your soap service"));
也可能有用户凭据,您可以使用
进行设置$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));
连接后,您将使用 $soapClient 对象访问所有提供 soap 服务器的方法 像这样
$soapClient->someMethodThatProvideMySoapServer($someParams);
您的服务器中没有此方法 someMethodThatProvideMySoapServer,它来自 soap 服务器,您可以使用它 有关更多详细信息,您可以从此处学习 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