douqulv6059 2012-01-08 13:21 采纳率: 0%
浏览 42

解析数组作为php soap服务器的输入

I have fallen into a PHP hole that I can't seem to google myself out of. I have a PHP soap server where one function takes an array of int as input. How do I parse it properly?

When the input is one int, it works. When it is an array, it parses the string 'Array'.

The server is run on my Synology NAS. I've been trying to find some kind of PHP log where the soap server could scream its potential parsing problems, but I have not found any such log.

This is my simplified server:

<?php
if(!extension_loaded("soap")){
 dl("php_soap.dll");
}

ini_set("soap.wsdl_cache_enabled","0");
$server = new SoapServer("input_array_debug.wsdl");

function createProduct($content_refs){
    $debugVar = "outside";

foreach ($content_refs as $reference) {
            $debugVar = "inside";
    error_log("Item:'".$reference."'
 ", 3, "/var/tmp/my-errors.log");
            $debugVar = "after";
}   
return $debugVar;
}

$server->AddFunction("createProduct");
$server->handle();

This is my WSDL:

    <?xml version="1.0"?>
<definitions 
name="FoodContent" 
targetNamespace="urn:FoodContent" 
xmlns:tns="urn:FoodContent"  
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" 
xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" 
xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" 
xmlns="http://schemas.xmlsoap.org/wsdl/">
  <types>
    <xsd:schema xmlns="http://www.w3.org/2001/XMLSchema" targetNamespace="urn:FoodContent">
      <xsd:complexType name="ArrayOfInt">
        <xsd:sequence>
          <xsd:element minOccurs="1" maxOccurs="unbounded" name="reference" type="xsd:int" />
        </xsd:sequence>
      </xsd:complexType>          
    </xsd:schema>   
  </types>

  <message name="createProduct">
    <part name="content_refs" type="tns:ArrayOfInt" />
  </message> 
  <message name="createProductResponse">
    <part name="reference" type="xsd:string" />
  </message>   

  <portType name="FoodContentPort">
    <operation name="createProduct">
      <input message="tns:createProduct" />
      <output message="tns:createProductResponse" />
    </operation>
  </portType>

  <binding name="FoodContentBinding" type="tns:FoodContentPort">
    <soap:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http" />
      <operation name="createProduct">
        <soap:operation soapAction="urn:FoodContentAction" />
        <input>
          <soap:body use="encoded" namespace="urn:FoodContent" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" />       
        </input>
        <output>
          <soap:body use="encoded" namespace="urn:FoodContent" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" />       
        </output>
      </operation>        
  </binding>

  <service name="FoodContentService">
    <port name="FoodContentPort" binding="tns:FoodContentBinding">
      <soap:address location="http://other.eu:8888/FoodContents/Debug_server.php" />
    </port>
  </service>          
</definitions>

The base of the soap request is generated and sent from soapUI 4.0.1:

    <soapenv:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:urn="urn:FoodContent">
   <soapenv:Header/>
   <soapenv:Body>
      <urn:createProduct soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
         <content_refs xsi:type="urn:ArrayOfInt">
            <!--1 or more repetitions:-->
            <reference xsi:type="xsd:int">3</reference>
            <reference xsi:type="xsd:int">7</reference>
         </content_refs>
      </urn:createProduct>
   </soapenv:Body>
</soapenv:Envelope>

The response looks OK

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥17 pro*C预编译“闪回查询”报错SCN不能识别
    • ¥15 微信会员卡接入微信支付商户号收款
    • ¥15 如何获取烟草零售终端数据
    • ¥15 数学建模招标中位数问题
    • ¥15 phython路径名过长报错 不知道什么问题
    • ¥15 深度学习中模型转换该怎么实现
    • ¥15 HLs设计手写数字识别程序编译通不过
    • ¥15 Stata外部命令安装问题求帮助!
    • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
    • ¥15 TYPCE母转母,插入认方向