WebSrvice简单客户端:
-----------------------------
package com.huawei.mds;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.net.Socket;
import java.net.UnknownHostException;
public class WSClient implements Runnable
{
private StringBuffer buffer;
public WSClient(StringBuffer buffer)
{
this.buffer = buffer;
}
public static void main(String[] args)
{
try
{
// input = new FileInputStream("sendMsg.xml");
InputStream input = new FileInputStream("sendMsg_for_unsub.xml");
StringBuffer buffer = new StringBuffer();
int inread = input.read();
while (inread != -1)
{
buffer.append((char) inread);
inread = input.read();
}
for (int i = 0; i < 1; i++)
{
new Thread(new WSClient(buffer)).start();
}
}
catch (UnknownHostException e)
{
e.printStackTrace();
}
catch (IOException e)
{
e.printStackTrace();
}
}
public void run()
{
try
{
long begin = System.currentTimeMillis();
for (int i = 0; i < 1; i++)
{
Socket socket = new Socket("10.37.89.154", 8688);
PrintWriter writer = new PrintWriter(socket.getOutputStream(), false);
writer.println("POST /services/CBSInterfaceBusinessMgrService?wsdl HTTP/1.1");
writer.println("Host: 10.37.89.154:8688");
writer.println("Content-Type: text/xml");
writer.println("SOAPAction: \"UnSubscribeAppendantProduct\"");
writer.println("Content-Length: " + buffer.length());
writer.write("Connection: close\r\n");
writer.println();
writer.append(buffer);
writer.flush();
InputStream in = socket.getInputStream();
int count = 0;
int read = in.read();
while (read != -1)
{
count++;
System.out.print((char) read);
read = in.read();
}
socket.close();
}
System.out.println("Used time is " + (System.currentTimeMillis() - begin));
}
catch (UnknownHostException e)
{
e.printStackTrace();
}
catch (IOException e)
{
e.printStackTrace();
}
}
}
-----------------------------