RSS
热门关键字:
当前位置 : 主页>编程开发>Jsp教程>列表

SOAP教程(-)--客户端

来源:我要研发网 作者: 时间:1970-01-01 点击:



客户端,程序中做了很多注释,看起来应该不会太困难,我就不多说了.
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 位网友发表了评论
发表评论
评论内容:不能超过250字,需审核,请自觉遵守互联网相关政策法规。
用户名: 密码:
匿名?
注册
相关文章