java - asmx

來源:趣味經驗館 5.61K

<link rel="stylesheet" href="https://js.how234.com/third-party/SyntaxHighlighter/shCoreDefault.css" type="text/css" /><script type="text/javascript" src="https://js.how234.com/third-party/SyntaxHighlighter/shCore.js"></script><script type="text/javascript"> SyntaxHighlighter.all(); </script>

java asmx是什麼,讓我們一起了解一下?

asmx是webservice的字尾介面,.asmx是WEB服務檔案,屬於B/S形式,用SOAP方式HTTP訪問,用XML返回,可以返回基礎型別和PUBLIC結構型別,在C/S結構中經常用到。

那webservice介面wsdl和asmx有什麼區別?

沒有區別,只是字尾名的區別。
Web Service也叫XML Web Service WebService是一種可以接收從Internet或者Intranet上的其它系統中傳遞過來的請求,輕量級的獨立的通訊技術。是通過SOAP在Web上提供的軟體(服務),使用WSDL檔案進行(說明),並通過(UDDI)進行註冊。

WSDL:(Web Services Description Language) WSDL 檔案是一個 XML 文件,用於說明一組 SOAP 訊息以及如何交換這些訊息。大多數情況下由軟體自動生成和使用。

java asmx

.asmx是webservice服務程式的字尾名,ASP.NET 使用.asmx 檔案來對Web Services的支援。.asmx 檔案和.aspx檔案一樣都屬於文字檔案。它包含在.aspx檔案之中,成為ASP.NET應用程式的一部分。

實戰操作:如何用Java呼叫webservice的.asmx字尾介面?

import javax.xml.namespace.QName;import org.apache.axis.client.Call;import org.apache.axis.client.Service;public class WebUtil {public static final String url = "http://127.0.0.1/ToVideoWebService.asmx";public static void main(String[] args){Object[] params = new Object[]{"stryang",18};String result = sendWebservice(url, params);System.out.println(result);}public static String sendWebservice(Object[] params, String url) {String soapaction = "http://tempuri.org/"; // 域名,這是在server定義的String operationName = "VideoWebService";// 呼叫方法名Service service = new Service();String ret = "";try {Call call = (Call) service.createCall();call.setTargetEndpointAddress(url);call.setOperationName(new QName(soapaction, operationName)); // 設定要呼叫哪個方法call.addParameter(new QName(soapaction, "name"), // 設定要傳遞的引數org.apache.axis.encoding.XMLType.XSD_STRING,javax.xml.rpc.ParameterMode.IN);call.addParameter(new QName(soapaction, "age"), // 設定要傳遞的引數org.apache.axis.encoding.XMLType.XSD_STRING,javax.xml.rpc.ParameterMode.IN);call.setReturnType(org.apache.axis.encoding.XMLType.XSD_STRING);// (標準的型別)call.setUseSOAPAction(true);call.setSOAPActionURI(soapaction + operationName);ret = (String) call.invoke(params);// 呼叫方法並傳遞引數} catch (Exception ex) {ex.printStackTrace();}return ret;}}

熱門標籤