如何制作PHP SOAP客户端并将结果xml存储在php变量中 [英] How to make a PHP SOAP client and store the result xml in php variables

查看:33
本文介绍了如何制作PHP SOAP客户端并将结果xml存储在php变量中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 PHP,之前从未使用过 SOAP 和 PHP.

I am using PHP and have never used SOAP and PHP before.

我需要构建一个 Soap PHP 客户端,它从一个Soap 服务器 .NET Web 服务.

I need to build a Soap PHP Client which is calling and retrieves information from a Soap server .NET Web service.

我目前正在为荷兰医疗保健系统的医生获取信息.对于在荷兰医疗保健系统中注册的每位医生,您都可以检索他的信息通过他的唯一唯一 BIG ID - 11 位唯一编号 )来自使用 WSDL 的 SOAP 网络服务.

I'm currently working on getting information for Doctors in Dutch Health care system .for Every doctor which is registered in the Dutch of health care system you can retrieve his information through his unique unique BIG ID - 11 digit unique number ) from a SOAP web-service using WSDL.

因此,当我调用 SOAP 服务器 时:(服务器链接如下)

So when I am calling the SOAP server : (link of the server is below)

进入这个测试网站(如soapclinet.com)

into this a Testing web site (like soapclinet.com)

我的XML 响应是正确的,与下面的 XML 完全一样括号中是我想在php中捕获的医生信息.

my XML response is correct and looks exactly like this XML below in brackets the information of the doctor that i want to capture in php.

<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<soap:Body>
 <ListHcpApprox3Result xmlns="http://services.cibg.nl/ExternalUser">
  <ListHcpApprox>
   <ListHcpApprox3>
    <HcpNumber>200822</HcpNumber>
    <BirthSurname> [Surname of the Doctor]</BirthSurname>
    <MailingName> [Mailing name of the doctor] </MailingName>
    <Initial> [Initials of the doctor] </Initial>
    <Gender> [Gender of the doctor] </Gender>
    <ArticleRegistration>
    <ArticleRegistrationExtApp>
    <ArticleRegistrationNumber> [unique BIG ID]  </ArticleRegistrationNumber>
    <StartDate>1998-12-10T00:00:00</StartDate>
    <EndDate xsi:nil="true"/>
    <TypeOfSpecialismId>15</TypeOfSpecialismId>
    </SpecialismExtApp>
    </Specialism>
    <Mention/>
    <JudgmentProvision/>
    <Limitation/>
   </ListHcpApprox3>
  </ListHcpApprox>
 </ListHcpApprox3Result>
</soap:Body>
</soap:Envelope>

我需要构建一个 PHP 网页,该网页将执行完全相同的 SOAP 调用.

wsdl文件的地址是这样的:

webservices.cibg.nl/Ribiz/OpenbaarV2.asmx?wsdl.asmx?wsdl

webservices.cibg.nl/Ribiz/OpenbaarV2.asmx?wsdl.asmx?wsdl

soap 服务器地址是这样的:http://webservices-acc.cibg.nl/Ribiz/OpenbaarV2.asmx

肥皂动作是这样的:http://services.cibg.nl/ExternalUser/ListHcpApprox3

我发送的 SOAP 消息是这样的:

<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
 <listHcpApproxRequest xmlns="http://services.cibg.nl/ExternalUser">
  <WebSite>Ribiz</WebSite>
  <RegistrationNumber> [BIG ID number of the doctor] </RegistrationNumber>
 </listHcpApproxRequest>
</soap:Body>
</soap:Envelope>

(括号中是我们在SOAP服务器中发送的医生的BIG ID号)

(in brackets is the BIG ID number of the doctor that we send in SOAP server)

如何将上述 SOAP 操作写入 PHP 代码并将我作为响应获得的 XML 变量存储在 PHP 中?

我需要存储在 php 代码中的 XML 响应中的变量是这些...

the variables in XML response that I need to store in php code are these...

<HcpNumber>200822</HcpNumber>
<BirthSurname> [Surname of the Doctor]</BirthSurname>
<MailingName> [Mailing name of the doctor] </MailingName>
<Initial> [Initials of the doctor] </Initial>
<Gender> [Gender of the doctor] </Gender> 

Update1:​​ 这是 var_dump 的输出.其中 xxxxxxx 是我想存储在 php 变量中的值!

object(stdClass)[2]
  public 'ListHcpApprox' => 
    object(stdClass)[3]
      public 'ListHcpApprox3' => 
        object(stdClass)[4]
          public 'HcpNumber' => string 'xxxxxxxxx' (length=6)
          public 'BirthSurname' => string 'xxxxxxxxxxx' (length=9)
          public 'MailingName' => string 'xxxxxxxxxxxxxxxxxx' (length=18)
          public 'Initial' => string 'xxxxxxxxxxxx' (length=8)
          public 'Gender' => string 'x' (length=1)
          public 'ArticleRegistration' => 
            object(stdClass)[5]
              ...
          public 'Specialism' => 
            object(stdClass)[7]
              ...
          public 'Mention' => 
            object(stdClass)[9]
              ...
          public 'JudgmentProvision' => 
            object(stdClass)[10]
              ...
          public 'Limitation' => 
            object(stdClass)[11]
              ...

推荐答案

PHP 有一个原生的 SoapClient 类,可以轻松调用 SOAP 服务.它提供了一个简单的接口,允许您将原生 PHP 数组和对象用于请求和响应数据,并处理 SOAP 信封和 WSDL 的复杂性.

PHP has a native SoapClient class that makes it easy to call SOAP services. It provides a simple interface allowing you to use native PHP arrays and objects for the request and response data, and handles the intricacies of the SOAP envelope and WSDL.

// create a new SoapClient and pass it the WSDL
$client = new SoapClient('http://webservices.cibg.nl/Ribiz/OpenbaarV2.asmx?WSDL');

// define the input parameters for the webservice call
$params = array('WebSite' => 'Ribiz', 'RegistrationNumber' => 'xxxxxxxxxx');
// invoke the ListHcpApprox3 method
$response = $client->ListHcpApprox3($params);

// print out the response to see its structure
var_dump($response);

您可以像这样从响应中选择变量:

You can pick the variables out of the response like this:

$data = $response->ListHcpApprox->ListHcpApprox3
$HcpNumber = $data->HcpNumber;
$BirthSurname = $data->BirthSurname;

echo $HcpNumber;

这篇关于如何制作PHP SOAP客户端并将结果xml存储在php变量中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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