海诗网 知识百科 java调用webservice接口(java调用webservice接口地址)

java调用webservice接口(java调用webservice接口地址)

java调用webservice接口, java调用webservice接口有三种方式。

方法1: Direct AXIS调用远程web服务,并输入代码:

public void doSelectRiskReportForm(HttpServletRequest request,

HttpServletResponse response){

//调用接口

//方法一:直接AXIS调用远程web服务。

try {

String endpoint=http://localhost:8080/platform-jxcx-service/services/settlementServiceImpl?wsdl;

Service service=new Service();

Call call=(Call) service.createCall();

call.setTargetEndpointAddress(endpoint);

线参数=settle _ num//参数名//对应的是公共字符串打印word(@ web param(name=settle _ num)String settle _ num);

//

call . setoperationname(print word);//被调用的方法名//当该调用不可用时,可以使用下面的方法添加命名空间名。

call.setOperationName(新QName(http://jjxg _ settlement。站台。博金斯。com/,print word));//调用的方法名

Call.addParameter (parameter name, XMLType. XSD _ string, parameter pattern. In); //parameter name //XSD _ string: string type//.Enter a parameter in .

call.setReturnType(XMLType。 XSD _ string); //Return value type: string

String message=123456789;

字符串结果=(字符串)调用。调用(新对象[]{ message });//远程调用

System.out.println(result is + result);

} catch (Exception e) {

System.err.println(e.toString());

}

}

java调用webservice接口地址

方法2:直接SOAP调用远程webservice。

下载jar,SOAP使用HTTP传输XML,虽然HTTP并不是一个高效的通信协议,XML需要额外的文件解析,使得事务速度远低于其他方案。

但是,XML是一种开放的、健全的、有语义的消息机制,而HTTP是一种广泛的、可以避免许多防火墙问题的机制,从而使得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 were 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();

}

}

}

方法三:直接用eclipse生成客户端。理念相似。

以天气预报为例:

http://www.webxml.com.cn/WebServices/WeatherWebService.asmx?wsdl

用编辑器打开下载的文件,并设置

s:element ref=s:schema/s:any /

用…替换

s:any minOccurs=2 maxOccurs=2 /

然后将文件保存为weather.wsdl。

打开保存的文件路径,输入cmd,输入

wsimport -s . weather.wsdl

java调用webservice接口地址

如果显示以上内容,则生成成功。下面是生成的文件。

java调用webservice接口地址

创建一个新的测试类WebserviceTest。java:

public class WebserviceTest {

public static void main(String[] args) {

//You can also use the New Weather Web Service (url). This method can reset the requested address URL=newurl (http://www.webxml.com.cn/webservices/weatherwebservice.asmx? wsdl)

WeatherWebService factory=new WeatherWebService();

WeatherWebServiceSoap WeatherWebServiceSoap=factory。getweatherwebservicesoap();//WeatherWebServiceSoap为调用的实现类

ArrayOfString strArray=null;

strArray=weatherwebservicesoap。getweatherbycityname(武汉);

System.out.println(strArray.getString());

}

}

如果显示以下内容,则呼叫成功。

java调用webservice接口地址

java调用webservice接口,以上就是本文为您收集整理的java调用webservice接口最新内容,希望能帮到您!更多相关内容欢迎关注。

本文来自网络,不代表海诗网立场,转载请注明出处:https://www.hallse.com/n/169505.html
      

modbus(modbus slave)

发表回复
联系我们
联系我们

在线咨询: QQ交谈

邮箱: 3587015498@qq.com

工作时间:周一至周五,9:00-17:30,节假日休息

关注微信
微信扫一扫关注我们
微信扫一扫关注我们
关注微博
返回顶部