Handle complex custom data types in AXIS

xiaoxiao2021-03-06  76

What is axis

AXIS is essentially a SOAP engine, but AXIS is not just a SOAP engine, but it can be called a web service. Since this paper is not in some, please refer to the Axis User Guide.

Knowledge you must understand

If you are a new hand of Java, Servlet, and SOAP, you may encounter a lot of trouble about AXIS, so it is not recommended to write AXIS's customers and servers. When you basically understand the following knowledge, you can start Axis tour.

Java's data type, core of class, and programming concepts.

What is Threads, Race Conditions, Thread Safety, and Synchronization.

What is ClassLoader, what is a common reason for multi-grade ClassLoader, and "classnotfoundexception" exception.

How to diagnose what is abnormal, NullPointerexception (NPE) and other common exceptions, and know how to modify them.

What is the web application; what is where servlets, classes, class libraries, and data placed in web applications.

How to start your application service, how to release a web application to the app service.

What is the core of the network, IP protocol concept, and those Sockets APIs. In particular, what is TCP / IP.

What is http. Core protocol and error code, HTTP header and most of the verification details.

What is XML. Although you don't need to know how to explain her or other technologies, you have to know how to make a good style and correct XML.

AXIS installation

Since we use JBuilder 8 developed in this article, how to install AXIS is not important. If you would like to know the installation of Axis, please refer to the "Axis Installation Description"

Start JBuider 8 and Axis Tour

1. Open JBuider 8, build a new project Axistour, build a web application TOUR, here Tomcat-4.0.6-Le-JDK14;

2, build a web service, select Web Services Configuration, OK, and press the default operation of the wizard;

3, test the AXIS project. Compile AXISOUR project, select Tour / root directory / index.html, select: Web Run for "Web Services Server", where Web Services Server refers to the name of Web Services, if you are in front of the wizard second step Entered other names, here you should display the name you entered;

4. Click on the link in Index.html if it is entirely executed, indicating that your AXIS is working properly. Special attention is "Validate" link:

5. Test completion begins writing AXIS's server-side program, build a defined complex data type Data (Data.java), which must be followed by Java Bean specification. code show as below:

Package com.neusoft.Axistour;

Import java.util.hashmap;

Public class data {

PRIVATE STRING Author = NULL;

Private string address = null;

Private hashmap hmap = null;

Public Data () {}

Public string getaddress () {

Return Address;

}

Public void setaddress (String address) {

THIS.ADDRESS = Address;

}

Public string getaouthor () {

Return Author;

}

Public void setaouthor (string author) {

THIS.AUTHOR = Author;

}

Public Hashmap gethmap () {

Return HMAP;

}

Public void setmap (havehmap map) {

THIS.HMAP = Map;

}

}

6. Create an AXIS service class, DataServices.java

Package com.neusoft.Axistour;

Import java.util.hashmap;

Public class dataservices {

Public Data BuildData (String ADDRESS, STRING AOUTHOR) {

Data Data = New Data ();

Data.Setaddress (address);

Data.setaouthor (aouthor);

Hashmap map = new hashmap ();

Map.put ("Key1", "Value1");

Map.put ("key2", "value2");

Map.put ("Key3", "Value3");

Data.SETMAP (MAP);

Return Data;

}

}

7. Select DataServices.java. In the Right-click menu, select Export As A Web Services, press the default wizard, complete the export of Axis, generate deploy.wsdd and WSDL, where deploy.wsdd is critical, and the WSDL file is not here important;

8, here you have completed the AXIS service, compile the entire project, start the web services;

9. Test WSDL if your HTTP port is 8080 (if you don't be 8080, please change it to your native, please visit URL: http: // localhost: 8080 / Tour / Services / Dataservices? WSDL

10. Java client code You can refer to the JUnit test class generated by the wizard, so it will not be explained here. You can run the JUnit Test Class: com.neusoft.Axistour.Generated. DataServicesSserviceTestCase, if it is correct, the test is successful.

11, VB client code, because the custom data type is used, so you can only use the low-end API of the Microsoft SOAP development package, where SOAP Toolkit 2.0, the code is as follows:

Option expedition

Private submmand1_click ()

ON Error Goto Errorhandler

DIM Serializer As SOAPSERIALIALIZER

Dim Reader As SoapReader

DIM Connector As SOAPConnector

Dim Method As String

Dim Dom as msxml2.domdocument30

DIM ELM as ixmldomelementMethod = Trim (Text2.Text)

If Method = "" "

Msgbox "Please enter the method name!"

EXIT SUB

END IF

SET Connector = New httpconnector

Connector.property ("endpointurl") = text1.text

'Connector.Property ("soapaction") = base_soap_action_uri & method

Connector.BeginMessage

Set Serializer = New SOAPSERIALIZER

Serializer.init Connector.InputStream

Serializer.Startenvelope

Serializer.StartBody

Serializer.StartElement method, "" "" "," "

'Parameters of the method

Serializer.StartElement "Address"

Serializer.writeString "Dalian"

Serializer.enDelement

Serializer.StartElement "aouthor"

Serializer.writestring "Neusoft"

Serializer.enDelement

Serializer.enDelement

Serializer.endbody

Serializer.Endenvelope

Connector.endMessage

Set Reader = New SoapReader

Reader.Load Connector.outputStream

IF not reader.fault is nothing then

Msgbox reader.faultstring.text, vbexclamation

Else

Text3.text = reader.dom.xml

END IF

EXIT SUB

Errorhandler:

Msgbox "error:" & Err.Description, vbexclamation

Err.clear

EXIT SUB

End Sub

Private sub flow_load ()

Text1.text = "http: // localhost: 8080 / Tour / Services / DataServices? WSDL"

TEXT2.TEXT = ""

TEXT3.TEXT = "" "

End Sub

12, VC code, build a Win32 Console Application:

#include "stdafx.h"

#include

#import "msxml3.dll"

USING NAMESPACE MSXML2;

/ / Modify the path specified in the following statement according to the situation of your machine

#import "c: / program files / compon files / mssoap / binaries / mssoap1.dll" /

Exclude ("iStream", "ISEquentialStream", "_large_integer", / /

"_Ularge_integer", "tagstatstg", "_filetime") Using Namespace MSSOAPLIB;

Void AxistourClient () {

Isoapserializerptr serializer;

IsoapReaderptr Reader;

IsoapConnectorptr Connector;

// Sub-join Services

Connector.createInstance (__ uuidof (httpconnector);

Connector-> Property ["endpointURL"] = "http: // localhost: 8080 / tour / service / dataservices? WSDL";

CONNECTOR-> Connect ();

// Begin Message

CONNECTOR-> BeginMessage ();

// Create The SOAPSERIALIZER

Serializer.createInstance (__ uuidof (SOAPSERIALIZER)

// Connect The Serializer to the Input Stream of the Connector

Serializer-> Init (_variant_t ((iunknown *) connector-> inputstream);

// build the soap message

Serializer-> Startenvelope (",", "" ");

Serializer-> StartBody ("");

Serializer-> StartElement ("BuildData", ",", "");

//parameter

Serializer-> StartElement ("Address", ",", "");

Serializer-> WriteString ("Dalian");

Serializer-> endelement ();

Serializer-> StartElement ("Aouthor", ",", "");

Serializer-> WriteString ("Neusoft");

Serializer-> endelement ();

Serializer-> endelement ();

Serializer-> endbody ();

Serializer-> EndENVelope ();

CONNECTOR-> endMessage ();

Reader.createInstance (__ uuidof (soapreader));

Reader-> Load (_VARIANT_T ((iunknown *) connector-> outputstream), "" "

// Show results

Printf ("Response:% S / N", (const char *) Reader-> DOM-> XML);

}

Int main (int Argc, char * argv [])

{

Coinitialize (NULL);

AxistourClient ();

Couninitialize ();

Return 0;

}

13. You can say that you can say the first step in the AXIS trip.

Last description:

1. In AXIS, there are two ways to serialize custom complex data types into XML. One method is the JavaBean method used in front, using the bean sequence chemical plant provided by AXIS to achieve serialization; another The method is to write sequence chemical plants and anti-sequence chemical plants, which will not be described here. In addition, other Web Service products should also provide these two ways; (Web Service Deployment Descriptor) Generates WSDL, in fact, WSDL is still a core description of Web Services;

3. If the generated WAR package cannot be run in some versions of Tomcat or other web engine, refer to the installation instructions for Axis;

If your program is not running properly, please contact me by MSN: jlzzb@hotmial.com

转载请注明原文地址:https://www.9cbs.com/read-121684.html

New Post(0)