<! -- [If! Supportlists] --> ③ <! -- [Endif] --> restart the service and enter
Http: // localhost: 8080/ordermgr/control/soapservices/testsoap? WSDL. If you see the service you just released, it means it is successful. For example:
3. write on the client.
Client code writing mainly needs to know what the server wants. First, we can see that the definition of our service class requires one input output, one input, and three outputs, that is, two inputs and two outputs. In the WSDL, we can see that
We need to input a map-map model, and salt and userid are required. Because verification information is not set, login. username and login. Password are optional. The code is better.
During the test, I just made a simple example. Because axiom is complicated, I need to study it in detail. Class description: clientgenricvalue, which encapsulates the type, key, and value of the data to be imported. Clientutil
Package com. wx;
Public class clientgenericvalue {
Private string type;
Private string key;
Private string value;
Public String GetType (){
Return type;
}
Public void settype (string type ){
This. type = type;
}
Public String getkey (){
Return key;
}
Public void setkey (string key ){
This. Key = key;
}
Public String getvalue (){
Return value;
}
Public void setvalue (string value ){
This. value = value;
}
}
Package com. wx;
Import java. util. List;
Import org. Apache. Axiom. om. omw.actfactory;
Import org. Apache. Axiom. om. omelement;
Import org. Apache. Axiom. om. omfactory;
Import org. Apache. Axiom. om. omnamespace;
Import org. Apache. axis2.axisfault;
Import org. Apache. axis2.addressing. endpointreference;
Import org. Apache. axis2.client. options;
Import org. Apache. axis2.client. serviceclient;
Public class clientutil {
Private Static omfactory factory = omdomainactfactory. getomfactory ();
Private string endpoint;
Private list <clientgenericvalue> ValueList;
Private string om;
Private string servicename;
Public clientutil (string endpoint, string servicename, string om,
List <clientgenericvalue> ValueList ){
This. endpoint = endpoint;
This. servicename = servicename;
This. Om = om;
This. ValueList = ValueList;
}
Public serviceclient createclient () throws axisfault {
Serviceclient client = new serviceclient ();
Options = new options ();
Endpointreference targeterp = new endpointreference (endpoint); // define the destination endpointreference, which is the service address.
Options. setto (targeterp );
Options. settimeoutinmilliseconds (400000); // defines timeout, which is not defined here
Client. setoptions (options );
Return client;
}
Public omelement send () throws axisfault {
Omnamespace NS = factory. createomnamespace ("http://ofbiz.apache.org/service/", servicename );
Omelement root = factory. createomelement (servicename, NS );
Omelement DATA = factory. createomelement ("Map-hashmap", null );
Root. addchild (data );
For (clientgenericvalue value: ValueList ){
Omelement mapkey = factory. createomelement ("Map-entry", null );
Omelement keyelement = factory. createomelement ("Map-key", null );
Omelement keyValue = factory. createomelement ("STD-string", null );
KeyValue. addattribute (factory. createomattribute ("value", null, value. getkey ()));
Keyelement. addchild (keyValue );
Omelement valueelement = factory. createomelement ("Map-value", null );
Omelement valuevalue = factory. createomelement (value. GetType (), null );
Valuevalue. addattribute (factory. createomattribute ("value", null, value. getvalue ()));
Valueelement. addchild (valuevalue );
Mapkey. addchild (keyelement );
Mapkey. addchild (valueelement );
Data. addchild (mapkey );
}
System. Out. println (Root );
Omelement result = createclient (). sendreceive (Root );
Return result;
}
Public String getendpoint (){
Return endpoint;
}
Public void setendpoint (string endpoint ){
This. endpoint = endpoint;
}
}
Package com. wx;
Import java. util. arraylist;
Import java. util. List;
Import org. Apache. Axiom. om. omelement;
Import org. Apache. axis2.axisfault;
Public class clienttest {
/**
* @ Param ARGs
* @ Throws axisfault
*/
Public static void main (string [] ARGs ){
String endpoint = "http: // localhost: 8080/ordermgr/control/soapservices/testsoap ";
String servicename = "testsoap ";
String om = "http://ofbiz.apache.org/service ";
List <clientgenericvalue> ValueList = gettestdata ();
Clientutil Cu = new clientutil (endpoint, servicename, OM, ValueList );
Try {
Omelement result = Cu. Send ();
System. Out. println ("sent hello, got:" + result. tostring ());
} Catch (axisfault e ){
// Todo auto-generated Catch Block
E. printstacktrace ();
}
}
Public static list <clientgenericvalue> gettestdata (){
List <clientgenericvalue> ValueList = new arraylist <clientgenericvalue> ();
Clientgenericvalue value1 = new clientgenericvalue ();
Value1.settype ("STD-string ");
Value1.setkey ("userid ");
Value1.setvalue ("11111 ");
Clientgenericvalue value2 = new clientgenericvalue ();
Value2.settype ("STD-string ");
Value2.setkey ("salt ");
Value2.setvalue ("the power of OFBiz ");
// Clientgenericvalue value3 = new clientgenericvalue ();
// Value3.settype ("eeval-orderitemtypeattr ");
// Value3.setkey ("testing ");
// Value3.setvalue ("org. OFBiz. entity. genericvalue"); // This can be left blank
ValueList. Add (value1 );
ValueList. Add (value2 );
// ValueList. Add (value3 );
Return ValueList;
}
}