谁能给我各例子看看,非常感谢
13 个解决方案
#1
//发送xml
private void sendTypeStatus(String uri, Document doc) {
HttpClient httpClient = new DefaultHttpClient();
try {
HttpPost httpost = new HttpPost(uri);
StringEntity se = new StringEntity(doc.asXML());
httpost.setEntity(se);
httpClient.execute(httpost);//这里获得一个返回的entity可以拿到流然后用saxreader解析就可以了,我是用dom4j和httpclient4做的,用java自带的也可以做,只不过麻烦点
} catch (Exception e) {
e.printStackTrace();
} finally {
httpClient.getConnectionManager().shutdown();
}
}
#2
呃,能提供一个服务端的例子吗,最主要是服务端的,非常感谢
#3
Document doc = new SAXReader().read(request.getInputStream());//接受xml
#4
发送就是上面那个就可以了
#5
这个好像太简单了一点,能详细一点吗?
这个request对象从哪里来?
#6
...http环境里,写个servlet就能拿到request的啊
#7
呃。。。还有别的什么方法吗
#8
//发送xml
private void sendTypeStatus(String uriwww.cctv40.com, Document doc) {
HttpClient httpClient = new DefaultHttpClient();
try {
HttpPost httpost = new HttpPost(uri);
StringEntity se = new StringEntity(doc.asXML());
httpost.setEntity(se);
httpClient.execute(httpost);//这里获得一个返回的entity可以拿到流然后用saxreader解析就可以了,我是用dom4j和httpclient4做的,用java自带的也可以做,只不过麻烦点
} catch (Exception e) {
e.printStackTrace();
} finally {
httpClient.getConnectionManager().shutdown();
}
}
这个可以??????????
private void sendTypeStatus(String uriwww.cctv40.com, Document doc) {
HttpClient httpClient = new DefaultHttpClient();
try {
HttpPost httpost = new HttpPost(uri);
StringEntity se = new StringEntity(doc.asXML());
httpost.setEntity(se);
httpClient.execute(httpost);//这里获得一个返回的entity可以拿到流然后用saxreader解析就可以了,我是用dom4j和httpclient4做的,用java自带的也可以做,只不过麻烦点
} catch (Exception e) {
e.printStackTrace();
} finally {
httpClient.getConnectionManager().shutdown();
}
}
这个可以??????????
#9
方法
web.xml
客户端
这是最简单的一个axis例子! 有不懂的问我 QQ303579750
package com.test;
public class HelloWorld {
public String sayHello(String name)
{
return "Hello! "+name;
}
}
web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
<listener>
<listener-class>
org.apache.axis.transport.http.AxisHTTPSessionListener
</listener-class>
</listener>
<servlet>
<display-name>Apache-Axis Servlet</display-name>
<servlet-name>AxisServlet</servlet-name>
<servlet-class>
org.apache.axis.transport.http.AxisServlet
</servlet-class>
</servlet>
<servlet>
<display-name>Axis Admin Servlet</display-name>
<servlet-name>AdminServlet</servlet-name>
<servlet-class>
org.apache.axis.transport.http.AdminServlet
</servlet-class>
<load-on-startup>100</load-on-startup>
</servlet>
<servlet>
<display-name>SOAPMonitorService</display-name>
<servlet-name>SOAPMonitorService</servlet-name>
<servlet-class>
org.apache.axis.monitor.SOAPMonitorService
</servlet-class>
<init-param>
<param-name>SOAPMonitorPort</param-name>
<param-value>5001</param-value>
</init-param>
<load-on-startup>100</load-on-startup>
</servlet>
<!-- Axis Webservice Servlet mapping -->
<servlet-mapping>
<servlet-name>AxisServlet</servlet-name>
<url-pattern>/servlet/AxisServlet</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>AxisServlet</servlet-name>
<url-pattern>/services/*</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>SOAPMonitorService</servlet-name>
<url-pattern>/SOAPMonitor</url-pattern>
</servlet-mapping>
<mime-mapping>
<extension>wsdl</extension>
<mime-type>text/xml</mime-type>
</mime-mapping>
<mime-mapping>
<extension>xsd</extension>
<mime-type>text/xml</mime-type>
</mime-mapping>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
</web-app>
客户端
package dao;
public interface IDao {
public String sayHello(String name);
}
package dao;
import java.net.MalformedURLException;
import java.rmi.RemoteException;
import javax.xml.rpc.ParameterMode;
import javax.xml.rpc.ServiceException;
import org.apache.axis.client.Call;
import org.apache.axis.client.Service;
import org.apache.axis.encoding.XMLType;
public class test {
public static void main(String[] args) throws ServiceException, MalformedURLException, RemoteException {
String endpoint = "http://192.168.2.159:8080/demo/services/HelloWorld";
String nameString="wuxy";
Service service = new Service();
Call call = (Call) service.createCall();
call.setTargetEndpointAddress(new java.net.URL(endpoint));
call.setOperationName("sayHello");
call.addParameter("nameString", XMLType.XSD_STRING, ParameterMode.IN);
call.setReturnType(XMLType.XSD_STRING);
String ret = (String) call.invoke(new Object[] {nameString});
System.out.println("Got result : " + ret);
}
}
这是最简单的一个axis例子! 有不懂的问我 QQ303579750
#10
感谢kevinPai2011大篇幅的代码,但我们这边协议要求用http post的方式,所以客户端服务端都不能采用WEBSERVICE的方式。
是我开始提问没说清楚,再一次表示感谢,我会给你分的^_^。
是我开始提问没说清楚,再一次表示感谢,我会给你分的^_^。
#11
恶心的web service
#12
在http接口中:
BufferedReader bufferedReader = new BufferedReader(
new InputStreamReader( (ServletInputStream)request.getInputStream(),"utf-8"));
StringBuffer stringBuffer =new StringBuffer("");
String temp;
while((temp=bufferedReader.readLine())!=null){
stringBuffer.append(temp);
}
bufferedReader.close();
String xml = stringBuffer.toString();
System.out.printlm("原始请求串:"+xml);
#13
百度httpclient发送xml
dom4j解析xml你的问题就解决了
#1
//发送xml
private void sendTypeStatus(String uri, Document doc) {
HttpClient httpClient = new DefaultHttpClient();
try {
HttpPost httpost = new HttpPost(uri);
StringEntity se = new StringEntity(doc.asXML());
httpost.setEntity(se);
httpClient.execute(httpost);//这里获得一个返回的entity可以拿到流然后用saxreader解析就可以了,我是用dom4j和httpclient4做的,用java自带的也可以做,只不过麻烦点
} catch (Exception e) {
e.printStackTrace();
} finally {
httpClient.getConnectionManager().shutdown();
}
}
#2
呃,能提供一个服务端的例子吗,最主要是服务端的,非常感谢
#3
Document doc = new SAXReader().read(request.getInputStream());//接受xml
#4
发送就是上面那个就可以了
#5
这个好像太简单了一点,能详细一点吗?
这个request对象从哪里来?
#6
...http环境里,写个servlet就能拿到request的啊
#7
呃。。。还有别的什么方法吗
#8
//发送xml
private void sendTypeStatus(String uriwww.cctv40.com, Document doc) {
HttpClient httpClient = new DefaultHttpClient();
try {
HttpPost httpost = new HttpPost(uri);
StringEntity se = new StringEntity(doc.asXML());
httpost.setEntity(se);
httpClient.execute(httpost);//这里获得一个返回的entity可以拿到流然后用saxreader解析就可以了,我是用dom4j和httpclient4做的,用java自带的也可以做,只不过麻烦点
} catch (Exception e) {
e.printStackTrace();
} finally {
httpClient.getConnectionManager().shutdown();
}
}
这个可以??????????
private void sendTypeStatus(String uriwww.cctv40.com, Document doc) {
HttpClient httpClient = new DefaultHttpClient();
try {
HttpPost httpost = new HttpPost(uri);
StringEntity se = new StringEntity(doc.asXML());
httpost.setEntity(se);
httpClient.execute(httpost);//这里获得一个返回的entity可以拿到流然后用saxreader解析就可以了,我是用dom4j和httpclient4做的,用java自带的也可以做,只不过麻烦点
} catch (Exception e) {
e.printStackTrace();
} finally {
httpClient.getConnectionManager().shutdown();
}
}
这个可以??????????
#9
方法
web.xml
客户端
这是最简单的一个axis例子! 有不懂的问我 QQ303579750
package com.test;
public class HelloWorld {
public String sayHello(String name)
{
return "Hello! "+name;
}
}
web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
<listener>
<listener-class>
org.apache.axis.transport.http.AxisHTTPSessionListener
</listener-class>
</listener>
<servlet>
<display-name>Apache-Axis Servlet</display-name>
<servlet-name>AxisServlet</servlet-name>
<servlet-class>
org.apache.axis.transport.http.AxisServlet
</servlet-class>
</servlet>
<servlet>
<display-name>Axis Admin Servlet</display-name>
<servlet-name>AdminServlet</servlet-name>
<servlet-class>
org.apache.axis.transport.http.AdminServlet
</servlet-class>
<load-on-startup>100</load-on-startup>
</servlet>
<servlet>
<display-name>SOAPMonitorService</display-name>
<servlet-name>SOAPMonitorService</servlet-name>
<servlet-class>
org.apache.axis.monitor.SOAPMonitorService
</servlet-class>
<init-param>
<param-name>SOAPMonitorPort</param-name>
<param-value>5001</param-value>
</init-param>
<load-on-startup>100</load-on-startup>
</servlet>
<!-- Axis Webservice Servlet mapping -->
<servlet-mapping>
<servlet-name>AxisServlet</servlet-name>
<url-pattern>/servlet/AxisServlet</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>AxisServlet</servlet-name>
<url-pattern>/services/*</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>SOAPMonitorService</servlet-name>
<url-pattern>/SOAPMonitor</url-pattern>
</servlet-mapping>
<mime-mapping>
<extension>wsdl</extension>
<mime-type>text/xml</mime-type>
</mime-mapping>
<mime-mapping>
<extension>xsd</extension>
<mime-type>text/xml</mime-type>
</mime-mapping>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
</web-app>
客户端
package dao;
public interface IDao {
public String sayHello(String name);
}
package dao;
import java.net.MalformedURLException;
import java.rmi.RemoteException;
import javax.xml.rpc.ParameterMode;
import javax.xml.rpc.ServiceException;
import org.apache.axis.client.Call;
import org.apache.axis.client.Service;
import org.apache.axis.encoding.XMLType;
public class test {
public static void main(String[] args) throws ServiceException, MalformedURLException, RemoteException {
String endpoint = "http://192.168.2.159:8080/demo/services/HelloWorld";
String nameString="wuxy";
Service service = new Service();
Call call = (Call) service.createCall();
call.setTargetEndpointAddress(new java.net.URL(endpoint));
call.setOperationName("sayHello");
call.addParameter("nameString", XMLType.XSD_STRING, ParameterMode.IN);
call.setReturnType(XMLType.XSD_STRING);
String ret = (String) call.invoke(new Object[] {nameString});
System.out.println("Got result : " + ret);
}
}
这是最简单的一个axis例子! 有不懂的问我 QQ303579750
#10
感谢kevinPai2011大篇幅的代码,但我们这边协议要求用http post的方式,所以客户端服务端都不能采用WEBSERVICE的方式。
是我开始提问没说清楚,再一次表示感谢,我会给你分的^_^。
是我开始提问没说清楚,再一次表示感谢,我会给你分的^_^。
#11
恶心的web service
#12
在http接口中:
BufferedReader bufferedReader = new BufferedReader(
new InputStreamReader( (ServletInputStream)request.getInputStream(),"utf-8"));
StringBuffer stringBuffer =new StringBuffer("");
String temp;
while((temp=bufferedReader.readLine())!=null){
stringBuffer.append(temp);
}
bufferedReader.close();
String xml = stringBuffer.toString();
System.out.printlm("原始请求串:"+xml);
#13
百度httpclient发送xml
dom4j解析xml你的问题就解决了