我有以下代码
final String METHOD="test";
final String PARAM1_VAL="Hello";
final String TARGET_EPR="http://bhanuka-TECRA-M11:8280/services/SoapToRestProxy";
SOAPFactory factory = OMAbstractFactory.getSOAP11Factory();
OMNamespace samplesNamespace = factory.createOMNamespace("http://services.samples/xsd", "m");
SOAPEnvelope envelope = factory.getDefaultEnvelope();
OMElement requestElement = factory.createOMElement("request", samplesNamespace);
OMElement methodElement = factory.createOMElement("method",samplesNamespace);
OMElement param1 = factory.createOMElement("val",samplesNamespace);
param1.setText(PARAM1_VAL);
methodElement.setText(METHOD);
requestElement.addChild(methodElement);
requestElement.addChild(param1);
envelope.getBody().addChild(requestElement);
try {
ServiceClient serviceClient = new ServiceClient();
Options options = new Options();
options.setTo(new EndpointReference(TARGET_EPR));
serviceClient.setOptions(options);
OMElement response = serviceClient.sendReceive(envelope);
System.out.println(response);
} catch (AxisFault axisFault) {
axisFault.printStackTrace();
}
我正在做的是制作一个SOAP信封并将其发送到特定的端点。但是在sendReceive
方法中,它会抛出一个
javax.xml.stream.XMLStreamException:无法输出XML声明, 其他输出完成后。
我在做什么错了?有人请帮助我。