javawebservice接口开发(web service接口开发)
java语言 编写接口开发需要用到WebService么?
WebService是第三方接口,就是可以远程调用服务接口。如果是本机上,直接调用就行了,不需要用WebService技术!
java开发webservice接口有几种方式
Support for Standards
JSR Support
??? JAX-WS - Java API for XML-Based Web Services (JAX-WS) 2.0 - JSR-224
??? Web Services Metadata for the Java Platform - JSR-181
??? JAX-RS - The Java API for RESTful Web Services - JSR-311
??? SAAJ - SOAP with Attachments API for Java (SAAJ) - JSR-67
WS-* and related Specifications Support
??? Basic support: WS-I Basic Profile 1.1
??? Quality of Service: WS-Reliable Messaging
??? Metadata: WS-Policy, WSDL 1.1 - Web Service Definition Language
??? Communication Security: WS-Security, WS-SecurityPolicy, WS-SecureConversation, WS-Trust (partial support)
??? Messaging Support: WS-Addressing, SOAP 1.1, SOAP 1.2, Message Transmission Optimization Mechanism (MTOM)
Multiple Transports, Protocol Bindings, Data Bindings, and Formats
??? Transports: HTTP, Servlet, JMS, In-VM and many others via the Camel transport for CXF such as SMTP/POP3, TCP and Jabber
??? Protocol Bindings: SOAP, REST/HTTP, pure XML
??? Data bindings: JAXB 2.x, Aegis, Apache XMLBeans, Service Data Objects (SDO), JiBX
??? Formats: XML Textual, JSON, FastInfoset
??? Extensibility API allows additional bindings for CXF, enabling additional message format support such as CORBA/IIOP
java如何调用webservice接口?
Java通过WSDL文件来调用webservice直接调用模式如下:
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 = "";
//直接引用远程的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());
}
}
}