对于 JAX-WS Web 服务,可能是 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
}
然后php代码就会成功。我发现我不需要 SoapVar 或 SoapParam,而且如果没有 MapWrapper,这些方法中的任何一个都无法工作。
$entry1['key'] = 'somekey';
$entry1['value'] = 1;
$params['map'] = array($entry1);
soapclient->doSomething(array('id' => 'blah', 'page' => 'blah',
'params' => $params));
这是使用包装器生成的正确 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>
这是 JAX-WS 仅使用哈希图生成的不正确模式
<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<String, String> 与此解决方案一起使用,但 HashMap<String, Object> 没有。对象被映射到 xsd:anyType,它作为 xsd 模式对象而不仅仅是对象进入 java web 服务。