java webservice soap消息请求例子
来源:互联网 发布:二级ms office软件 编辑:程序博客网 时间:2024/06/07 17:38
接口返回来的xml字符串jkdata.xml
<?xml version="1.0" encoding="UTF-8"?>
<DataTable xmlns="http://sys.cdxinyong.com">
<xs:schema id="NewDataSet" xmlns="" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xs:element name="NewDataSet" msdata:IsDataSet="true" msdata:MainDataTable="Table" msdata:UseCurrentLocale="true">
<xs:complexType>
<xs:choice minOccurs="0" maxOccurs="unbounded">
<xs:element name="Table">
<xs:complexType>
<xs:sequence>
<xs:element name="Id" type="xs:int" minOccurs="0" />
<xs:element name="GUID" type="xs:string" minOccurs="0" />
<xs:element name="GName" type="xs:string" minOccurs="0" />
<xs:element name="BId" type="xs:int" minOccurs="0" />
<xs:element name="LastDate" type="xs:string" minOccurs="0" />
<xs:element name="Status" type="xs:unsignedByte" minOccurs="0" />
<xs:element name="StatusDis" type="xs:string" minOccurs="0" />
<xs:element name="BiaoDuanName" type="xs:string" minOccurs="0" />
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:choice>
</xs:complexType>
</xs:element>
</xs:schema>
<diffgr:diffgram xmlns:msdata="urn:schemas-microsoft-com:xml-msdata" xmlns:diffgr="urn:schemas-microsoft-com:xml-diffgram-v1">
<NewDataSet xmlns="">
<Table diffgr:id="Table1" msdata:rowOrder="0">
<Id>166</Id>
<GUID>1002000100000000000000001014100</GUID>
<GName>皇冠国际社区四期总图幼儿园大门</GName>
<BId>7814</BId>
<LastDate>2013-03-11</LastDate>
<Status>1</Status>
<StatusDis>在线</StatusDis>
<BiaoDuanName>皇冠国际社区四期总图、幼儿园</BiaoDuanName>
</Table>
<Table diffgr:id="Table2" msdata:rowOrder="1">
<Id>167</Id>
<GUID>1002000100000000000000001014101</GUID>
<GName>皇冠国际社区四期总图刷卡机</GName>
<BId>0</BId>
<LastDate>2013-03-11</LastDate>
<Status>1</Status>
<StatusDis>在线</StatusDis>
</Table>
</NewDataSet>
</diffgr:diffgram>
</DataTable>
package com.cdmcs.jksp.client.update;
import org.dom4j.Document;
import org.dom4j.DocumentException;
import org.dom4j.DocumentHelper;
import org.dom4j.Element;
import org.dom4j.VisitorSupport;
public class SurveyServiceUtil extends VisitorSupport{
private String GName;
public String getGName() {
return GName;
}
public void setGName(String name) {
GName = name;
}
public void visit(Element node) {
if ("GName".equals(node.getName())) {
this.setGName(node.getText());
try{
System.out.println("GName==="+new String(node.getText().getBytes("iso8859-1"),"gbk"));
}catch(Exception e){
e.printStackTrace();
}
} else{
}
}
public void analysis(String soapContent) throws DocumentException {
Document doc = (Document) DocumentHelper.parseText(soapContent);
doc.accept(this);
}
}
package com.cdmcs.jksp.client.update;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.HttpException;
import org.apache.commons.httpclient.methods.InputStreamRequestEntity;
import org.apache.commons.httpclient.methods.PostMethod;
import org.apache.commons.httpclient.methods.RequestEntity;
public class Test {
/**
* @param args
*/
public static void main(String[] args) throws HttpException, IOException {
String soapRequestData = "<?xml version=\"1.0\" encoding=\"utf-8\"?>";
soapRequestData += "<soap12:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:soap12=\"http://www.w3.org/2003/05/soap-envelope\">";
soapRequestData += "<soap12:Body>";
soapRequestData += "<GetVideos xmlns=\"http://sys.cdxinyong.com\" />";
soapRequestData += "</soap12:Body>";
soapRequestData += "</soap12:Envelope>";
System.out.println(soapRequestData);
PostMethod postMethod = new PostMethod("http://localhost/jkdata.xml");
postMethod.setRequestHeader("Content-Type", "text/xml; charset=UTF-8");
byte[] b = soapRequestData.getBytes("utf-8");
InputStream is = new ByteArrayInputStream(b,0,b.length);
RequestEntity re = new InputStreamRequestEntity(is,b.length,"application/soap + xml; charset=utf-8");
postMethod.setRequestEntity(re);
HttpClient httpClient = new HttpClient();
int statusCode = httpClient.executeMethod(postMethod);
System.out.println("statuscode=" + statusCode);
String soapResponseData = postMethod.getResponseBodyAsString();
//System.out.println("soapResponseData=" + soapResponseData);
SurveyServiceUtil util = new SurveyServiceUtil();
try{
util.analysis(soapResponseData);
}catch(Exception e){
e.printStackTrace();
}
}
}
解决解析时的编码问题:
PostMethod postMethod = new PostMethod("http://www.tvsou.com/program/TV_54/Channel_166/W3.htm");
postMethod.setRequestHeader("Content-Type", "text/xml; charset=gb2312");
postMethod.getParams().setParameter(HttpMethodParams.HTTP_CONTENT_CHARSET,"gb2312");
postMethod.setRequestHeader("Content-Type", "text/xml; charset=gb2312");
postMethod.getParams().setParameter(HttpMethodParams.HTTP_CONTENT_CHARSET,"gb2312");
0 0
- java webservice soap消息请求例子
- java 请求响应soap(webService)
- [Python]webservice学习(2) --自己写soap消息请求服务
- webservice 之 soap 消息
- webservice 之 soap 消息
- 抓取Webservice Soap请求
- Android Soap请求webService
- java 调用.net webservice 带soap验证头消息方式
- Java发布一个简单 webservice应用 并发送SOAP请求
- cxf 发送 soap 请求(webService)
- WebService (二) PHP soap 请求
- Retrofit框架请求SOAP WebService
- Retrofit框架请求SOAP WebService
- JAVA 备忘录【webservice】 soap
- WebService大讲堂之Axis2(10):使用soapmonitor模块监视soap请求与响应消息
- WebService大讲堂之Axis2(10):使用soapmonitor模块监视soap请求与响应消息
- WebService大讲堂之Axis2(10):使用soapmonitor模块监视soap请求与响应消息 (zhuan)
- WebService大讲堂之Axis2(10):使用soapmonitor模块监视soap请求与响应消息
- 知识库--Reloader interface(47)
- sql语句 查询表中 每门课都大于80分的学生名称 根据以下三种 学习sql 中其他函数的使用
- Scala 的 yield 例子 (for 循环和 yield 的例子)
- 正则表达式中的基本正则规则详解01
- 【C#】39. 前台线程与后台线程
- java webservice soap消息请求例子
- ESP8266移植MQTT连接中移ONENET
- 10个经典的Java main方法面试题
- Collection
- 关于iptables
- http协议中的get和post
- 九宫格项目一
- 结合Dot语言和工具graphviz来画图
- ListIterator