導航:首頁 > 版本升級 > wsdl文件怎麼使用

wsdl文件怎麼使用

發布時間:2024-09-07 23:11:32

⑴ 如何打開wsdl文件

webservice的發布一般都是使用WSDL(web service descriptive language)文件的樣式來發布的,在WSDL文件裡面,包含這個webservice暴露在外面可供使用的介面。
注意,以下的代碼並沒有經過真正的測試,只是說明這些情況,不同版本的Axis相差很大,最好以apache網站上的例子為准,這里僅僅用於說明其基本用法。

1,直接AXIS調用遠程的web service,直接調用模式如下:
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";
//直接引用遠程的wsdl文件
//以下都是套路
Service service = new Service();
Call call = (Call) service.createCall();
call.setTargetEndpointAddress(endpoint);
call.setOperationName("addUser");//WSDL裡面描述的介面名稱
call.addParameter("userName", org.apache.axis.encoding.XMLType.XSD_DATE,
javax.xml.rpc.ParameterMode.IN);//介面的參數
call.setReturnType(org.apache.axis.encoding.XMLType.XSD_STRING);//設置返回類型
String temp = "測試人員";
String result = (String)call.invoke(new Object[]{temp});
//給方法傳遞參數,並且調用方法
System.out.println("result is "+result);
}
catch (Exception e) {
System.err.println(e.toString());
}
}
}

2,直接SOAP調用遠程的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();
}
}
}

閱讀全文

與wsdl文件怎麼使用相關的資料

熱點內容
純文本文件和二進制文件 瀏覽:216
如何把網路玩起來 瀏覽:654
錄視頻文件特別小的軟體 瀏覽:75
vivo隱藏文件夾在哪裡設置 瀏覽:790
都有哪些圈錢APP 瀏覽:434
javaweb開發pdf 瀏覽:313
ps保存文件特大 瀏覽:46
網路和編程哪個更吃香 瀏覽:583
神武用過的賬號都在哪個文件夾里 瀏覽:70
對於初學者用什麼編程語言比較好 瀏覽:470
吉林環保文件櫃值多少錢 瀏覽:111
1607版本win10 瀏覽:968
如何使文件不能復制 瀏覽:96
matlabr2017a安裝教程 瀏覽:287
access資料庫查詢生成表 瀏覽:661
nodejsforever配置 瀏覽:181
蘿卜網路什麼意思 瀏覽:925
steam地平線4存檔在哪個文件夾 瀏覽:870
JAVA下載壓縮文件包括文件夾 瀏覽:277
上古5法術代碼 瀏覽:235

友情鏈接