Java Apache CXF JAX-WS客户端错误:无法识别消息部分
我使用ApacheCXF编写了一个Web服务。当使用SoapUI进行测试时,它工作良好。我编写了一个Java客户端来调用webservice,但它失败了,出现以下错误: org.apache.cxf.interceptor.Fault:未识别消息部分客户。(它是否存在于服务WSDL中?) 客户机程序从xml文件读取数据,并将其作为文档添加到SOAPBody中 以下是SoapUI中的输入数据:Java Apache CXF JAX-WS客户端错误:无法识别消息部分,java,apache,web-services,soap,wsdl,Java,Apache,Web Services,Soap,Wsdl,我使用ApacheCXF编写了一个Web服务。当使用SoapUI进行测试时,它工作良好。我编写了一个Java客户端来调用webservice,但它失败了,出现以下错误: org.apache.cxf.interceptor.Fault:未识别消息部分客户。(它是否存在于服务WSDL中?) 客户机程序从xml文件读取数据,并将其作为文档添加到SOAPBody中 以下是SoapUI中的输入数据: <soapenv:Envelope xmlns:soapenv="http://schemas.x
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:app="ApplyLoanRequest">
<soapenv:Header/>
<soapenv:Body>
<app:customer>
<contact>
<!--1 to 2 repetitions:-->
<name part="first">J</name>
<name part="last">H</name>
<country>US</country>
</contact>
</app:customer>
</soapenv:Body>
</soapenv:Envelope>
即使我将URL更改为指向wsdl,也会得到相同的错误
URL endpoint = new URL("http://localhost:8080/bankloan/services/applyloan?wsdl");
有没有发现这个问题?没有。咨询过六位Java专家,但无法解决。我的一位同事解决了我们遇到的问题。似乎他们必须将wsdl下载到一个文件中,然后我们就不再遇到这个问题了。我们使用的是非标准的java soap客户端。有没有发现这个问题?没有。与六位java专家进行了检查,但无法解决。我的一位同事解决了我们遇到的问题。似乎他们必须将wsdl下载到一个文件中,然后我们就不再遇到这个问题了。不过,我们使用的是非标准的JavaSOAP客户端。
public class BankLoanClient
{
public Document convertXMLFileToDocument(String pathToFile) throws Exception
{
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
factory.setNamespaceAware(true);
DocumentBuilder builder = factory.newDocumentBuilder();
Document doc = builder.parse(pathToFile);
return doc;
}
public static void main(String[] args) throws Exception
{
System.out.println("Starting BankLoan Client ... ");
SOAPMessage message = MessageFactory.newInstance().createMessage();
SOAPBody body = message.getSOAPBody();
SOAPPart part = message.getSOAPPart();
SOAPEnvelope envelope = part.getEnvelope();
envelope.addNamespaceDeclaration("app", "ApplyLoanRequest");
body.addDocument(new BankLoanClient().convertXMLFileToDocument(args[0]));
System.out.println("Service request ... ");
System.out.println("====================================");
message.writeTo(System.out);
System.out.println();
URL endpoint = new URL("http://localhost:8080/bankloan/services/applyloan");
SOAPConnectionFactory factory = SOAPConnectionFactory.newInstance();
SOAPConnection connection = factory.createConnection();
SOAPMessage response = connection.call(message, endpoint);
connection.close();
// Process the response message
SOAPBody respBody = response.getSOAPBody();
Iterator it = respBody.getChildElements();
SOAPBodyElement element = (SOAPBodyElement) it.next();
System.out.println("Service response ... ");
System.out.println("====================================");
System.out.println(element.getNodeName());
it = element.getChildElements();
SOAPElement ret = (SOAPElement) it.next();
System.out.println(ret.getNodeName() + " = " + ret.getTextContent());
}
}
URL endpoint = new URL("http://localhost:8080/bankloan/services/applyloan?wsdl");