首页 文章

如何在SOAP响应中发送纯XML?

提问于
浏览
5

我正在使用PHP SoapServer类,并尝试将纯XML放在SOAP响应的主体中 .

Case 1:

我的WSDL有

<element name="getDataResponse" type="xsd:string"/>

我编码响应

return new SoapVar($my_xml,XSD_ANYXML)

PHP SoapClient说

SOAP-ERROR: Encoding: Violation of encoding rules

Case 2:

WSDL

<element name="getDataResponse" type="xsd:string"/>

响应编码

return new SoapVar($my_xml,XSD_STRING)

响应XML全部<编码为&lt;和> as&gt;

Case 3:

WDSL

<element name="getDataResponse">
  <complexType>
   ... 
  </complexType>
</element>

其中complexType对应要返回的XML结构

响应编码

return new SoapVar($my_xml,XSD_ANYXML)

现在返回类型是一个对象,而不是XML字符串

Case 4

除了编码为SOAP_ENC_OBJECT之外,与案例3相同 . 结果将是对象 .

请帮忙!我怎样才能将纯XML文本作为SOAP响应的主体?

1 回答

  • 5

    你试过这个吗?

    return new SoapVar(
         '<ns1:xmlDocument>'.$my_xml.'</ns1:xmlDocument>',
         XSD_ANYXML
    );
    

    还有其他解决方案at this PHP page . (见'User Contributed Notes'部分)

相关问题