海詩網(wǎng) 知識百科 java調(diào)用webservice接口(java調(diào)用webservice接口地址)

java調(diào)用webservice接口(java調(diào)用webservice接口地址)

java調(diào)用webservice接口, java調(diào)用webservice接口有三種方式。

方法1: Direct AXIS調(diào)用遠(yuǎn)程web服務(wù),并輸入代碼:

public void doSelectRiskReportForm(HttpServletRequest request,

HttpServletResponse response){

//調(diào)用接口

//方法一:直接AXIS調(diào)用遠(yuǎn)程web服務(wù)。

try {

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

Service service=new Service();

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

call.setTargetEndpointAddress(endpoint);

線參數(shù)=settle _ num//參數(shù)名//對應(yīng)的是公共字符串打印word(@ web param(name=settle _ num)String settle _ num);

//

call . setoperationname(print word);//被調(diào)用的方法名//當(dāng)該調(diào)用不可用時,可以使用下面的方法添加命名空間名。

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

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;

字符串結(jié)果=(字符串)調(diào)用。調(diào)用(新對象[]{ message });//遠(yuǎn)程調(diào)用

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

} catch (Exception e) {

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

}

}

java調(diào)用webservice接口地址

方法2:直接SOAP調(diào)用遠(yuǎn)程webservice。

下載jar,SOAP使用HTTP傳輸XML,雖然HTTP并不是一個高效的通信協(xié)議,XML需要額外的文件解析,使得事務(wù)速度遠(yuǎn)低于其他方案。

但是,XML是一種開放的、健全的、有語義的消息機制,而HTTP是一種廣泛的、可以避免許多防火墻問題的機制,從而使得SOAP得到廣泛的應(yīng)用。但是如果效率對你來說很重要,那么你應(yīng)該考慮其他方式。

而不是用肥皂。

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生成客戶端。理念相似。

以天氣預(yù)報為例:

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

用編輯器打開下載的文件,并設(shè)置

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

用…替換

s:any minOccurs=2 maxOccurs=2 /

然后將文件保存為weather.wsdl。

打開保存的文件路徑,輸入cmd,輸入

wsimport -s . weather.wsdl

java調(diào)用webservice接口地址

如果顯示以上內(nèi)容,則生成成功。下面是生成的文件。

java調(diào)用webservice接口地址

創(chuàng)建一個新的測試類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為調(diào)用的實現(xiàn)類

ArrayOfString strArray=null;

strArray=weatherwebservicesoap。getweatherbycityname(武漢);

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

}

}

如果顯示以下內(nèi)容,則呼叫成功。

java調(diào)用webservice接口地址

java調(diào)用webservice接口,以上就是本文為您收集整理的java調(diào)用webservice接口最新內(nèi)容,希望能幫到您!更多相關(guān)內(nèi)容歡迎關(guān)注。

本文來自網(wǎng)絡(luò),不代表海詩網(wǎng)立場,轉(zhuǎn)載請注明出處:http://x91880.com/n/169505.html
      

modbus(modbus slave)

發(fā)表回復(fù)
聯(lián)系我們
聯(lián)系我們

在線咨詢: QQ交談

郵箱: 3587015498@qq.com

工作時間:周一至周五,9:00-17:30,節(jié)假日休息

關(guān)注微信
微信掃一掃關(guān)注我們
微信掃一掃關(guān)注我們
關(guān)注微博
返回頂部