AXIS 粹

xiaoxiao2021-03-06  25

Custom object class

Package WebServicedemo;

/ ** *

Title: *

Description: *

Copyright: Copyright (c) 2003 *

Company: * @ Author not attributable * @version 1.0 * /

Public class cmsbean {private string name = ""; private int userid = 0;

Public string getname () {return name;}

Public void setname (String name) {this.name = name;}

Public int getUserid () {return userid;}

Public void setUserid (int userid) {this.userid = userid;

} The above is a custom user class

Package WebServicedemo.bean;

/ ** *

Title: *

Description: *

Copyright: Copyright (c) 2003 *

Company: * @ Author not attributable * @version 1.0 * /

import webservicedemo.CmsBean; public class ServerBean {private int count = 0; public ServerBean () {} public static void main (String [] args) {ServerBean serverBean1 = new ServerBean (); / * CmsBean temp = new CmsBean (); Temp.setname ("abcd"); temp.setUserid (7); serverbean1.showcmsbean (temp); * /

CMSBean TMP = ServerBean1.getBean (); system.out.println ("#########" (tmp.getuserid ()))); system.out.println ("####### ## " (tmp.getname ()));

Public cmsbean getBean () {cmsbean temp = new cmsbean (); temp.setname ("abcd"); Temp.setUserId (8888); Return Temp;

Public int showcmsbean (cmsbean cmsbean) {count ; system.out.println ("#########" (cmsbean.getuserid ())); system.out.println ("###### ### " (cmsbean.getname ()))); return count;}}

The above is the server-side program code

Package WebServicedemo.bean;

/ ** *

Title: *

Description: *

Copyright: Copyright (c) 2003 *

Company: * @ Author not attributable * @version 1.0 * /

Import org.apache.axis.client.call; import org.apache.axis.client.Service; import org.apache.axis.utils.Options; import org.apache.axis.encoding .Xmltype;

Import javax.xml.namespace.qname; import javax.xml.rpc.ParameterMode;

Import WebServiceDemo.cmsbean;

public class ClientBean {public ClientBean () {} public static void main (String [] args) {ClientBean clientBean1 = new ClientBean (); try {//clientBean1.sendServer (); clientBean1.getServer ();} catch (Exception e ) {E.PrintStackTrace ();}}

public void getServer () throws Exception {String endpoint = "http: // localhost / axis / services / ServerBean"; Service service = new Service (); Call call = (Call) service.createCall (); call.setMaintainSession (true ); QNAME Qn = New QNAME ("URN: CMSBean", "cmsbean"); call.registertypemapping (cmsbean.class, qn, new org.apache.axis.encoding.ser.beanserialfactory (cmsbean.class, qn), New Org.apache.axis.encoding.ser.beandeserializerFactory (CMSBean.class, QN));

Call.SetTargetendPointd Address (new java.net.URL (endpoint)); Call.SetoperationName (New QName ("Serverbean", "GetBean")); Call.setReturntype (New QName ("Serverbean", "GetBean"); cmsbean Result = (cmsbean) Call.invoke (new object [] {}; system.out.println ("#########" (Result.getUserid ())); System.out.Println "#########" (result.getname ()));

Public void sendserver () throws exception {string endpoint = "http: // localhost / axis / service / serverbean"; cmsbean tmp = new cmsbean (); tmp.setname ("abcd"); tmp.setUserID (168);

Service service = new service (); call call = (call) service.createcall (); call.setMainTainSession (TRUE)

QNAME Qn = New QNAME ("URN: CMSBean", "CMSBean");

call.registerTypeMapping (CmsBean.class, qn, new org.apache.axis.encoding.ser.BeanSerializerFactory (CmsBean.class, qn), new org.apache.axis.encoding.ser.BeanDeserializerFactory (CmsBean.class, qn)) ;

Call.SetTargetendPointDress (new java.net.URL (endpoint)); Call.SetoperationName (New QName ("Serverbean", "Showcmsbean"); Call.Addparameter ("Arg1", Qn, ParameterMode.in);

Call.setRetURNTYPE (XMLTYPE.XSD_INT); Integer Result = (Integer) Call.invoke (New Object [] {TMP}; system.out.println (Result.intValue ());

Result = (Integer) Call.Invoke (new object [] {tmp}; system.out.println (Result.intValue ());

}

The above is the client program code

-> above for server-side configuration files where qname =" ns: cmsbean "declared - Web service custom data type

XMLns: ns = "URN: CMSBean" declared -

Name Space / Axis The returned value can be a class. I don't know what this class is to pay attention to. In addition, the parameters can be a class, I don't know how to use 1, this class should pay attention to it. A simple way is that this class is written to comply with the Java Bean specification (mainly GET, SET method), and then pass similar This is registered. Of course, there are additional methods, but this method will be very troublesome, but efficiency may be better, this method To write Serializer Class to implement org.apache.axis.Encoding.Serialize, write Serializer Factory Class to implement org.apache.axis .Encoding.serialzerFactory, write the Deserializer Class and Deserializer Factory Class, and register with the Typemapping element. 2, Creating Type MappingsApache SOAP uses type mappings to determine how Java datatypes should be marshalled to / unmarshalled from XML so that they can be transmitted on / received from the wire. The type mappings are stored in a type mapping registry, with the default registry being org.apache.soap.encoding.SOAPMappingRegistry.Each type mapping carries several pieces of information: a URI describing the encoding style (ie http://schemas.xmlsoap.org/soap/encoding/,) a qualified name (QName) Fer the Java class to act as the deserializer. The Java classes acting as serializers / deserializers must implement org.apache.soap.util.xml.Serializer and org.apache.soap.util.xml.Deserializer, respectively.

To make Life a little Easier, a set of type mappings HAS Been Predefined and Registered Into the soapmappingregistry for the soap encoding style. These include map for the following java types:

most Java primitive types, such as int, float, boolean, byte, etc. and their corresponding wrapper classes (ie java.lang.Integer, java.lang.Boolean, etc.) Java arrays java.lang.String java.util. Date java.util.GregorianCalendar java.util.Vector java.util.Hashtable java.util.Map (under Java editions in which this is supported) java.math.BigDecimal javax.mail.internet.MimeBodyPart java.io.InputStream javax. activation.DataSource javax.activation.DataHandler org.apache.soap.util.xml.QName org.apache.soap.rpc.Parameter java.lang.Object (a deserializer for null objects only) The SOAPMappingRegistry also provides a type mapping to encode org.apache.soap.rpc.Parameters in the literal XML encoding style, and a set of mappings to encode types supported by the IBM XMI Framework in the XMI encoding style.If you want to pass your own objects as parameters to SOAP RPC services ............................................................ .. Ou Will Need To Register The New Type Mappings on Both The Server and The Client Side.

Registering type mappings on the Serverthere Are Two Main Ways to register type mapping information INTO An Apache SOAP SERVER:

Registering them via the deployment descriptor. Overriding the default mapping registry with a registry that has your new type mappings pre-registered. The first way is probably the easiest to implement and manage, but it does require that you replicate the mapping information in each deployment Descriptor That Needs It. for More Information on Registering Type Mapping Information Via a Deployment Descriptor, Look Here.

The second mechanism requires a little more work, but allows you to limit the amount of additional information that you need to put into each deployment descriptor. In addition, the same mapping registry may be used on the client side, and thus may cut down on the amount of additional code that must be written for the client. The new registry must be a subclass of the SOAPMappingRegistry. for information about overriding the default mapping registry, look here.Registering Type Mappings on the ClientAs is the case with the server, on The Client Theree Are Are Also Two Main Ways To Register Type Mapping Information:

Create an instance of the SOAPMappingRegistry and use the mapTypes (...) method to add new mappings. Create an instance of a subclass of the SOAPMappingRegistry that already has your mappings pre-registered. The first way is probably the easiest to do, but If You Have to Use The Same Type Mappings in Multiple Different Clients or if You Are ALSO Implementing The Server-Side As Well, The Second Method May Save You a Little Bit of Coding.

The Bean Serializer / DeserializerIn many cases, even if there is not a default type mapping for the object that you are trying to transmit, you still may not need to create a new serializer / deserializer. Apache SOAP comes with a Java Bean Serializer / Deserializer that may suit your needs. The org.apache.soap.encoding.soapenc.BeanSerializer can be used to serialize and deserialize JavaBeans using the SOAP encoding style. The public properties of the bean will become named accessors (elements) in the XML form. To use the BeanSerializer, simply pass "org.apache.soap.encoding.soapenc.BeanSerializer" as the last two parameters when you are registering the type mapping for your object.Note: The object that you are serializing with the BeanSerializer MUST be a Javabean for this Serializer to Work:

It MUST have a no-args constructor It MUST expose all interesting state through properties It MUST not matter what order the accessors for the properties (ie the setX / getX methods) are in etc. This is NOT a general / all-purpose serializer. It WILL nOT work if the object which you are serializing / deserializing does not conform to the JavaBeans definition. It is nOT a bug if you can not serialize / deserialize your non-Bean, Java class with this, any more than it is a bug that You can't serialize a java.awt.panel with the java.util.date Serializer.

Creating New Serializers and DeserializersIf you need to create a new serializer / deserializer, then looking at the source code for the predefined ones will probably provide you with the best guidance. Remember that they will need to implement org.apache.soap.util.xml .Serializer and org.apache.soap.util.xml.Deserializer respectively. You can implement them both in the same class, or use two different classes, it really makes no difference.Last updated 5/21/2001 by Bill Nagy . If the parameter or return value is arraylist or vector, how to deal with arraylist or vector? 1, SOAP (Simple Object Access Protocol) - - it supports some simple object types. If the calling service is developed with Java, we generally like to use ArrayList or Vector. But as far as my hand: I don't support these two types (** personal opinion **). If you want to re-implement: java2xmlclassname = "org.apache.soap.encoding.soapenc.beanserializer" xml2javaclassname = "org.apache.soap.encoding.soApenc.beanserializer". Change angle consideration: SOAP is independent of language, unrelated to the platform. How to do with the language ---- need to reach a balance point: Various languages ​​support universal data types. Take Delphi as an example, we can't find data types with ArrayList or Vector peer, when we publish services, Delphi cannot be called. We can use arrays. Both languages ​​support.

For example: publishing as follows in Apache SOAP:

Org.apache.soap.server.domfaultlistener

// The location information of the equipment room device is defined below according to the conditions:

< S: Element minoccurs = "1" maxoccurs = "1" name = "user_birth" type = "s: String" /> -> <

S: Element minoccurs = "1" maxoccurs = "1" name = "devicecode" type = "s: string" />

Maxoccurs = "1" name = "deep" type = "s: string" /> < S: Element minoccurs = "1" maxoccurs = "1" name = "pxmin" type = "s: string" /> <

S: Element minoccurs = "1" maxoccurs = "1" name = "pymax" type = "s: string" /> < S: ComplexContent Mixed = "false">

Here: We define Array for transmission data

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

New Post(0)