Webservice调用方式:axis,soap详解

转自: [url]http://blog.csdn.net/baiboy4493/archive/2009/03/13/3987526.aspx[/url]
调用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;
}
/**
* 调用 C# 的webservice接口
* SoapRpcMethod(Action = "http://www.tangs.com/Add",
* RequestNamespace = "http://www.tangs.com/T",
* ResponseNamespace = "http://www.tangs.com/T",
* Use = SoapBindingUse.Literal)]
*
* */
public static void addTest() {
try {
Integer i = 1;
Integer j = 2;

// WebService URL
String service_url = "http://localhost:4079/ws/Service.asmx";

Service service = new Service();
Call call = (Call) service.createCall();
call.setTargetEndpointAddress(new java.net.URL(service_url));

// 设置要调用的方法
call.setOperationName(new QName("http://www.tangs.com/T", "Add"));

// 该方法需要的参数
call.addParameter("a", org.apache.axis.encoding.XMLType.XSD_INT, javax.xml.rpc.ParameterMode.IN);
call.addParameter("b", org.apache.axis.encoding.XMLType.XSD_INT, javax.xml.rpc.ParameterMode.IN);

// 方法的返回值类型
call.setReturnType(org.apache.axis.encoding.XMLType.XSD_INT);

call.setUseSOAPAction(true);
call.setSOAPActionURI("http://www.tangs.com/Add");

// 调用该方法
Integer res = (Integer) call.invoke(new Object[] { i, j });

System.out.println("Result: " + res.toString());

} catch (Exception e) {
System.err.println(e);
}
}

/**
* 调用 C# 的webservice接口
* SoapRpcMethod(Action = "http://www.tangs.com/Add",
* RequestNamespace = "http://www.tangs.com/T",
* ResponseNamespace = "http://www.tangs.com/T",
* Use = SoapBindingUse.Literal)]
*
* */
public static void helloTest() {
try {

String endpoint = "http://localhost:4079/ws/Service.asmx";
Service service = new Service();
Call call = (Call) service.createCall();
call.setTargetEndpointAddress(new java.net.URL(endpoint));
call.setOperationName(new QName("http://www.tangs.com/T", "HelloWorld"));

call.setUseSOAPAction(true);
call.setSOAPActionURI("http://www.tangs.com/Hello");

String res = (String) call.invoke(new Object[] { null });

System.out.println("Result: " + res);
} catch (Exception e) {
System.err.println(e.toString());
}
}
SOAP Axis 三种发布调用方式简单实例 比较简单的SOAP Axis三种发布、调用方式简单的实例,代码和文档都在,不包含AXIS包,需要自行下载。 立即下载

相关推荐

WebService实例(axis + soapUI)

WebService实例(axis + soapUI),包含服务端代码和客户端代码。 客户端代码可用soapUI生成,也可以自己用axis写。客户端程序里面都有。

axis解析返回值_深入剖析Axis2中返回值为复杂自定义类型值【步步逼近实践篇】...

问:Axis2中到底能否传递复杂以及自定义对象?答:肯定可以那如何传递呢?在开发过程中,基本类型已经不能满足要求。所以才有有相应的List,Map,以及User对象,Dog对象等等。比如传递User对象,我们想象一下,到底我们该怎么样,把这个对象传递过去呢?我们再根据前面讲的Webservice传递协议,该如何办呢?实际上发给服务器中是怎么样的格式呢?在做Webservice时,肯定很好奇,到底这...

weixin_34363294的博客 696

瑞芯微RK3576上手实测:8nm新U配6TOPS NPU,做AIoT项目选它还是RK3588/RK3568?

本文深度评测瑞芯微RK3576芯片在中高端AIoT项目中的表现,对比RK3588和RK3568的性能差异。RK3576采用8nm工艺,配备6TOPS NPU,在解码能力、AI推理效率和功耗控制方面表现均衡,是中端项目的黄金选择。实测数据显示其在多路视频解码和AI加速性能上优势明显,特别适合智能摄像头和工业HMI设备。

weixin_42627853的博客 727

axis调用webservice服务

1.axis1 调用 **首先要引入jar: <dependency> <groupId>axis</groupId> <artifactId>axis</artifactId> <version>1.4</version> </dependency>** ====...

weixin_43128990的博客 685

【GAN实战】基于pytorch-CycleGAN与pix2pix的自定义数据集训练全攻略

本文详细解析了基于PyTorch的CycleGAN与pix2pix模型在自定义数据集上的完整训练流程。核心在于根据数据是否成对来正确选择模型:pix2pix适用于严格配对的“孪生”数据,而CycleGAN则擅长处理非配对的“散装”数据集。文章从数据准备、配置训练到测试应用,提供了全链路实战指南与关键参数调优心得,帮助开发者高效实现图像到图像的风格转换。

x2y3z4a5b的博客 708

Halcon实战:5分钟搞定金属表面划痕检测(附完整代码解析)

本文提供了一份基于Halcon的金属表面划痕检测实战指南。通过核心的动态阈值算法,快速从图像中提取局部对比度异常区域,并结合形态学后处理与特征筛选,精准识别划痕。文章详解了从代码搭建、参数优化到工业场景适配的全流程,帮助工程师在五分钟内构建稳定高效的机器视觉检测方案。

weixin_29084231的博客 500

AXIS1.4 client invokes service error NumberFormatException

Recently, ourclients provided a web service which was implemented by RCP way using SOAP1.1 protocol. Everything was smooth before we invoke service. I use WSDL2Java togenerate STUB, SEI, Locator and e

shryan_bin的专栏 1629

【SEED Labs 2.0】V*N Tunneling Lab

本文为 SEED Labs 2.0 - V*N Tunneling Lab 的实验记录。本实验工作量较大,但难度不大,重点在于搞清是谁发给谁,走的什么路径。另外,本次实验由于网络中的设备较多,修改了环境变量方便分清哪个窗口是哪个设备。这样操作起来就方便多了。...

Chenyang的博客 6992

Java - Webservice调用方式:axis,soap详解

调用webservice,可以首先根据wsdl文件生成客户端,或者直接根据地址调用,下面讨论直接调用地址的两种不同方式:axis和Soap,soap方式主要是用在websphere下 axis方式调用: import java.util.Date; import java.text.DateFormat; import org.apache.axis.client.Ca...

wenliang1990的博客 283

如何设计ADAS系统功能状态机(一)

状态机模块在自动驾驶系统中扮演着关键的角色,它负责管理和控制各个功能的状态转换和行为执行。今天我们来聊聊如何设计自动驾驶系统的状态机。

supass2018的博客 1619

DC算法竞赛——北京PM2.5浓度回归分析

北京PM2.5浓度回归分析 比赛结果(118/1150) 一. 概述 1、项目来源:https://www.dcjingsai.com/static_page/cmpList.html 2、给定数据字段如下: 3、使用方法:回归算法 4、目的:预测北京pm2.5值,使平均预测误差越小越好。 二、分析过程 setwd("E:/R数据源") #读入数据 data <- read.csv('p...

玻璃球的博客 3478

java js webservice接口_java调用webservice接口实现方式有哪些?

我们知道,接口是java的一个重要概念,一切的实现都基于接口,这次,小编要为大家讲解的就是如何在java中调用webservice,下面就一下来看看。一、AXIS远程调用web serviceimportjava.util.Date;importjava.text.DateFormat;importorg.apache.axis.client.Call;importorg.apache.a...

weixin_42261068的博客 204

React 源码解析 | Reconcile协调过程

上篇讲了React的工作流程,这篇详细的讲一下render过程中的beginWork函数,也就是深度优先创建Fiber树中"递"的过程。beginWork函数传入当前已经创建好的Fiber节点,返回创建/复用的第一个子FIber节点,也就是wip.child在renderRoot中,在开始创建整棵FIber树之前,会先调用prepareRefreshStack创建/复用一个新的HostRootFiber。

weixin_40710412的博客 1222
下一篇: 一些URL
htcp3700
博客等级 码龄17年 0粉丝 3原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值