使用JAVA调用.NET写的WEB SERVICES(急!) 调用Web Service的时候,你接收到的是通过HTTP信道传过来的一个XML格式的字符序列,自己用XML解析器可以把它解析成一份XML文档(当然还有别的更方便的工具),哪里会有什么对象类型的? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 to Schlemiel: 但是如何使用java调用呢?例子有吗? 完全没问题,记得和另一公司webservice with C#合作时用java调用是这样写的RecDocument是自己封闭的Document你就想成Dom吧 /** * 公共对外的接口 * @param doc * @param endpoint * @param soapAction * @return 是否发送成功 */ public static boolean recDocumentWS(RecDocument doc, String endpoint, String soapAction) { boolean ret = false; SOAPMessage msg = new SOAPMessage(); Document d = SOAPUtils.getDocument(doc); msg.setDocument(d); msg.setSoapAction(soapAction); try { SOAPMessage retmsg = HTTPUtils.post(new URL(endpoint), msg); Document respDoc = retmsg.getDoc(); Element payload = null; if (respDoc != null) { payload = respDoc.getDocumentElement(); String ret2 = payload.getElementsByTagName("RecDocumentResult").item(0).getFirstChild().getNodeValue(); if (ret2.equalsIgnoreCase("true")) ret = true; } else { throw new SOAPException(HttpConstants.FAULT_CODE_CLIENT, "Parsing error for the return content:" + retmsg.getStringMsg()); } } catch (IllegalArgumentException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } catch (SOAPException e) { e.printStackTrace(); } catch (SAXException e) { e.printStackTrace(); } return ret; }实际写时就那样 Call call = new Call(); Parameter param = new Parameter("caller", caller.getClass(), caller, Constants.NS_URI_SOAP_ENC); call.setTargetObjectURI(uri); call.setMethodName(remoteMethod); call.setParams(new Vector(Arrays.asList(new Parameter[] { param }))); Response resp = call.invoke(new URL(url), "");而且如果你用其它方式如URL返回也是个XML DOM你也可以自己解析 完全没问题,记得和另一公司webservice with C#合作时用java调用是这样写的RecDocument是自己封闭的Document你就想成Dom吧 /** * 公共对外的接口 * @param doc * @param endpoint * @param soapAction * @return 是否发送成功 */ public static boolean recDocumentWS(RecDocument doc, String endpoint, String soapAction) { boolean ret = false; SOAPMessage msg = new SOAPMessage(); Document d = SOAPUtils.getDocument(doc); msg.setDocument(d); msg.setSoapAction(soapAction); try { SOAPMessage retmsg = HTTPUtils.post(new URL(endpoint), msg); Document respDoc = retmsg.getDoc(); Element payload = null; if (respDoc != null) { payload = respDoc.getDocumentElement(); String ret2 = payload.getElementsByTagName("RecDocumentResult").item(0).getFirstChild().getNodeValue(); if (ret2.equalsIgnoreCase("true")) ret = true; } else { throw new SOAPException(HttpConstants.FAULT_CODE_CLIENT, "Parsing error for the return content:" + retmsg.getStringMsg()); } } catch (IllegalArgumentException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } catch (SOAPException e) { e.printStackTrace(); } catch (SAXException e) { e.printStackTrace(); } return ret; }实际写时就那样 Call call = new Call(); Parameter param = new Parameter("caller", caller.getClass(), caller, Constants.NS_URI_SOAP_ENC); call.setTargetObjectURI(uri); call.setMethodName(remoteMethod); call.setParams(new Vector(Arrays.asList(new Parameter[] { param }))); Response resp = call.invoke(new URL(url), "");而且如果你用其它方式如URL返回也是个XML DOM你也可以自己解析 有谁知道中国气象网的天气预报的接口? Java怎么获得点击网页时的超链接代码 求助 配置了jsp环境后,我的电脑访问很多网站都是乱码,就连www.gov.cn都是,未解决! 求助:javax.xml.rpc.server 不存在,应该复制哪个jar阿? ####生成随机不重复数的问题 关于java类文件读取 的问题 weblogic7配置连接池问题 获取父页面对象 Java如何将html转换成word 将XML转化为HTML的一个问题 使用JDOM 输出xml文档的一个问题
但是如何使用java调用呢?例子有吗?
用java调用是这样写的
RecDocument是自己封闭的Document你就想成Dom吧 /**
* 公共对外的接口
* @param doc
* @param endpoint
* @param soapAction
* @return 是否发送成功
*/
public static boolean recDocumentWS(RecDocument doc, String endpoint, String soapAction) {
boolean ret = false;
SOAPMessage msg = new SOAPMessage();
Document d = SOAPUtils.getDocument(doc);
msg.setDocument(d); msg.setSoapAction(soapAction);
try { SOAPMessage retmsg = HTTPUtils.post(new URL(endpoint), msg);
Document respDoc = retmsg.getDoc();
Element payload = null;
if (respDoc != null) {
payload = respDoc.getDocumentElement();
String ret2 = payload.getElementsByTagName("RecDocumentResult").item(0).getFirstChild().getNodeValue();
if (ret2.equalsIgnoreCase("true")) ret = true;
} else {
throw new SOAPException(HttpConstants.FAULT_CODE_CLIENT,
"Parsing error for the return content:" + retmsg.getStringMsg());
}
} catch (IllegalArgumentException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (SOAPException e) {
e.printStackTrace();
} catch (SAXException e) {
e.printStackTrace();
}
return ret;
}实际写时就那样
Call call = new Call();
Parameter param = new Parameter("caller", caller.getClass(), caller,
Constants.NS_URI_SOAP_ENC); call.setTargetObjectURI(uri);
call.setMethodName(remoteMethod);
call.setParams(new Vector(Arrays.asList(new Parameter[] {
param
}))); Response resp = call.invoke(new URL(url), "");而且如果你用其它方式如URL返回也是个XML DOM你也可以自己解析
用java调用是这样写的
RecDocument是自己封闭的Document你就想成Dom吧 /**
* 公共对外的接口
* @param doc
* @param endpoint
* @param soapAction
* @return 是否发送成功
*/
public static boolean recDocumentWS(RecDocument doc, String endpoint, String soapAction) {
boolean ret = false;
SOAPMessage msg = new SOAPMessage();
Document d = SOAPUtils.getDocument(doc);
msg.setDocument(d); msg.setSoapAction(soapAction);
try { SOAPMessage retmsg = HTTPUtils.post(new URL(endpoint), msg);
Document respDoc = retmsg.getDoc();
Element payload = null;
if (respDoc != null) {
payload = respDoc.getDocumentElement();
String ret2 = payload.getElementsByTagName("RecDocumentResult").item(0).getFirstChild().getNodeValue();
if (ret2.equalsIgnoreCase("true")) ret = true;
} else {
throw new SOAPException(HttpConstants.FAULT_CODE_CLIENT,
"Parsing error for the return content:" + retmsg.getStringMsg());
}
} catch (IllegalArgumentException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (SOAPException e) {
e.printStackTrace();
} catch (SAXException e) {
e.printStackTrace();
}
return ret;
}实际写时就那样
Call call = new Call();
Parameter param = new Parameter("caller", caller.getClass(), caller,
Constants.NS_URI_SOAP_ENC); call.setTargetObjectURI(uri);
call.setMethodName(remoteMethod);
call.setParams(new Vector(Arrays.asList(new Parameter[] {
param
}))); Response resp = call.invoke(new URL(url), "");而且如果你用其它方式如URL返回也是个XML DOM你也可以自己解析