怎么用xfire调用别人的一个webservice接口
1个回答
展开全部
构建SOAP文件可以使用JAVA底层提供的支持类。
Java代橡配码
public SOAPMessage createMessage(String target, String... values) {
try {
MessageFactory mf = MessageFactory.newInstance();
SOAPMessage msg = mf.createMessage();
SOAPPart sp = msg.getSOAPPart();
SOAPEnvelope envelope = sp.getEnvelope();
SOAPBody body = envelope.getBody();
SOAPElement node2 = body
.addChildElement(new QName(
"http://www.w3.org/2001/XMLSchema-instance",
target, "ns1"));
for (int i = 0; i < values.length; i++) {
String value = values[i];
node2.addChildElement("param" + i).addTextNode(value);
}
msg.writeTo(System.err);
msg.saveChanges();
return msg;
} catch (Exception e) {
e.printStackTrace();
return null;// 一般要进行错误处理,这渣态里梁梁指省略
}
}
Java代橡配码
public SOAPMessage createMessage(String target, String... values) {
try {
MessageFactory mf = MessageFactory.newInstance();
SOAPMessage msg = mf.createMessage();
SOAPPart sp = msg.getSOAPPart();
SOAPEnvelope envelope = sp.getEnvelope();
SOAPBody body = envelope.getBody();
SOAPElement node2 = body
.addChildElement(new QName(
"http://www.w3.org/2001/XMLSchema-instance",
target, "ns1"));
for (int i = 0; i < values.length; i++) {
String value = values[i];
node2.addChildElement("param" + i).addTextNode(value);
}
msg.writeTo(System.err);
msg.saveChanges();
return msg;
} catch (Exception e) {
e.printStackTrace();
return null;// 一般要进行错误处理,这渣态里梁梁指省略
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询