简体   繁体   English

PHP SoapServer和复杂类型

[英]PHP SoapServer and Complex Types

I am working on building a web service in PHP using the SoapServer class, but I'm running into an issue with casting of complex types. 我正在使用SoapServer类在PHP中构建Web服务,但是我遇到了转换复杂类型的问题。

The WSDL is completely valid, and the PHP SoapClient handles it flawlessly, but there seems to be an issue with the complex types that are returned not being cast properly. WSDL是完全有效的,PHP SoapClient可以完美地对其进行处理,但是返回的复杂类型似乎存在问题,这些类型返回的类型不正确。 This came to light when consuming the service in .Net, as I was getting exceptions that indicated the type was not present in the given namespace. 当使用.Net中的服务时,这一点很明显,因为我遇到了异常,该异常表明类型在给定的命名空间中不存在。

I mangled my function numerous times, changing the namespace on the element, but .Net continues to give me errors, regardless of what namespace I use. 我多次修改了函数,更改了元素上的命名空间,但是.Net仍然给我错误,无论我使用什么命名空间。

Consider the following abbreviation of the script: 请考虑以下脚本缩写:

function getCommands() {
    $output = array();
    // ...
    foreach($result as $row) {
        $output[] = new SoapVar($row, SOAP_ENC_OBJECT, 'ns1:command');
    }

    return $output;
}

The abbreviated response: 缩写的响应:

<?xml version="1.0" encoding="utf-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
    xmlns:ns1="urn:MyWebService"
    xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/"
    xmlns:xsd="http://www.w3.org/2001/XMLSchema"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
  <SOAP-ENV:Body>
    <ns1:getCommandsResponse>
      <return SOAP-ENC:arrayType="ns1:command[12]" xsi:type="ns1:ArrayOfCommand">
        <item xsi:type="ns1:command">
            <!-- ... -->
        </item>
      <!-- ... -->
      </return>
    </ns1:getCommandsResponse>
  </SOAP-ENV:Body>
</SOAP-ENV:Envelope>

What I've noticed is that xmlns:ns1 is defined by way of the WSDL, and it does match the namespace in the WSDL. 我注意到的是xmlns:ns1是通过WSDL定义的,并且确实与WSDL中的名称空间匹配。 However, the .Net SOAP client doesn't seem to understand that the command element is defined there. 但是,.Net SOAP客户端似乎不了解在此定义了command元素。 It does, however, understand that that's where ArrayOfCommand is defined. 但是,它确实知道那是定义ArrayOfCommand的地方。

So my question is multipart: 所以我的问题是多方面的:

  1. Is this a known bug with the SoapServer? 这是SoapServer的已知错误吗?
  2. If not, am I missing something grievous in my WSDL? 如果不是,我在WSDL中是否缺少一些严重的问题?
  3. Am I not encoding my objects properly? 我没有正确编码对象吗?
  4. Is this an issue with .Net? .Net是否有问题? If so, what's the work-around? 如果是这样,有什么解决方法?

I was able to resolve this issue by working over the <types/> section of my WSDL again, using the Google WSDL for reference. 通过使用Google WSDL作为参考,再次研究WSDL的<types/>部分,可以解决此问题。 Then, I had to work some magic in my PHP function, casting the elements of the $command appropriate to their respective types in the WSDL, and encoding the entire command as a ns2:command . 然后,我必须在PHP函数中发挥一些魔术作用,将$command的元素转换为适合WSDL中它们各自类型的元素,然后将整个命令编码为ns2:command When aligned with the WSDL, this all fell together nicely and .Net is having zero difficulty with it. 当与WSDL保持一致时,所有这些都很好地融合在一起,.Net的使用难度为零。

I'm surprised nobody in the development community was willing to answer this, but I hope someone will be able to glean from it at least some direction on how to fix their own instance of this problem. 我感到惊讶的是,开发社区中没有人愿意回答这个问题,但是我希望有人能够从中获得至少一些指导,以解决自己的问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM