The previous use of the WebService service was simple, based on the provided WSDL interface address, automatically generating the WebService client package via eclipse or idea, and then calling directly on it. This business provides the WSDL is need to verify the SoapHeader, and through the IDE tools can not generate a direct call to the class package, but only through other means to achieve, through Baidu, you can use the axis package to achieve the implementation process as follows: 1, the need for JAR package dependencies
<dependency>
<groupId>org.apache.axis</groupId>
<artifactid>axis</ artifactid>
<version>1.4</version>
</dependency>
<dependency>
< groupid>javax.xml.rpc</groupid>
<artifactId>javax.xml.rpc-api</artifactId>
< version>1.1.1</version>
</dependency>
<dependency>
<groupId> org.apache.geronimo.bundles</groupid>
<artifactId>commons-discovery</artifactId>
<version>0.4_1</version>
</dependency>
<dependency>
<groupId> wsdl4j</groupid>
<artifactId>wsdl4j</artifactId>
<version>1.6.3</version >
</dependency>
2. WSDL Interface Document
<?xml version= "1.0" encoding= "Utf-8"?> <wsdl:definitions xmlns:wsdl= "http://schemas.xmlsoap.org/wsdl/" xmlns:s= "Http://www.w3.org/2001/XMLSchema" xmlns:soap12= "http://schemas.xmlsoap.org/wsdl/soap12/" Xmlns:mime= " http://schemas.xmlsoap.org/wsdl/mime/"xmlns:tns=" http://tempuri.org/"xmlns:soap=" http://schemas.xmlsoap.org/ wsdl/soap/"xmlns:tm=" http://microsoft.com/wsdl/mime/textMatching/"xmlns:http=" http://schemas.xmlsoap.org/wsdl/ http/"xmlns:soapenc=" http://schemas.xmlsoap.org/soap/encoding/"targetnamespace=" http://tempuri.org/"> < wsdl:types> <s:schema elementformdefault= "qualified" targetnamespace= "http://tempuri.org/" > <s:ele ment name= "Sendxmlfile" > <s:complexType> <s:sequence> <s:element minocc urs= "0" maxoccurs= "1" name= "Xmlprojectdata" type= "s:base64binary"/> <s:element minoccurs= "0" maxOccurs = "1" name= "reportdate" type= "s:string"/> </s:sequence> </s:complexType> </s:element> <s:element name= "Sendxmlfilerespon Se "> <s:complexType> <s:sequence> <s:element minoccurs=" 0 "maxoccurs=" 1 "Name=" Sendxmlfileresult "type=" s:string "/> </s:sequence> </s:complexType> < /s:element> <s:element name= "Usersoapheader" type= "Tns:usersoapheader"/> <s:complextype "name=" Usersoapheader "> <s:sequence> <s:element minoccurs=" 0 "maxoccurs=" 1 "name=" UserId "type=" s : string "/> <s:element minoccurs=" 0 "maxoccurs=" 1 "name=" PassWord "type=" s:string "/> </s:s
equence> <s:anyAttribute/> </s:complexType> </s:schema> </wsdl:types> <wsdl:message name= "Sendxmlfilesoapin" > <wsdl:part name= "Parameters" element= "Tns:sendxmlfile"/> &
Lt;/wsdl:message> <wsdl:message name= "Sendxmlfilesoapout" > <wsdl:part name= "Parameters" element= "Tns:sendxmlfileresponse"/&
Gt </wsdl:message> <wsdl:message name= "Sendxmlfileusersoapheader" > <wsdl:part name= "Usersoapheader" E lement= "Tns:usersoapheader"/> </wsdl:message> <wsdl:porttype name= "Datareportservicesoap" > < Wsdl:operation name= "Sendxmlfile" > <wsdl:input message= "Tns:sendxmlfilesoapin"/> <wsdl:output m Essage= "Tns:sendxmlfilesoapout"/> </wsdl:operation> </wsdl:portType> <wsdl:binding name= "Dat Areportservicesoap "type=" Tns:datareportservicesoap "> <soap:binding transport=" http://schemas.xmlsoap.org/ Soap/http "/> <wsdl:operation name=" Sendxmlfile "> <soap:operation soapaction=" Http://tempuri.org/S Endxmlfile "style=" document "/> <wsdl:input> <soap:body use=" literal "/> <soap: Header message= "Tns:sendXmlfileusersoapheader "part=" Usersoapheader "use=" literal "/> </wsdl:input> <wsdl:output>
<soap:body use= "literal"/> </wsdl:output> </wsdl:operation> </wsdl:binding> <wsdl:binding name= "DATAREPORTSERVICESOAP12" type= "Tns:datareportservicesoap" > <soap12:binding transport= "Http://schemas.xmlsoap.org/soap/http"/> <wsdl:operation name= "Sendxmlfile" > <soap12:operation so apaction= "Http://tempuri.org/SendXMLFile" style= "document"/> <wsdl:input> <soap12:body use= "L
Iteral "/> <soap12:header message= tns:sendxmlfileusersoapheader" part= "Usersoapheader" use= "literal"/> </wsdl:input> <wsdl:output> <soap12:body use= "literal"/> </wsdl:output > </wsdl:operation> </wsdl:binding> <wsdl:service name= "Datareportservice" > <wsdl :p ort name= "DatareportseRvicesoap "binding=" Tns:datareportservicesoap "> <soap:address location=" http://221.226.63.54:8187/ Datareportservice.asmx "/> </wsdl:port> <wsdl:port name=" DATAREPORTSERVICESOAP12 "binding=" Tns:datar EPORTSERVICESOAP12 "> <soap12:address location=" http://221.226.63.54:8187/DataReportService.asmx "/> &L T;/wsdl:port> </wsdl:service> </wsdl:definitions>
3. Interface calling code
public static void Sendreporttest (byte[] reportdata, String date) {try {//server-side URL that needs to be changed depending on the situation.
String Endpointurl = URL;
Service service = new service ();
Call call = (call) Service.createcall ();
Call.settimeout (New Integer (60000));
Call.settargetendpointaddress (New URL (Endpointurl));
Call.setsoapactionuri ("Http://tempuri.org/SendXMLFile");
Call.setoperationname (New QName ("http://tempuri.org/", "Sendxmlfile"));//Set the name of the operation.
Because you need authentication, you need to set the username and password for the call.
Soapheaderelement soapheaderelement = new Soapheaderelement ("http://tempuri.org/", "Usersoapheader");
Soapheaderelement.setnamespaceuri ("http://tempuri.org/");
try {soapheaderelement.addchildelement ("UserId"). SetValue (USER_ID);
Soapheaderelement.addchildelement ("PassWord"). SetValue (PassWord);
catch (SoapException e) {e.printstacktrace ();
} call.addheader (Soapheaderelement); Call.setreturntype (xmltype.xsd_string);//returned data type Call.addparameter (new QName ("http://tempuri.org/", " Xmlprojectdata "), XmlType. Xsd_base64, parametermode.in);//parameter Type Call.addparameter (new QName ("http://tempuri.org/", "reportdate"), xmltype.xsd _string, parametermode.in);//The type of the parameter string result = (string) call.invoke (new object[]{reportdata,date});//Execute call//result letter
Parse Document document = Documenthelper.parsetext (result);
Element rootelement = Document.getrootelement ();
Iterator iter = rootelement.elementiterator ("state");
while (Iter.hasnext ()) {element Recordele = (Element) Iter.next ();
String code = Recordele.gettexttrim ()//state value if ("0". Equals (code)) {//Success Logger.getrootlogger (). Error ("Invoke interface succeeded");
}else{//Failed to save Log logger.getrootlogger (). Error (Result);
Exception e) {Logger.getrootlogger (). Error ("Invoke interface failed", e); }
}