Java calls the WebService WSDL form interface in Apache axis mode invocation (i) __web

Source: Internet
Author: User
Tags soap tomcat wsdl

1. First, what is WebService

WebService releases are typically published using the style of the WSDL (Web Service descriptive language) file, which contains the interface that the webservice exposes to use in the WSDL file.

(1) WebService is an SOA (service-oriented programming) architecture that is independent of the language, does not depend on the platform, can realize the mutual invocation between different languages, through the Internet for the HTTP protocol based on the interaction between network applications.
(2) WebService implementation of calls between languages is based on a standard, WebService is required to comply with the WSDL (Web Service Definition Language)/soap (Simple request Protocol) specification.


2. Here is a description of how to use axis to invoke WebService

(1) First download axis related jar package from official website, address: http://axis.apache.org/axis/

The official request for the introduction of the following Jar package (to introduce the jar under Lib)

Axis-<version>/lib/axis.jar Axis-<version>/lib/jaxrpc.jar Axis-<version>/lib/saaj.jar axis- <version>/lib/commons-logging-<version>.jar axis-<version>/lib/commons-discovery-<version >.jar Axis-<version>/lib/wsdl4j-<version>.jar The minimum jar I actually used in my project is as follows: H:\libs\axis.jar
H:\libs\ Jaxrpc.jar
H:\libs\commons-logging-1.0.4.jar
H:\libs\commons-discovery-0.2.jar
H:\libs\ Wsdl4j-1.5.1.jar

(2) Specific code implementation

Package IC;

Import Javax.xml.rpc.ParameterMode;
Import Org.apache.axis.client.Call;
Import Org.apache.axis.client.Service;

Import Org.apache.axis.encoding.XMLType; public class ICServiceTest1 {public static void main (string[] args) {try {String endpoint = ' http://localhost:

			3000/HY/GW/QUERYCONSIGNORDER?WSDL ";
			Service service = new service ();
			Call call = (call) Service.createcall ();
			Call.settargetendpointaddress (endpoint);
			The name of the interface described in the WSDL (the method to invoke) Call.setoperationname ("Getlisqueryconsignorder"); Parameter names of interface methods, parameter types, parametric mode in (input), out (output) or INOUT (input and output) Call.addparameter ("Icsystem", Xmltype.xsd_string, Parametermode.
			in);
			Call.addparameter ("Companyflag", xmltype.xsd_string, parametermode.in);
			Call.addparameter ("Consignorderno", xmltype.xsd_string, parametermode.in);
			Call.addparameter ("OrderNo", xmltype.xsd_string, parametermode.in);
			Sets the return value type of the invoked method Call.setreturntype (xmltype.xsd_string); Set the value of the parameter in the method object[] paramvalues = new object[] {"4PL", "NJHY,NJHF", "TC201309172206", ""};	
	
			Passes arguments to the method and invokes method String result = (string) call.invoke (paramvalues);
		SYSTEM.OUT.PRINTLN ("result being" + result);
		catch (Exception e) {e.printstacktrace ();
 }

	}

}

=========================================== Exception Resolution =============================================================

The following exception occurred today when calling the Webserivce interface

Warning: Unable to find required classes (Javax.activation.DataHandler and Javax.mail.internet.MimeMultipart).
Attachment support is disabled. Axisfault faultcode: {http://schemas.xmlsoap.org/soap/envelope/}server faultsubcode:faultstring:org/apache/axis/ Client/service FaultActor:faultNode:faultDetail: {http://xml.apache.org/axis/}stacktrace:org/apache/axis/client/ Service at Org.apache.axis.message.SOAPFaultBuilder.createFault (soapfaultbuilder.java:222) at Org.apache.axis.message.SOAPFaultBuilder.endElement (soapfaultbuilder.java:129) at Org.apache.axis.encoding.DeserializationContext.endElement (deserializationcontext.java:1087) at Com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.endElement (Unknown Source) at Com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanEndElement (Unknown Source) at Com.sun.org.apache.xerces.internal.impl.xmldocumentfragmentscannerimpl$fragmentcontentdriver.next (Unknown Source) at Com.sun.org.apache.xerces.interNal.impl.XMLDocumentScannerImpl.next (Unknown Source) at Com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.next (Unknown Source) at Com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument (Unknown Source) at Com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse (Unknown Source) at Com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse (Unknown Source) at Com.sun.org.apache.xerces.internal.parsers.XMLParser.parse (Unknown Source) at Com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse (Unknown Source) at Com.sun.org.apache.xerces.internal.jaxp.saxparserimpl$jaxpsaxparser.parse (Unknown Source) at Com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl.parse (Unknown Source) at Org.apache.axis.encoding.DeserializationContext.parse (deserializationcontext.java:227) at Org.apache.axis.SOAPPart.getAsSOAPEnvelope (soappart.java:696) at Org.apache.axis.Message.getSOAPEnvelope ( message.java:435) at Org.apache.axiS.handlers.soap.mustunderstandchecker.invoke (mustunderstandchecker.java:62) at Org.apache.axis.client.AxisClient.invoke (axisclient.java:206) at Org.apache.axis.client.Call.invokeEngine ( call.java:2784) at Org.apache.axis.client.Call.invoke (call.java:2767) at Org.apache.axis.client.Call.invoke ( call.java:2443) at Org.apache.axis.client.Call.invoke (call.java:2366) at Org.apache.axis.client.Call.invoke ( call.java:1812) at Com.pcitc.lis.ws.lisforcrm.LisForCrmWebServicePortBindingStub.createPickupOrder ( lisforcrmwebserviceportbindingstub.java:345) at Com.pcitc.lis.ws.lisforcrm.LisForCrmWebServiceDelegateProxy.createPickupOrder ( lisforcrmwebservicedelegateproxy.java:74) at Com.pcitc.lis.ws.lisforcrm.test.Test.main (test.java:24) {http:// Xml.apache.org/axis/}hostname:user-20150617tz Org/apache/axis/client/service at Org.apache.axis.message.SOAPFaultBuilder.createFault (soapfaultbuilder.java:222) at Org.apache.axis.message.SOAPFaultBuilder.endElement (soapfaultbuilder.java:129) at ORG.APache.axis.encoding.DeserializationContext.endElement (deserializationcontext.java:1087) at Com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.endElement (Unknown Source) at Com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanEndElement (Unknown Source) at Com.sun.org.apache.xerces.internal.impl.xmldocumentfragmentscannerimpl$fragmentcontentdriver.next (Unknown SOURCE) at Com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next (Unknown source) at Com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.next (Unknown Source) at Com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument (Unknown Source) at Com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse (Unknown Source) at Com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse (Unknown Source) at Com.sun.org.apache.xerces.internal.parsers.XMLParser.parse (Unknown Source) at Com.sun.org.apache.xerces.internal.parsers.AbstractSAXPArser.parse (Unknown Source) at Com.sun.org.apache.xerces.internal.jaxp.saxparserimpl$jaxpsaxparser.parse (Unknown SOURCE) at Com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl.parse (Unknown source) at Org.apache.axis.encoding.DeserializationContext.parse (deserializationcontext.java:227) at Org.apache.axis.SOAPPart.getAsSOAPEnvelope (soappart.java:696) at Org.apache.axis.Message.getSOAPEnvelope ( message.java:435) at Org.apache.axis.handlers.soap.MustUnderstandChecker.invoke (mustunderstandchecker.java:62) at Org.apache.axis.client.AxisClient.invoke (axisclient.java:206) at Org.apache.axis.client.Call.invokeEngine ( call.java:2784) at Org.apache.axis.client.Call.invoke (call.java:2767) at Org.apache.axis.client.Call.invoke ( call.java:2443) at Org.apache.axis.client.Call.invoke (call.java:2366) at Org.apache.axis.client.Call.invoke ( call.java:1812) at Com.pcitc.lis.ws.lisforcrm.LisForCrmWebServicePortBindingStub.createPickupOrder ( lisforcrmwebserviceportbindingstub.java:345) at COM.PCitc.lis.ws.lisforcrm.LisForCrmWebServiceDelegateProxy.createPickupOrder (Lisforcrmwebservicedelegateproxy.java :) at Com.pcitc.lis.ws.lisforcrm.test.Test.main (test.java:24)

This exception is not a program thrown out, is thrown by the server, so in the program to catch the exception.

This problem should be noticed whether the jar package used in the interface has been added to the server or project.

I use the WebService interface of the server for Tomcat, at this point need to use the WebService interface to all the jar into Tomcat under the Lib, after doing so, the exception to resolve


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.