通州厂房出售:Web Service调用方式大全
来源:百度文库 编辑:九乡新闻网 时间:2024/05/13 18:17:00
Webservice调用方式:axis,soap详解
调用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;
}
Web Service调用方式大全
NO Code直接根据Wsdl生成SOAP报文,发送http请求调用web service...
dedecms所有标签调用方式大全
Web Service与SOA 关系区别
web service之axis(一)111
web service之axis(一)222
Mule 3.0之Web Service Proxy555
Mule 3.0之Web Service Proxy
Web Service Composition: Design and Analysis - 飞茂 - 博客园
使用Axis开发Web Service程序-月光博客
DDD的Service用DCI的替代方式
使用 RESTlet 框架开发符合 JSR311 规范标准的 REST Web Service
web
web
Perl调用外部命令的方式和区别 - iTech's Blog - 博客园
接吻方式大全
调用IE内置打印组件完成web打印方案及例程,jsp,asp,sql,php,mysql,server,apache,iis,tomcat,oracle,java,linux,dns
群共享操作我选择Web方式 - 电脑迷杂志社官方网站
系统调用
异步调用
IPC框架分析 Binder,Service,Service manager
转贴:dedecms首页调用代码大全、会员、下载)第一篇教...
毒死中国人的方式大全
毒死中国人的方式大全