2010-02-25 111 views
1

如何将数组作为值传入PHP soapclient请求中?如何将数组作为值传入PHP soapclient请求?

我有一个soapclient已经实例化和连接。然后我尝试调用一个需要3个参数(string,string,hashmap)的webservice方法。

这是我期望在下面的工作。但是当查看xml输出时,params节点是空的。

soapclient->doSomething(array('id' => 'blah', 'page' => 'blah', 'params' => array('email' => '[email protected]', 'password' => 'password', 'blah' => 'blah'))); 

SOAP主体XML这样结束了(注意空params元素):

<SOAP-ENV:Body><ns1:doSomething> 
<id>blah</id> 
<page>blah</page> 
<params/> 
</ns1:register></SOAP-ENV:Body> 

回答

0

根据Web服务定义,HashMap的参数可能需要具有特定结构/编码能不能直接从数组创建。您可能想要检查WSDL,并查看SoapVarSoapParam类,以获取有关Soap参数构造的更多选项。

2

对于JAX-WS webservices,它可能是散列表输入参数的问题。生成的xsd模式似乎对hashmaps不正确。将映射放置在包装器对象中会导致JAX-WS输出正确的xsd。

public class MapWrapper { 
    public HashMap<String, String> map; 
} 


// in your web service class 
@WebMethod(operationName = "doSomething") 
public SomeResponseObject doSomething(
     @WebParam(name = "id") String id, 
     @WebParam(name = "page") String page, 
     @WebParam(name = "params") MapWrapper params { 
    // body of method 
} 

然后php代码就会成功。我发现我不需要SoapVar或SoapParam,并且无法使这两种方法在没有MapWrapper的情况下工作。

$entry1['key'] = 'somekey'; 
$entry1['value'] = 1; 
$params['map'] = array($entry1); 
soapclient->doSomething(array('id' => 'blah', 'page' => 'blah', 
    'params' => $params)); 

这里是与包装物

<xs:complexType name="mapWrapper"> 
    <xs:sequence> 
    <xs:element name="map"> 
     <xs:complexType> 
     <xs:sequence> 
      <xs:element name="entry" minOccurs="0" maxOccurs="unbounded"> 
      <xs:complexType> 
       <xs:sequence> 
       <xs:element name="key" minOccurs="0" type="xs:string"/> 
       <xs:element name="value" minOccurs="0" type="xs:string"/> 
       </xs:sequence> 
      </xs:complexType> 
      </xs:element> 
     </xs:sequence> 
     </xs:complexType> 
    </xs:element> 
    </xs:sequence> 
</xs:complexType> 

生成正确的XSD这里是JAX-WS只HashMap的最后

<xs:complexType name="hashMap"> 
    <xs:complexContent> 
    <xs:extension base="tns:abstractMap"> 
     <xs:sequence/> 
    </xs:extension> 
    </xs:complexContent> 
</xs:complexType> 
<xs:complexType name="abstractMap" abstract="true"> 
    <xs:sequence/> 
</xs:complexType> 

一个音符所产生的不正确的架构。包装HashMap <字符串,字符串>与此解决方案一起工作,但HashMap <字符串,对象>没有。 Object被映射为xsd:anyType,它作为xsd模式对象而不是Object来进入java webservice。