客户端,程序中做了很多的注释,看起来应该不会太困难,我就不多说了.
package demo;
/**
* Title:SOAP
* Description: 浆糊作品
* Copyright: Copyright (c) 2001
* Company:
* @author 一桶浆糊
* @version 1.0
*/
import org.apache.soap.*;
import org.apache.soap.rpc.*;
import java.util.*;
import java.net.URL;
public class HelloClient {
public HelloClient() {
}
public static void main( String[] args ) throws Exception
{
URL url = new URL( "http://localhost:8080/soap/servlet/rpcrouter" );
String urn = "urn:demo:helloworld"; //服务器名称,在部署的时候自己定义
Call call = new Call(); // 准备调用web service
call.setTargetObjectURI( urn );
call.setMethodName( "getHello" );
call.setEncodingStyleURI( Constants.NS_URI_SOAP_ENC );
Vector params = new Vector();
//设置接口参数 字串7
params.addElement( new Parameter("aUserName", String.class, "浆糊", null ) );
call.setParams( params );
try
{
System.out.println( "invoke service\n" " URL= " url "\n URN =" urn );
Response response = call.invoke( url, "" ); // 进行调用
if( !response.generatedFault() ) //是否产生错误
{
Parameter result = response.getReturnValue(); // 取得返回值
System.out.println( "Result= " result.getValue() );//哇!,成功了
}
else
{
Fault f = response.getFault(); // 得到一个错误
System.err.println( "Fault= " f.getFaultCode() ", " f.getFaultString() );
}
}
catch( SOAPException e ) // 捕获异常
{
System.err.println( "SOAPException= " e.getFaultCode() ", " e.getMessage() );
}
}
}
最新评论共有 0 位网友发表了评论
查看所有评论
发表评论
热点关注
相关文章
相关文章
![我要研发网[www.51dev.com]](/templets/images/toplogo.gif)
