如何使用Soap服务器下载XML内容并使用PHP和nusoap通过Soap客户端使用XML内容

时间:2018-08-02 12:05:08

标签: php soap nusoap

我正在使用肥皂服务器和客户端来测试客户端与服务器之间的通信。因此,我在服务器端有一个XML文件。我需要使用SOAP客户端服务器在客户端中访问该文件。我很困惑如何从服务器获取该XML文件并从客户端使用它。拜托,任何人,请帮帮我。提前致谢。

服务器端代码

require 'nusoap/lib/nusoap.php';
require_once 'functions.php';
$server = new nusoap_server();

$server->configureWSDL('demo', 'urn:demo');

$server->register('peekMessages', array(), array("peekMessagesReturn" => "impl:ArrayOf_xsd_string"));

//$HTTP_RAW_POST_DATA = isset($HTTP_RAW_POST_DATA) ? $HTTP_RAW_POST_DATA : '';
$postdata = file_get_contents("php://input");

$server->service($postdata);

Functions.php

function peekMessages()
{
    $xml = simplexml_load_file("http://localhost/Projects/soap-server/xml/message-data.xml");
    return $xml;

}

客户端代码:

require 'nusoap/lib/nusoap.php';


$client = new nusoap_client("http://localhost/Projects/soap-server/server.php?wsdl", true);
$client->soap_defencoding = 'UTF-8';
$client->decode_utf8 = FALSE;

$book = "abc";


//$data = $client->call('price', array("name"=> "$book"));
$data = $client->call('peekMessages');

echo json_encode($data);

XML格式

<?xml version="1.0"?>
<Message>
    <messagerx>
        <sourcemsisdn>123456789</sourcemsisdn>
        <destinationmsisdn>987654321</destinationmsisdn>
        <receivedtime>22/08/2018 09:35:31</receivedtime>
        <bearer>SMS</bearer>
        <messageref>0</messageref>
        <message>
            <id>abc123</id>
            <s1>0</s1>
            <s2>1</s2>
            <s3>0</s3>
            <s4>1</s4>
            <f>0</f>
            <t>38</t>
            <k>5</k>
        </message>
    </messagerx>
    <messagerx>
        <sourcemsisdn>987654321</sourcemsisdn>
        <destinationmsisdn>123456789</destinationmsisdn>
        <receivedtime>23/08/2018 09:35:31</receivedtime>
        <bearer>SMS</bearer>
        <messageref>0</messageref>
        <message>
            <id>abc123</id>
            <s1>0</s1>
            <s2>1</s2>
            <s3>0</s3>
            <s4>1</s4>
            <f>0</f>
            <t>38</t>
            <k>5</k>
        </message>
    </messagerx>
</Message>

0 个答案:

没有答案