都知道webservice 底层也是用http通信的 ,但是怎么把底部通信的报文打印出来也是我们调试接口时最方便最快捷的方式.
这些只适用于用工具生成的代理类.亲测java jdk生成的代理类好使.也称JAX-WS.
下面代码
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.net.ServerSocket;
import java.net.Socket;
public class Server {
ServerSocket ss;
Socket serverSocket;
InputStream inStream;
OutputStream outStream;
public Server() {
try {
System.out.println("====================Server==================");
ss = new ServerSocket(80);
serverSocket = ss.accept();
System.out
.println("--------------some guest connected----------------");
inStream = serverSocket.getInputStream();
outStream = serverSocket.getOutputStream();
} catch (Exception e) {
e.printStackTrace();
}
}
public void conn() {
new Thread() {
public void run() {
try {
InputStreamReader iReader = new InputStreamReader(inStream);
BufferedReader iBufferStream = new BufferedReader(iReader);
String line = null;
while ((line = iBufferStream.readLine()) != null) {
System.out.println(line);
}
} catch (IOException e) {
e.printStackTrace();
}
}
}.start();
}
public static void main(String args[]) {
Server server = new Server();
server.conn();
}
}
上面代码是监听端口,比如你的webservice是发送到9001端口的,就要把80改成9001了.
其次是要改webservice wsdl 地址,先把wsdl下载下来.放到内部项目中.然后改代理类中的服务类地址.记得 有的webservice接口提供方说明 必须用域名,那时候 你就要改你的host配置了 ,配置个映射,如下图.