我怎么能传递一个数组作为值插入到PHP SoapClient的要求? [英] How can I pass in an array as a value into a PHP soapclient request?
问题描述
我怎么能传递一个数组作为值插入到PHP SoapClient的请求?
我有一个SoapClient的实例化并已连接。然后我尽量让给需要3个参数(字符串,字符串,HashMap中)。
一个Web服务方法的调用下面是我的预期之下工作。但在查看XML输出时,该节点PARAMS是空的。
soapclient-> DoSomething的(阵列('ID'=>'嗒嗒','网页'=>'嗒嗒','参数'=>阵列('电子邮件'=>'test@test.com','密码'=>'密码','嗒嗒'=>'胡说')));
SOAP体的XML最终像这样(注意空params元素):
< SOAP-ENV:身体与GT;< NS1:DoSomething的>
<&ID GT;等等< / ID>
<网页>等等< /页>
< PARAMS />
< / NS1:注册>< / SOAP-ENV:身体与GT;
有关JAX-WS Web服务则可能是HashMap的输入参数的问题。生成的XSD架构似乎是不正确的包含HashMap。放置在地图中的一个包装对象会导致JAX-WS输出正确的XSD。
公共类MapWrapper {
公众的HashMap<字符串,字符串>地图;
}
//在你的web服务类
@WebMethod(operationName =DoSomething的)
公共SomeResponseObject DoSomething的(
@WebParam(NAME =ID)串ID,
@WebParam(NAME =页)字符串页,
@WebParam(NAME =PARAMS)MapWrapper PARAMS {
//方法体
}
那么php code会成功。我发现我并不需要SoapVar或SoapParam并不能得到任何这些方法没有MapWrapper工作。
$取值范['关键'] ='somekey';
$取值范['值'] = 1;
$ PARAMS ['地图'] =阵列($取值范);
soapclient-> DoSomething的(阵列('ID'=>'嗒嗒','网页'=>'嗒嗒',
'参数'=> $ params)方法);
下面是与包装物产生正确的XSD
< XS:复杂类型名称=mapWrapper>
< XS:序列>
< XS:元素的名称=地图>
< XS:复杂类型>
< XS:序列>
&所述; XS:元素名称=条目的minOccurs =0maxOccurs为=无限>
< XS:复杂类型>
< XS:序列>
< XS:元素的名称=键的minOccurs =0类型=XS:字符串/>
< XS:元素的名称=值的minOccurs =0类型=XS:字符串/>
< / XS:序列>
< / XS:复杂类型>
< / XS:组件>
< / XS:序列>
< / XS:复杂类型>
< / XS:组件>
< / XS:序列>
< / XS:复杂类型>
下面是JAX-WS只HashMap中产生的不正确的架构
< XS:复杂类型名称=HashMap的>
< XS:复杂内容>
< XS:扩展基板=TNS:abstractMap>
< XS:序列/>
< / XS:扩展>
< / XS:复杂内容>
< / XS:复杂类型>
< XS:复杂类型名称=abstractMap抽象=真>
< XS:序列/>
< / XS:复杂类型>
最后一个音符。包装的HashMap<字符串,字符串>这个解决方案的工作,但HashMap的<弦乐,对象>没有。该对象被映射为xsd:这涉及到Java Web服务作为XSD架构对象,而不是对象anyType的
How can I pass in an array as a value into a PHP soapclient request?
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).
Here is what I expected to work below. But when viewing the xml output, the params node is empty.
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-ENV:Body><ns1:doSomething>
<id>blah</id>
<page>blah</page>
<params/>
</ns1:register></SOAP-ENV:Body>
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.
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.
$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
<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
<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.
这篇关于我怎么能传递一个数组作为值插入到PHP SoapClient的要求?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!