Call the WebService interface using axis __web

Source: Internet
Author: User
Tags soap xmlns wsdl

The previous use of the WebService service was simple, by automatically generating the WebService client package from Eclipse or idea, based on the provided WSDL interface address, and then invoking it directly. This business provides WSDL is need to verify SoapHeader, and through the IDE tool can not generate directly call class package, helpless can only be implemented by other means, through Baidu, you can use the axis package to achieve, the implementation process is as follows: 1, the need for the jar package depends on

        <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 Documentation
<?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 Call Code

public static void Sendreporttest (byte[] reportdata, String date) {try {//server-side URL, needs to be changed as appropriate.
		String Endpointurl = URL;
		Service service = new service ();
		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 authentication is required, the user name and password for the call need to be set.
		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);//The data type returned Call.addparameter (new QName ("http://tempuri.org/", " Xmlprojectdata "), XMLType. Xsd_base64, parametermode.in);//The type of the parameter 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
		Parsing 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 ("Call interface succeeded");
			}else{//Failed to save Log logger.getrootlogger (). Error (Result);
	}}} catch (Exception e) {Logger.getrootlogger (). Error ("Failed to invoke interface", e); }
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.