wsdl加入header部分

来源:互联网 发布:拓展人脉的软件 编辑:程序博客网 时间:2024/06/02 14:39

     这几天在做webservice方面的东西,自己想通过java接口代码自动生成wsdl文件,找了几种方式,决定用 org.apache.axis2.eclipse.codegen.plugin插件来生成,
   后面wsdl生成倒是自动生成了,就是header部分不知道怎么自动生成,后面还是使用手工部分添加上去。感觉也挺简单的,这里记录下供需要的人参考下
1.下载org.apache.axis2.eclipse.codegen.plugin_1.7.4.jar丢入到eclipse的plugins中,重启eclipse
2.写好一个接口


3.右键项目新建


下一步




下一步,默认






拿到wsdl文件后,红色部分为修改部分加入header:

<?xml version="1.0" encoding="UTF-8"?>
<wsdl:definitions xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
xmlns:ns1="http://org.apache.axis2/xsd" xmlns:ax27="http://com/xsd"
xmlns:xsd="http://com" xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/"
xmlns:http="http://schemas.xmlsoap.org/wsdl/http/" xmlns:mime="http://schemas.xmlsoap.org/wsdl/mime/"
xmlns:wsaw="http://www.w3.org/2006/05/addressing/wsdl" targetNamespace="http://com">
<wsdl:types>
<xs:schema xmlns:ax28="http://com/xsd" attributeFormDefault="qualified"
elementFormDefault="qualified" targetNamespace="http://com">
<xs:import namespace="http://com/xsd" />
<!-- 头部分定义 -->
<xs:element name="AuthObj">
<xs:complexType>
<xs:sequence>
<xs:element name="useName" type="xs:string" />
<xs:element name="password" type="xs:string" />
<xs:element name="token" type="xs:string" />
</xs:sequence>
</xs:complexType>
</xs:element>

<!-- 请求 -->
<xs:element name="AlarmEntity">
<xs:complexType>
<xs:sequence>
<xs:element name="alarmId" type="xs:string" />
<xs:element name="alarmName" type="xs:string" />
</xs:sequence>
</xs:complexType>
</xs:element>
<!-- 响应 -->
<xs:element name="addItsmResponse">
<xs:complexType>
<xs:sequence>
<xs:element name="return" type="xs:int" />
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
</wsdl:types>
<wsdl:message name="header">
<wsdl:part name="head" element="xsd:AuthObj">
</wsdl:part>
</wsdl:message>

<wsdl:message name="addItsmRequest">
<wsdl:part name="parameters" element="xsd:AlarmEntity" />
</wsdl:message>
<wsdl:message name="addItsmResponse">
<wsdl:part name="parameters" element="xsd:addItsmResponse" />
</wsdl:message>
<wsdl:portType name="TestIntfacePortType">
<wsdl:operation name="addItsm">
<wsdl:input message="xsd:addItsmRequest" wsaw:Action="urn:addItsm" />
<wsdl:output message="xsd:addItsmResponse" wsaw:Action="urn:addItsmResponse" />
</wsdl:operation>
</wsdl:portType>
<wsdl:binding name="TestIntfaceSoap11Binding" type="xsd:TestIntfacePortType">
<soap:binding transport="http://schemas.xmlsoap.org/soap/http"
style="document" />
<wsdl:operation name="addItsm">
<soap:operation soapAction="urn:addItsm" style="document" />
<wsdl:input>
<soap:header message="xsd:header" part="head" use="literal" />
<soap:body use="literal" />
</wsdl:input>
<wsdl:output>
<soap:body use="literal" />
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
<wsdl:service name="TestIntface">
<wsdl:port name="TestIntfaceHttpSoap11Endpoint" binding="xsd:TestIntfaceSoap11Binding">
<soap:address location="http://localhost:8080/axis2/services/TestIntface" />
</wsdl:port>
</wsdl:service>
</wsdl:definitions>


导入到SOAPUI中效果如下:





原创粉丝点击