echoclient.java

来自「精通Jboss——Ejb和Web Services开发精解的随书源代码」· Java 代码 · 共 52 行

JAVA
52
字号
/**
 * EchoClient.java Created on 2003-12-4
 *
 */
package com.liuyang.axis.client;

import java.io.ByteArrayInputStream;
import java.io.InputStream;
import java.net.URL;

import org.apache.axis.client.Call;
import org.apache.axis.client.Service;
import org.apache.axis.message.SOAPEnvelope;

/**
 * @author 刘洋
 *
 */
public class EchoClient {

	public static String msg = "<SOAP-ENV:Envelope " +
		"xmlns:SOAP-ENV=\"http://schemas.xmlsoap.org/soap/envelope/\" " +
		"xmlns:soapenc=\"http://schemas.xmlsoap.org/soap/encoding/\" > " +
		"<SOAP-ENV:Body>\n" +
		"<echo:Echo xmlns:echo=\"EchoService\">\n" +
		"<symbol>IBM</symbol>\n" +
		"</echo:Echo>\n" +
		"</SOAP-ENV:Body></SOAP-ENV:Envelope>\n";
	public static void main(String[] args) throws Exception {
		String	url     = "http://localhost:8080/axis/services/EchoService";
		String  action  = "EchoService" ;
		
		InputStream   input   = new ByteArrayInputStream(msg.getBytes());
		Service       service = new Service();
		Call          call    = (Call) service.createCall();
		SOAPEnvelope  env     = new SOAPEnvelope(input);

		call.setTargetEndpointAddress( new URL(url) );
		if (action != null) {
			call.setUseSOAPAction( true );
			call.setSOAPActionURI( action );
		}

		System.out.println( "Request:\n" + msg );

		env = call.invoke( env );

		System.out.println( "Response:\n" + env.toString() );
		
	}
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?