商讯信箱
用户名:
@
vip.it168.com
free.it168.com
udc.it168.com
staff.it168.com
it168.com
密 码:
注册
|
忘记密码
登录
个人用户
经销商
用户名:
密 码:
注册
|
忘记密码
验证码:
看不清?
用户名:
密 码:
注册
|
忘记密码
我的空间
登录
注册
返回首页
专题
教程
IBM软件技术精英
门户
|
论坛
|
空间
|
Blog
|
新闻
|
文档
|
Tag
|
下载
|
搜索
|
培训
|
WiKi
|
IXPUB
|
投稿
频道:
Oracle
|
DB2
|
SQL Server
|
ERP
|
Java
|
.NET
|
开源
|
移动
|
管理
|
SOA
|
测试
|
BI
|
SCM
社区导航
数据库技术
企业信息化
开发技术
系统设计与项目管理
IBM软件技术
行业纵向讨论区
会员交流
您的位置:
首页
>
技术频道
> 正文
Webservice调用方式:axis,soap详解
[
收藏此页
] [
打印
]
作者:
佚名
2007-12-19
内容导航:
Webservice调用方式:axis,so...
第1页:
Webservice调用方式:axis,soap详解
【IT168 技术文档】
调用webservice,可以首先根据wsdl文件生成客户端,或者直接根据地址调用,下面讨论直接调用地址的两种不同方式:axis和Soap,soap方式主要是用在websphere下
axis方式调用:
import java.util.Date;
import java.text.DateFormat;
import org.apache.axis.client.Call;
import org.apache.axis.client.Service;
import javax.xml.namespace.QName;
import java.lang.Integer;
import javax.xml.rpc.ParameterMode;
public class caClient {
public static void main(String[] args) {
try {
String endpoint = "http://localhost:8080/ca3/services/caSynrochnized?wsdl";
Service service = new Service();
Call call = (Call) service.createCall();
call.setTargetEndpointAddress(endpoint);
call.setOperationName("addUser");
call.addParameter("userName", org.apache.axis.encoding.XMLType.XSD_DATE,
javax.xml.rpc.ParameterMode.IN);
call.setReturnType(org.apache.axis.encoding.XMLType.XSD_STRING);
call.setUseSOAPAction(true);
call.setSOAPActionURI("http://www.my.com/Rpc");
//Integer k = (Integer) call.invoke(new Object[] { i, j });
//System.out.println("result is " + k.toString() + ".");
String temp = "测试人员";
String result = (String)call.invoke(new Object[]{temp});
System.out.println("result is "+result);
}
catch (Exception e) {
System.err.println(e.toString());
}
}
}
soap方式调用
调用java生成的webservice
import org.apache.soap.util.xml.*;
import org.apache.soap.*;
import org.apache.soap.rpc.*;
import java.io.*;
import java.net.*;
import java.util.Vector;
public class caService{
public static String getService(String user) {
URL url = null;
try {
url=new URL("http://192.168.0.100:8080/ca3/services/caSynrochnized");
} catch (MalformedURLException mue) {
return mue.getMessage();
}
// This is the main SOAP object
Call soapCall = new Call();
// Use SOAP encoding
soapCall.setEncodingStyleURI(Constants.NS_URI_SOAP_ENC);
// This is the remote object we're asking for the price
soapCall.setTargetObjectURI("urn:xmethods-caSynrochnized");
// This is the name of the method on the above object
soapCall.setMethodName("getUser");
// We need to send the ISBN number as an input parameter to the method
Vector soapParams = new Vector();
// name, type, value, encoding style
Parameter isbnParam = new Parameter("userName", String.class, user, null);
soapParams.addElement(isbnParam);
soapCall.setParams(soapParams);
try {
// Invoke the remote method on the object
Response soapResponse = soapCall.invoke(url,"");
// Check to see if there is an error, return "N/A"
if (soapResponse.generatedFault()) {
Fault fault = soapResponse.getFault();
String f = fault.getFaultString();
return f;
} else {
// read result
Parameter soapResult = soapResponse.getReturnValue ();
// get a string from the result
return soapResult.getValue().toString();
}
} catch (SOAPException se) {
return se.getMessage();
}
}
}
返回一维数组时
Parameter soapResult = soapResponse.getReturnValue();
String[] temp = (String[])soapResult.getValue();
调用ASP.Net生成的webservice
private String HelloWorld(String uri, String u) {
try {
SOAPMappingRegistry smr = new SOAPMappingRegistry();
StringDeserializer sd = new StringDeserializer();
ArraySerializer arraySer = new ArraySerializer();
BeanSerializer beanSer = new BeanSerializer();
smr.mapTypes(Constants.NS_URI_SOAP_ENC, new QName(
"http://tempuri.org/", "HelloWorldResult"), String.class,
null, sd);
smr.mapTypes(Constants.NS_URI_SOAP_ENC, new QName(
"http://tempuri.org/", "temp"), String.class,
beanSer, beanSer);
URL url = new URL(uri);
Call call = new Call();
call.setSOAPMappingRegistry(smr);
call.setTargetObjectURI("urn:xmethods-Service1");
call.setMethodName("HelloWorld");
call.setEncodingStyleURI(Constants.NS_URI_SOAP_ENC);
Vector soapParams = new Vector();
soapParams.addElement(new Parameter("temp", String.class, u, null));
call.setParams(soapParams);
Response soapResponse = call.invoke(url,"http://tempuri.org/HelloWorld");
if (soapResponse.generatedFault()) {
Fault fault = soapResponse.getFault();
System.out.println(fault);
} else {
Parameter soapResult = soapResponse.getReturnValue();
Object obj = soapResult.getValue();
System.out.println("===" + obj);
}
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
1
1
【内容导航】
第1页:
Webservice调用方式:axis,soap详解
©版权所有。未经许可,不得转载。
[责任编辑:
李宁
]
进入论坛>>
相关论坛贴
求供货商行项目明细的相关BAPI
如何控制已开发票不能跨两个月或以上进行冲销
如何將兩個PARAMETERS放在一行?
问个简单的问题,account type有什么控制作用?
abap中select 怎麼取SY-DATUM的年月
大家来列举一下查找同一内表中重复记录的最优化...
专题推荐
·
拥抱多核计算,提升软件性能
·
移动操作系统之世上最强:Symbian
·
AJAX技术学习专题
·
SQL Server 2005/2008技术专题
·
项目管理的艺术
·
Tomcat技术学习专题
·
Google+开源=??
·
SOA企业应用新专题
热点文章排行
微软企图跨越开源的鸿沟?
决战RIA 谷歌微软谁得Adobe相助?
走向标准 微软欲借IE 8取悦Web开发者?
从开发者角度分析微软Vista SP1的变化
改变形象 微软欲变身敏捷开发典范?
专访潘海东:WIKI模式协作产生价值
化干戈为玉帛 微软与Sun携手互通
耿增强:三驾马车 驱动红旗Linux
从玩具到游戏 看另类项目激励机制
一个糟糕的SOA应用不如不用?
关于皓辰
|
关于IT168
|
合作伙伴
|
广告服务
|
使用条款
|
投稿指南
|
诚聘精英
|
联系我们
|
法律顾问
|
网站地图
|
繁体版
CopyRight 1999-2006 www.it168.com All Right Reserved. 北京皓辰网域网络信息技术有限公司. 版权所有 京ICP证:060528号