我正在处理使用 RPC/编码的 WSDL 文件将 Web 服务连接到我的 Java/Spring 服务的问题。我无法更改此 WSDL。
我发现我必须使用 Apache Axis 1.4 来创建客户端(根据这个问题:https ://dzone.com/articles/wsdltojava-error-rpcencoded )。
然后我在登录/密码/api_key 参数上遇到了这样的消息:
<message name="login_message">
<part name="login" type="xsd:string"/>
<part name="password" type="xsd:string"/>
<part name="api_key" type="xsd:int"/>
</message>
错误Element 'api_key': '' is not a valid value of the atomic type 'xs:int'
我通过添加解决了这个问题:
webapi_locator.getEngine().setOption("sendMultiRefs", Boolean.FALSE);
现在我可以登录并从该服务中获取一些数据,但我无法推送带有空参数的消息,例如:
<message name="add_offer_input">
<part name="session" type="xsd:string"/>
<part name="category_id" type="xsd:int"/>
<part name="offer" type="tns:offer"/>
</message>
其中报价定义为:
<xsd:complexType name="offer">
<xsd:all>
<xsd:element name="price" type="xsd:float" minOccurs="0" maxOccurs="1"/>
<xsd:element name="price_m2" type="xsd:int" minOccurs="0" maxOccurs="1"/>
[...]
</xsd:all>
</xsd:complexType>
现在我遇到了这样的异常:
org.apache.axis.AxisFault: Wrong parameters input xml
Element 'price': '' is not a valid value of the atomic type 'xs:int'. line: 1 column: 0'
at org.apache.axis.message.SOAPFaultBuilder.createFault(SOAPFaultBuilder.java:222) ~[axis-1.4.jar:na]
我已经尝试过设置
elemField.setNillable(false);
至
elemField.setNillable(true);
在 Offer.java 中。
我正在通过以下方式创建优惠消息:
Offer offer = new Offer(null,null);
我将非常感谢找到解决此错误的方法。我不需要坚持使用轴 1.4 - 任何其他让我通过 SOAP 连接到此服务的解决方案对我有用。非常感谢您的帮助!