SOAP faultcode env:使用SOAPClientSaaj的客户端

时间:2016-07-06 06:53:02

标签: java xml soap soapui

我有一个xml,当遇到一个区域(URL)我得到以下XML作为回复,可以请任何人建议为什么会发生这种情况, 如果我使用SOAPUI手动执行相同的xml,它执行正常,抛出我的Java代码错误。

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Body>
  <soapenv:Fault xmlns:en="http://schemas.xmlsoap.org/soap/envelope/">
     <faultcode>en:Client</faultcode>
     <faultstring>The service provider does not support requested service</faultstring>
  </soapenv:Fault>
</soapenv:Body>
</soapenv:Envelope>

我的java代码是: -

public class SOAPClientSAAJ {
    public static void main(String args[]) throws SOAPException, IOException {

    // Create SOAP Connection
    SOAPConnectionFactory soapConnectionFactory = SOAPConnectionFactory
            .newInstance();
    SOAPConnection soapConnection = soapConnectionFactory
            .createConnection();

    // Send SOAP Message to SOAP Server
    String url = "SOME URL";
    SOAPMessage soapRq = readSoapMessage("C:\\1.1.1.xml");
    SOAPMessage soapResponse = soapConnection.call(soapRq, url);

    // print SOAP Response
    System.out.print("Response SOAP Message:" + "\n");
    soapResponse.writeTo(System.out);

    soapConnection.close();
}

public static SOAPMessage readSoapMessage(String filename)
        throws SOAPException, FileNotFoundException {
    SOAPMessage message = MessageFactory.newInstance().createMessage();
    SOAPPart soapPart = message.getSOAPPart();
    soapPart.setContent(new StreamSource(new FileInputStream(filename)));
    message.saveChanges();
    return message;
}
}

谢谢

0 个答案:

没有答案