Webservice调用方式:axis,soap
2014-03-15 21:52
274 查看
Webservice调用方式:axis,soap
java调用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 userName= "开发人员";
String result = (String)call.invoke(new Object[]{userName});
System.out.println("result is "+result);
}
catch (Exception e) {
System.err.println(e.toString());
}
}
}
soap方式调用
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();
相关文章推荐
- Webservice调用方式:axis,soap详解
- Webservice调用方式:axis,soap详解
- Webservice调用方式:axis,soap详解
- Webservice调用方式:axis,soap详解
- java调用.NET的webservice实例的二种方法soap方式axis模式
- .Net下采用GET/POST/SOAP方式动态调用WebService的简易灵活方法(C#)
- Android 直接写和读XML串方式 调用 WebService soap
- .Net下采用GET/POST/SOAP方式动态调用WebService的简易灵活方法(C#)
- java用axis方式调用webservice接口
- .Net下采用GET/POST/SOAP方式动态调用WebService的简易灵活方法(C#) [轉]Redfox
- java调用webservice天气预报(SOAP请求的方式获取天气信息并解析返回的XML)
- JavaScript Soap 方式调用WebService
- .Net下采用GET/POST/SOAP方式动态调用WebService
- webservice调用方式http和soap的区别
- 利用SOAP方式调用webservice
- .Net下采用GET/POST/SOAP方式动态调用WebService的简易灵活方法(C#)
- JavaScript Soap 方式调用WebServicejavascript
- .Net下采用GET/POST/SOAP方式动态调用WebService的简易灵活方法(C#)
- 客户端调用webservice方式一(soap请求)
- 起步X5开发HTML5通过ajax调用WebService服务,调用的两种方式SOAP和Result