PHP Soap Server 响应格式

2024-03-29

我正在 PHP 中制作 SOAP Web 服务,该服务必须满足客户端 XSD 文件的要求。

以下是客户提供的 XSD 文件的链接:http://pastebin.com/MX1BZUXc http://pastebin.com/MX1BZUXc

他们期待的响应如下所示:

[为了便于阅读,一些长行被打断,理论上该问题与空格无关。]

<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
  <s:Header />
  <s:Body xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
          xmlns:xsd="http://www.w3.org/2001/XMLSchema">
    <CheckVersionResponse xmlns="http://www.---.---/---">
      <CheckversionResult>
        <ValidationOk>true</ValidationOk>
        <VersionNumber>1.4.0</VersionNumber>
        <CurrentRemoteServerTime
          >2014-05-02T09:35:20.368+02:00</CurrentRemoteServerTime>
      </CheckversionResult>
    </CheckVersionResponse>
  </s:Body>
</s:Envelope>

但是,我目前得到的回复如下所示:

<env:Envelope xmlns:env="http://www.w3.org/2003/05/soap-envelope" 
              xmlns:ns1="http://---.---/" 
              xmlns:xsd="http://www.w3.org/2001/XMLSchema" 
              xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
              xmlns:enc="http://www.w3.org/2003/05/soap-encoding">
<env:Body xmlns:rpc="http://www.w3.org/2003/05/soap-rpc">
    <ns1:CheckVersionResponse 
      env:encodingStyle="http://www.w3.org/2003/05/soap-encoding">
        <rpc:result>return</rpc:result>
        <return xsi:type="enc:Struct">
            <ValidationOk xsi:type="xsd:int">1</ValidationOk>
            <VersionNumber xsi:type="xsd:string"
              >1.4.0</VersionNumber>
            <CurrentRemoteServerTime xsi:type="xsd:string"
              >2014-05-08T10:31:49</CurrentRemoteServerTime>
        </return>
    </ns1:CheckVersionResponse>
</env:Body>
</env:Envelope>

这就是我制作 SOAP Web 服务的方式:

<?php

/* Helper class for my response object */
class CheckVersionResult extends stdClass
{
    /** @var bool */
    public $ValidationOk = '';
    /** @var string */
    public $VersionNumber = '';
    /** @var string */
    public $CurrentRemoteServerTime = '';
}

/* SOAP interface class */
class MySoapClass
{
    /**
     * Returns version
     *
     * @param string $param1
     * @param string $param2
     * @return CheckVersionResult
     */
    public function CheckVersion($param1, $param2)
    {
        $data = new CheckVersionResult();
        $data->ValidationOk = 1;
        $data->VersionNumber = '1.4.0';
        $data->CurrentRemoteServerTime = date('Y-m-d\TH:i:s');
    }
}

/* Controller class */
class WebserviceController {

    public function indexAction() {
        $soap = new Zend_Soap_Server();
        $soap->setClass('MySoapClass');
        $soap->setUri("http://---.---/");
        $mySoapClass = new MySoapClass();
        $soap->setObject($mySoapClass);
        $soap->setSoapVersion(SOAP_1_2);
        $soap->handle();
    }

}

这就是我调用我的网络服务的方式:

$client = new SoapClient(null, array(
    "soap_version" => SOAP_1_2,
    "location" => "http://---.---/webservice/index",
    "uri" => "http://---.---/",
    "trace" => 1, // enable trace to view what is happening
    "exceptions" => 0, // disable exceptions
    "cache_wsdl" => 0)   // no wsdl
);

$client->CheckVersion('param1', 'param2');
header('Content-Type: application/xml; charset=utf-8');
echo $client->__getLastResponse();
die();

有谁知道如何根据我收到的 XSD 文件正确格式化我的 SOAP 响应?


您必须构建正确的 wsdl 文件。现在您的服务器正在以默认的 rpc 方式运行。尝试使用:http://framework.zend.com/manual/1.12/en/zend.soap.autodiscovery.html http://framework.zend.com/manual/1.12/en/zend.soap.autodiscovery.html具有不同的 WSDL 绑定样式。

像这样的东西:

服务器.php:

<?php

error_reporting(E_ALL);
ini_set('display_errors', 1);

set_include_path(get_include_path().';./library/;./library/Zend');

require_once 'Zend/Loader/Autoloader.php';

$autoloader = Zend_Loader_Autoloader::getInstance();
$autoloader->setFallbackAutoloader(true);

/* Helper class for my response object */
class CheckVersionResult extends stdClass
{
    /** @var bool */
    public $ValidationOk = '';
    /** @var string */
    public $VersionNumber = '';
    /** @var string */
    public $CurrentRemoteServerTime = '';
}

/* SOAP interface class */
class MySoapClass
{
    /**
     * Returns version
     *
     * @param string $param1
     * @param string $param2
     * @return CheckVersionResult
     */
    public function CheckVersion($param1, $param2)
    {
        $data = new CheckVersionResult();
        $data->ValidationOk = 1;
        $data->VersionNumber = '1.4.0';
        $data->CurrentRemoteServerTime = date('Y-m-d\TH:i:s');

        return $data;
    }
}

$mySoapClass = new MySoapClass();


if(isset($_GET['wsdl'])) {
    $autodiscover = new Zend_Soap_AutoDiscover();
    $autodiscover->setClass('MySoapClass');

    $autodiscover->setOperationBodyStyle(
    array('use' => 'literal',
          'namespace' => 'http://localhost/stack/23537231/server.php')
    );

    $autodiscover->setBindingStyle(
        array('style' => 'document',
          'transport' => 'http://localhost/stack/23537231/server.php')
    );

    $autodiscover->handle();
} else {
    // pointing to the current file here
    $soap = new Zend_Soap_Server("http://localhost/stack/23537231/server.php?wsdl", array(
        'cache_wsdl'=> WSDL_CACHE_NONE,
        'classmap'  => array(
            'CheckVersionResult'=>'CheckVersionResult',
        )

    ));
    $soap->setClass('MySoapClass');
    $soap->handle();
}

客户端.php

<?php

error_reporting(E_ALL);
ini_set('display_errors', 1);

set_include_path(get_include_path().';./library/;./library/Zend');

require_once 'Zend/Loader/Autoloader.php';

$autoloader = Zend_Loader_Autoloader::getInstance();
$autoloader->setFallbackAutoloader(true);

/* Helper class for my response object */
class CheckVersionResult extends stdClass
{
    /** @var bool */
    public $ValidationOk = '';
    /** @var string */
    public $VersionNumber = '';
    /** @var string */
    public $CurrentRemoteServerTime = '';
}

$client = new SoapClient('http://localhost/stack/23537231/server.php?wsdl', array(
        "trace" => 1, // enable trace to view what is happening
        "exceptions" => 1, // disable exceptions
        "cache_wsdl" => WSDL_CACHE_NONE,
        'classmap'  => array(
            'CheckVersionResult'=>'CheckVersionResult',
        ))   // no wsdl
);

$ret = $client->CheckVersion('param1', 'param2');
header('Content-Type: application/xml; charset=utf-8');

echo $client->__getLastResponse();
die();

有了这个我有这个:

<SOAP-ENV:Envelope SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
  <SOAP-ENV:Body>
    <ns1:CheckVersionResponse>
      <return xsi:type="ns1:CheckVersionResult">
        <ValidationOk xsi:type="xsd:boolean">true</ValidationOk>
        <VersionNumber xsi:type="xsd:string">1.4.0</VersionNumber>
        <CurrentRemoteServerTime xsi:type="xsd:string">2014-05-19T22:22:59</CurrentRemoteServerTime>
      </return>
    </ns1:CheckVersionResponse>
  </SOAP-ENV:Body>
</SOAP-ENV:Envelope>

旁注:我认为您的回复是有效的肥皂回复。因此,如果客户端是有效的肥皂客户端,它应该能够解析响应并仍然使用它。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

PHP Soap Server 响应格式 的相关文章

  • 有没有办法在 Windows 上全局安装 Composer?

    我读过全局安装文档 http getcomposer org doc 00 intro md globally对于 Composer 但仅适用于 nix 系统 curl s https getcomposer org installer p
  • 此集合实例 Laravel 关系中不存在属性 [X]

    我在 Laravel 5 6 中使用了很多 Realtions 当我添加 phonebooks 时 我看到所有关系都工作正常 一切都很好 但是当我尝试在视图中显示它们时 我得到了属性在此集合上不存在的错误 这是关系代码 public fun
  • 作为数据流写入 div

    考虑写入 div 的 AJAX 调用 recent req post result php d data function returnData content html returnData PHP 脚本位于result php执行一些需
  • 如何使用 PHP 调整缩略图大小时提高图像质量?

    我在网上找到了这个脚本 它可以从图像中创建缩略图 但创建的缩略图质量很差 如何提高图像的质量 有没有更好的方法来创建缩略图 如果有的话 您能给我指点一下如何使用 PHP 创建缩略图的教程吗 这是下面的代码
  • 在 PHP $_SESSION 中存储数据不安全吗?

    根据我的理解 PHP 进程的行为并不像应用程序服务器进程 因此 执行脚本后 PHP 进程不会保留任何用户特定数据 相反 它将它们存储在用户的 cookie 中 所以无论我们存储在什么地方 SESSSION进入cookie 这是真的 如果是
  • dompdf 在文档末尾插入空白页

    我正在使用 dompdf 0 6 0 生成 pdf 文档 并且遇到一个奇怪的问题 即最后创建了一个空白页面 我的 简化的 html
  • PHP shell_exec 使用 ssh 运行 shell 脚本

    我有一个 shell 脚本 使用 ssh 和密钥连接到另一台机器 因此它不需要用户名和密码 当我从命令行运行这个脚本时 它工作正常 但是当我从 php shell exec 运行这个脚本时 它不起作用 如果我与 PHP 建立 ssh 连接并
  • 撇号 php 问题

    我正在做一项涉及喊话箱的学校作业 一个很棒的教程 它使用 jquery ajax mysql 和 php 现在我遇到了以下句子的一个小问题 result li strong row user strong img src alt row m
  • 如何从 php 代码更改 php 设置?

    我想更改 php 设置 但从 php 页面而不是 php ini 更改 我要更改的设置是 upload max filesize post max size and memory limit 如果您有AllowOverride 选项 您可以
  • 从边界框确定文本坐标 a 的正确方法是什么?

    鉴于调用的结果imagettfbbox https www php net manual en function imagettfbbox php 什么是正确的 像素完美的点提供给imagettftext https www php net
  • 使用 PKCS1 生成私钥 RSA

    有没有办法在 PHP 中通过 OpenSSL 生成私钥openssl pkey 新 http php net manual en function openssl pkey new php在 RSA 和 PKCS1 中 如果您的意思是带有
  • Doctrine 生成实体命名空间问题?

    好吧 我对原则有最后一个问题 生成 实体命令 我运行以下命令 并得到预期的文件 src MyNamespace Bundle MyNamespaceBundle Resources config doctrine metadata orm
  • 在 Spring 中设置 WS https 调用超时 (HttpsUrlConnectionMessageSender)

    我正在尝试为 WS 调用设置超时 我延长了WebServiceGatewaySupport并尝试将发送者超时设置为如下 public Object marshalSendAndReceive Object requestPayload We
  • 使用 Python 解析 XML,解析外部 ENTITY 引用

    在我的 S1000D xml 中 它指定了一个带有对公共 URL 的引用的 DOCTYPE 该 URL 包含对包含所有有效字符实体的许多其他文件的引用 我使用 xml etree ElementTree 和 lxml 尝试解析它并得到解析错
  • PHP使用正则表达式查找字符串

    我已经阅读了多个有关正则表达式的教程 但它只是不会留在我的脑海中 我永远无法让我的模式发挥作用 希望有人能帮忙 我有一个 php 变量 content 我需要在其中找到如下所示的特定模式 图库 名称 文件夹 我想搜索 starting wi
  • 如何在WCF Rest服务中从流上传图像

    我正在尝试创建 wcf 服务 该服务将上传 pdf doc xls 图像等文件 但 pdf txt 文件正在上传并正确打开 但是当我尝试上传图像文件时 文件正在上传 但是图像不可见 OperationContract WebInvoke M
  • 如何测试“If-Modified-Since”HTTP 标头支持

    使用 PHP 如何准确测试远程网站supports If Modified Since HTTP 标头 据我所知 如果您获取的远程文件自标头请求中指定的日期以来已被修改 它应该返回 200 OK 状态 如果尚未修改 则应返回 304 Not
  • 在仅包含键的字符串的嵌套数组中查找值

    我有一个数组 其中包含一些设置 基本上如下所示 defaults array variable gt value thearray gt array foo gt bar myvar gt array morevars gt moreval
  • jQuery - xpath 查找?

    如果您在 xml 中有下面的 xml 那么您会使用以下命令变得昏昏欲睡 xml find animal find dog find beagle text jQuery 中是否有类似的方法来使用 xpath xml xpathfind an
  • 是否需要使用fetch_object或fetch_array?

    我最近发现我可以打印数据库中的结果而不使用mysqli fetch object功能 例如 假设我们有一个简单的 sql select 语句 可以使用如下所示的语句来执行 conn mysqli connect localhost root

随机推荐