【问题标题】:How can I add urn to SoapClient on PHP?如何在 PHP 上将 urn 添加到 SoapClient?
【发布时间】:2012-04-29 08:25:47
【问题描述】:

我有这个由 SoapUI 从this wsdl 生成的 xml:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:urn="urn:safetypay:mws:api:messages">
   <soapenv:Header/>
   <soapenv:Body>
      <urn:CommunicationTestRequest>
         <urn:ApiKey>?</urn:ApiKey>
         <urn:RequestDateTime>?</urn:RequestDateTime>
         <urn:Signature>?</urn:Signature>
      </urn:CommunicationTestRequest>
   </soapenv:Body>
</soapenv:Envelope>

它工作正常,但是当我使用 PHP 客户端 SoapClient 创建它时,它失败了......我发现错误是因为它略有不同,它只是缺少骨灰盒(我不知道这是什么)。 SoapClient 的 xml 如下所示:

<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
    <SOAP-ENV:Body>
        <CommunicationTestRequest>
            <RequestDateTime>2012-04-17T23:21:54</RequestDateTime>
            <ApiKey>XXXXX</ApiKey>
            <Signature>XXXXX</Signature>
        </CommunicationTestRequest>
    </SOAP-ENV:Body>
</SOAP-ENV:Envelope>

三个主要区别是: 1)在定义中,SoapClient 生成的代码缺少这个: xmlns:urn="urn:safetypay:mws:api:messages" 2)在SoapUI生成的xml中,我有soapenv,而在SoapClient生成的xml中,它是SOAP-ENV 3) 在 SoapUI 中,我在每个孩子之前都有瓮,SoapClient 没有。

我几乎一整天都在更改配置并从对象向后移动到数组(因为过去它与其他 wsdl 一起使用),而我在互联网上的研究并没有给我任何帮助......所以...... . 谁能知道我的错误是什么?

请求是这样的:

$std = new RequestDateTime();
$std->RequestDateTime = date ( 'Y-m-d\TH:i:s', time () );
$std->ApiKey = SafetyPaySoap::API_KEY_SAND;
$std->Signature = SafetyPaySoap::SIG_KEY_SAND;
$this->_wsdl->CommunicationTest($std);

SoapClient 的配置在哪里

$config = array ();
$config ['exceptions'] = true;
$config ['trace'] = true;
$config ['cache_wsdl'] = WSDL_CACHE_NONE;
$config ['soap_version'] = SOAP_1_1;
parent::SoapClient ( $url . '?wsdl', $config );

编辑: 我能够修复这个错误。我不得不重写 __doRequest 方法。现在看起来像这样:

public function __doRequest($request, $location, $action, $version, $one_way = null) {
    $request = str_ireplace("<{$this->_method}Request>", "<{$this->_method}Request xmlns='urn:safetypay:mws:api:messages'>", $request);
    return parent::__doRequest ( $request, $location, $action, $version, $one_way );
}

所以,我正在做的是在请求中添加命名空间,然后它会生成这个 xml:

<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
    <SOAP-ENV:Body>
        <CommunicationTestRequest xmlns='urn:safetypay:mws:api:messages'>
            <ApiKey>XXXX</ApiKey>
            <RequestDateTime>2012-04-18T20:22:51</RequestDateTime>
            <Signature>XXXXX</Signature>
        </CommunicationTestRequest>
    </SOAP-ENV:Body>
</SOAP-ENV:Envelope>

【问题讨论】:

    标签: php web-services soap namespaces wsdl


    【解决方案1】:

    urn: 实际上是一个 XML 命名空间。查看 SoapClient 的文档,它看起来像是在目标命名空间中作为配置数组中的“uri”条目传递。可能值得尝试以下方法,看看是否有所作为。

    $config = array();
    $config['uri'] = "urn:safetypay:mws:api:messages";
    // your other configurations
    parent::SoapClient('https://mws2.safetypay.com/sandbox/express/ws/v.2.4/MerchantWS.asmx?wsdl', $config);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-12-28
      • 1970-01-01
      • 2015-09-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多