我有一个使用远程 SOAP 服务的 SOAP 客户端。连接和设置一切正常。当我发送 SOAP 请求时,我收到 SOAP 故障消息,如下所示:
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<soap:Fault>
<faultcode>soap:Server</faultcode>
<faultstring>Index: 0, Size: 0</faultstring>
</soap:Fault>
</soap:Body>
</soap:Envelope>
现在我真的很难理解这样的错误消息。事实上,我知道请求信封一切正常。谁能帮我理解这个错误。
这是 SOAP 请求信封:
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<ns2:createRequest xmlns:ns2="http://request.services.xyz.com/">
<hid>1234</hid>
<requestTypeCode>APPOINT_REQ</requestTypeCode>
<createdBy>testuser</createdBy>
<assignedTo>testuser</assignedTo>
<data>
<dataField>
<name>ContentText</name>
<value xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xs="http://www.w3.org/2001/XMLSchema" xsi:type="xs:string">Test!</value>
</dataField>
<dataField>
<name>Date</name>
<value xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xs="http://www.w3.org/2001/XMLSchema" xsi:type="xs:dateTime">2013-12-09T13:28:34.009-05:00</value>
</dataField>
<dataField>
<name>OrderNumber</name>
<value xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xs="http://www.w3.org/2001/XMLSchema" xsi:type="xs:string">1-123432</value>
</dataField>
</data>
<originAppCode>ABCD</originAppCode>
</ns2:createRequest>
</soap:Body>
</soap:Envelope>
这是我尝试通过 SOAP 请求调用的方法签名。
public @XmlElement(name="Request")Request createRequest( @WebParam(name="hid")int hid, @WebParam(name="requestTypeCode")String requestTypeCode, @WebParam(name="createdBy")String createdBy,
@WebParam(name="assignedTo")String assignedTo, @WebParam(name="createTime")Date createTime, @WebParam(name="data")DataFields data, @WebParam(name="originAppCode") String originAppCode) throws Exception;
这是 wsdl 的部分:
<wsdl:definitions xmlns:ns1="http://cxf.apache.org/bindings/xformat" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:tns="http://request.services.xyz.com/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" name="requestServiceImplService" targetNamespace="http://request.services.xyz.com/">
<wsdl:types>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" targetNamespace="http://jaxb.dev.java.net/array" version="1.0">
<xs:complexType final="#all" name="stringArray">
<xs:sequence>
<xs:element maxOccurs="unbounded" minOccurs="0" name="item" nillable="true" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:schema>
<xs:schema xmlns:tns="http://request.services.xyz.com/" xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="unqualified" targetNamespace="http://request.services.xyz.com/" version="1.0">
<xs:element name="createRequest" type="tns:createRequest"/>
<xs:element name="createRequestResponse" type="tns:createRequestResponse"/>
<xs:element name="dataFields" type="tns:dataFields"/>
<xs:complexType name="createRequest">
<xs:sequence>
<xs:element name="hid" type="xs:int"/>
<xs:element minOccurs="0" name="requestTypeCode" type="xs:string"/>
<xs:element minOccurs="0" name="createdBy" type="xs:string"/>
<xs:element minOccurs="0" name="assignedTo" type="xs:string"/>
<xs:element minOccurs="0" name="createTime" type="xs:dateTime"/>
<xs:element minOccurs="0" name="data" type="tns:dataFields"/>
<xs:element minOccurs="0" name="originAppCode" type="xs:string"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="createRequestResponse">
<xs:sequence>
<xs:element minOccurs="0" name="return" type="tns:request"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="dataFields">
<xs:sequence>
<xs:element maxOccurs="unbounded" minOccurs="0" name="dataField" type="tns:dataField"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="dataField">
<xs:sequence>
<xs:element name="name" type="xs:string"/>
<xs:element name="value" type="xs:anyType"/>
</xs:sequence>
</xs:complexType>
</xs:schema>
</wsdl:types>
<wsdl:message name="createRequest">
<wsdl:part element="tns:createRequest" name="parameters"></wsdl:part>
</wsdl:message>
<wsdl:message name="createRequestResponse">
<wsdl:part element="tns:createRequestResponse" name="parameters"></wsdl:part>
</wsdl:message>
<wsdl:operation name="createRequest">
<wsdl:input message="tns:createRequest" name="createRequest"></wsdl:input>
<wsdl:output message="tns:createRequestResponse" name="createRequestResponse"> </wsdl:output>
</wsdl:operation>
<wsdl:binding name="RequestServiceImplServiceSoapBinding" type="tns:IRequestService">
<soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
<wsdl:operation name="createRequest">
<soap:operation soapAction="" style="document"/>
<wsdl:input name="createRequest">
<soap:body use="literal"/>
</wsdl:input>
<wsdl:output name="createRequestResponse">
<soap:body use="literal"/>
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
<wsdl:service name="RequestServiceImplService">
<wsdl:port binding="tns:RequestServiceImplServiceSoapBinding" name="RequestServiceImplPort">
<soap:address location="location_where_service_is_being_hosted/cxf/jaxws/RequestService"/>
</wsdl:port>
</wsdl:service>
</wsdl:definitions>
最佳答案
类似 Index: 0, Size: 0
的消息通常是由 IndexOutOfBoundsException
引起的s。
在您的情况下,这可能意味着:
- 请求为空。
- 请求的编码错误。
- 安全机制不会让您的请求通过。
- 有一个
IndexOutOfBoundsException
在后端。
后续步骤:
检查您的服务器是否接受来自 SoapUI 的请求.
- 您可以完全控制请求,因此如果出现问题,可能是后端出现错误。
- 如果有效,则表明您的客户端存在问题。检查您的客户发送的请求。完成了吗?是否包含不可读的字符?
结果:使用 SoapUI 时也会出现该错误。
XML/XML 架构
XML 和 XML Schema 中的一些东西引起了我的注意。
- 仅在请求中
createRequest
使用命名空间。其他元素没有命名空间,因为它们没有指定命名空间前缀。使用<createRequest xmlns="http://request.services.xyz.com/">
将为createRequest
下面的所有元素分配默认命名空间. - (在 XML 模式中,尽管只有
type="tns:dataFields"
,但有对dataField
的引用。另外,createRequest
是小写,而在请求中它是用驼峰式大小写编写的。我认为两者都不是真正的问题,因为你更改了 StackOverflow 的名称。)
服务器错误
由于不可能发送服务器接受的任何请求(即使使用 SoapUI 也不行),因此您肯定必须调试服务器。
- 日志中是否有任何错误消息?
- 异常发生在哪里?在
java.lang.Exception
设置断点并缩小范围,直到找到问题。
关于java - 获取 SOAP :Fault while consuming a soap service,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20500275/