How can I pass in an array as a value into a PHP soapclient request?
如何将数组作为值传入PHP soapclient请求?
I have a soapclient instantiated and connected already. I then try to make a call to a webservice method that expects 3 parameters (string, string, hashmap).
我已经实例化并连接了一个soapclient。然后我尝试调用一个需要3个参数(string,string,hashmap)的webservice方法。
Here is what I expected to work below. But when viewing the xml output, the params node is empty.
以下是我期望在下面工作的内容。但是在查看xml输出时,params节点为空。
soapclient->doSomething(array('id' => 'blah', 'page' => 'blah', 'params' => array('email' => 'test@test.com', 'password' => 'password', 'blah' => 'blah')));
The soap body xml ends up like this (note the empty params element):
soap body xml就像这样结束(注意空params元素):
<SOAP-ENV:Body><ns1:doSomething>
<id>blah</id>
<page>blah</page>
<params/>
</ns1:register></SOAP-ENV:Body>
2 个解决方案
#1
3
For JAX-WS webservices it may be a problem with the hashmap input parameter. The xsd schema generated seems to be incorrect for hashmaps. Placing the map in a wrapper object causes JAX-WS to output the correct xsd.
对于JAX-WS webservices,它可能是hashmap输入参数的问题。生成的xsd架构似乎对于散列图不正确。将映射放在包装器对象中会导致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
}
Then the php code will succeed. I found I didn't need SoapVar or SoapParam and could not get either of those methods to work without the MapWrapper.
然后PHP代码将成功。我发现我不需要SoapVar或SoapParam,并且在没有MapWrapper的情况下无法使这些方法中的任何一个工作。
$entry1['key'] = 'somekey';
$entry1['value'] = 1;
$params['map'] = array($entry1);
soapclient->doSomething(array('id' => 'blah', 'page' => 'blah',
'params' => $params));
Here is the correct xsd generated with the wrapper
这是使用包装器生成的正确xsd
<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>
Here is the incorrect schema generated by JAX-WS with just the hashmap
这是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>
One last note. Wrapping HashMap<String, String> worked with this solution, but HashMap<String, Object> did not. The Object gets mapped to xsd:anyType which comes into the java webservice as a xsd schema object rather than just Object.
最后一点。包装HashMap
#2
0
Depending on the webservice definition, the hashmap parameter might need to have a specific structure/encoding that can not be directly created from an array. You might want to check the WSDL on that, and take a look into the SoapVar and the SoapParam classes for more options on Soap parameter construction.
根据webservice定义,hashmap参数可能需要具有无法从数组直接创建的特定结构/编码。您可能想要检查WSDL,并查看SoapVar和SoapParam类以获取有关Soap参数构造的更多选项。
#1
3
For JAX-WS webservices it may be a problem with the hashmap input parameter. The xsd schema generated seems to be incorrect for hashmaps. Placing the map in a wrapper object causes JAX-WS to output the correct xsd.
对于JAX-WS webservices,它可能是hashmap输入参数的问题。生成的xsd架构似乎对于散列图不正确。将映射放在包装器对象中会导致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
}
Then the php code will succeed. I found I didn't need SoapVar or SoapParam and could not get either of those methods to work without the MapWrapper.
然后PHP代码将成功。我发现我不需要SoapVar或SoapParam,并且在没有MapWrapper的情况下无法使这些方法中的任何一个工作。
$entry1['key'] = 'somekey';
$entry1['value'] = 1;
$params['map'] = array($entry1);
soapclient->doSomething(array('id' => 'blah', 'page' => 'blah',
'params' => $params));
Here is the correct xsd generated with the wrapper
这是使用包装器生成的正确xsd
<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>
Here is the incorrect schema generated by JAX-WS with just the hashmap
这是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>
One last note. Wrapping HashMap<String, String> worked with this solution, but HashMap<String, Object> did not. The Object gets mapped to xsd:anyType which comes into the java webservice as a xsd schema object rather than just Object.
最后一点。包装HashMap
#2
0
Depending on the webservice definition, the hashmap parameter might need to have a specific structure/encoding that can not be directly created from an array. You might want to check the WSDL on that, and take a look into the SoapVar and the SoapParam classes for more options on Soap parameter construction.
根据webservice定义,hashmap参数可能需要具有无法从数组直接创建的特定结构/编码。您可能想要检查WSDL,并查看SoapVar和SoapParam类以获取有关Soap参数构造的更多选项。