CXF创建WebService的一些注解
<wsdl:binding name="HelloWSServiceSoapBinding" type="tns:HelloWS ">
<soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
<wsdl:operation name="welcome">
<soap:operation soapAction="" style="document"/>
<wsdl:input name="welcome">
<soap:body use="literal"/>
</wsdl:input>
<wsdl:output name="welcomeResponse">
<soap:body use="literal"/>
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
<wsdl:service name="HelloWSService">
<wsdl:port binding="tns:HelloWSServiceSoapBinding" name="HelloWS Port">
<soap:address location="http://localhost:8000/services/hello"/>
</wsdl:port>
</wsdl:service>
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.TYPE,ElementType.METHOD})
public @interface SOAPBinding {
SOAPBinding.Style style() default SOAPBinding.Style.DOCUMENT;
/** Specifies the style of the SOAP message. If RPC style is specified,each message part within the SOAP body is a parameter or return value and will appear inside a wrapper element within the soap:body element. The message parts within the wrapper element correspond to operation parameters and must appear in the same order as the parameters in the operation. If DOCUMENT style is specified,the contents of the SOAP body must be a valid XML document,but its form is not as tightly constrained. (DOCUMENT 形式不是很严格) **/
SOAPBinding.Use use() default SOAPBinding.Use.LITERAL;
/** Specifies how the data of the SOAP message is streamed.定义数据流的形式 ENCODED:译成密码 LITERAL:照字面的;原义的,不进行加密处理 **/
SOAPBinding.ParameterStyle parameterStyle() default SOAPBinding.ParameterStyle.WRAPPED;
/** Specifies how the method parameters,(方法的参数) which correspond to message parts in a WSDL contract,are placed into the SOAP message body. A parameter style of BARE(光秃秃的) means that each parameter the message root. A parameter style of WRAPPED means that all of the input parameters are wrapped into a single element on a into a single element in the response message. If you set the style to RPC you must use the WRAPPED parameter style. (感觉差距不大,自己想玩自己编程试试就知道这个到底是什么意思了) **/
public static enum ParameterStyle {
BARE,WRAPPED;
private ParameterStyle() {
}
}
public static enum Style {
DOCUMENT,RPC;
private Style() {
}
}
public static enum Use {
LITERAL,ENCODED;
private Use() {
}
}
}
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.METHOD})
public @interface WebMethod {
String operationName() default "";
//方法的名称,默认为当前方法的名称
String action() default "";
/** Specifies the value of the soapAction attribute of the soap:operation element generated for the method. The default value is an empty string. (就是在操作方法下面生成的一个子元素,默认为空) **/
boolean exclude() default false;
/** Specifies if the method should be excluded from the service interface. The default is false.(从接口方法中排除,默认为false,感觉没有啥子用处啊! ) **/
}
@Target(ElementType.METHOD)
@Retention(RetentionPolicy.RUNTIME)
@Documented
public @interface RequestWrapper {
/** * Element's local name. */
public String localName() default "";
/** Specifies the local name of the wrapper element in the XML representation of the request message. The default value is the name of the method or the value of the @WebMethod annotation's operationName property.(默认为方法中的名称) **/
/** Specifies the namespace under which the XML wrapper element is defined. The default value is the target namespace of the SEI. */
public String targetNamespace() default "";
/** * Specifies the full name of the Java class that implements the wrapper element. * 这个定义是必须的! */
public String className() default "";
/** * wsdl:part name for the wrapper part * * @since JAX-WS 2.2 */
public String partName() default "";
}
7.The @ResponseWrapper annotation 这个下面是apache 中的例子,我在使用的时候不用包装也是可以的。使用起来还是挺麻烦的。 package org.apache.cxf;
import javax.jws.*;
import javax.xml.ws.*;
@WebService(name="quoteReporter")
public interface QuoteReporter {
@WebMethod(operationName="getStockQuote")
@RequestWrapper(targetNamespace="http://demo.mycompany.com/types",className="java.lang.String")
@ResponseWrapper(targetNamespace="http://demo.mycompany.com/types",className="org.eric.demo.Quote")
public Quote getQuote(String ticker);
}
8.The @WebParam annotation @Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.PARAMETER})
public @interface WebParam {
String name() default "";
/** Specifies the name of the parameter as it appears in the WSDL. For RPC bindings,this is name of the wsdl:part representing the parameter. For document bindings,this is the local name of the XML element representing the parameter. Per the JAX-WS specification,the default is argN,where N is replaced with the zero-based argument index (i.e.,arg0,arg1,etc.) **/
String partName() default "";
/** Specifies the value of the name attribute of the wsdl:part element for the parameter when the binding is document. **/
String targetNamespace() default "";
WebParam.Mode mode() default WebParam.Mode.IN;
/** Specifies the direction of the parameter. 有点类似于引用传参数,这个哥哥尝试了一下,真的可以诶,INOUT 传入,传出参数。 **/
boolean header() default false;
/** Specifies if the parameter is passed as part of the SOAP header. **/
public static enum Mode {
IN,OUT,INOUT;
private Mode() {
}
}
}
(编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |