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 消息以及如何交換這些消息。大多數情況下由軟件自動生成和使用。
.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; } }
以上就是小編今天的分享了,希望可以幫助到大家。