Reference article: 76022928
The problem that the parameter cannot be passed to the interface when you call the. NET WebService interface by using the AXIS2 call, find a lot of data, and find a way to implement it.
the correct code is :
Import Org.apache.axiom.om.OMAbstractFactory;
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;
Import java.rmi.RemoteException;
public class Axis2test
{
public static void Main (string[] args) throws RemoteException {
Test ();
}
Public static void Test () throws Axisfault {
try {
String url = "Destination URL";
Options options = new options ();
endpointreference targetepr = new EndpointReference (URL);
Options.setto (TARGETEPR);
options.setaction ("TargetNamespace of the target" + "method name called");//need to add this statement
serviceclient sender = new ServiceClient ();
sender.setoptions (options);
omfactory FAC = omabstractfactory.getomfactory ();
String TNS = "TargetNamespace of the target";
omnamespace omns = Fac.createomnamespace (TNS, "");
Omelement method = Fac.createomelement ("Called Methods Name", Omns);
omelement symbol = fac.createomelement ("parameter name", Omns);
symbol.addchild (fac.createomtext (symbol, "parameter value"));
method.addchild (symbol);
method.build ();
omelement result = Sender.sendreceive (method);
System.out.println (result);
} catch (Axisfault Axisfault) {
axisfault.printstacktrace ();
}
}
}
Detailed steps:
The first step is to add AXIS2 related jar packages, I use MAVEN to manage jar packages
The Pom.xml configuration in Maven is as follows:
<properties>
<!--AXIS2 Begin--
<axis2.version>1.3</axis2.version>
<axiom.version>1.2.5</axiom.version>
<commons-logging.version>1.1.1</commons-logging.version>
<wsdl4j.version>1.6.2</wsdl4j.version>
<XmlSchema.version>1.4.5</XmlSchema.version>
<commons-httpclient.version>3.1</commons-httpclient.version>
<backport-util-concurrent.version>3.0</backport-util-concurrent.version>
<!--Axis2 End--
</properties>
</dependencies>
<!--AXIS2 Begin--
<!--https://mvnrepository.com/artifact/backport-util-concurrent/backport-util-concurrent--
<dependency>
<groupId>backport-util-concurrent</groupId>
<artifactId>backport-util-concurrent</artifactId>
<version>${backport-util-concurrent.version}</version>
</dependency>
<!--https://mvnrepository.com/artifact/commons-httpclient/commons-httpclient--
<dependency>
<groupId>commons-httpclient</groupId>
<artifactId>commons-httpclient</artifactId>
<version>${commons-httpclient.version}</version>
</dependency>
<!--Https://mvnrepository.com/artifact/org.apache.ws.commons.schema/XmlSchema--
<dependency>
<groupId>org.apache.ws.commons.schema</groupId>
<artifactId>XmlSchema</artifactId>
<version>${XmlSchema.version}</version>
</dependency>
<!--https://mvnrepository.com/artifact/wsdl4j/wsdl4j--
<dependency>
<groupId>wsdl4j</groupId>
<artifactId>wsdl4j</artifactId>
<version>${wsdl4j.version}</version>
</dependency>
<!--https://mvnrepository.com/artifact/commons-logging/commons-logging--
<dependency>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
<version>${commons-logging.version}</version>
</dependency>
<!--Https://mvnrepository.com/artifact/org.apache.ws.commons.axiom/axiom--
<dependency>
<groupId>org.apache.ws.commons.axiom</groupId>
<artifactId>axiom</artifactId>
<version>${axiom.version}</version>
</dependency>
<!--Https://mvnrepository.com/artifact/org.apache.axis2/axis2--
<dependency>
<groupId>org.apache.axis2</groupId>
<artifactId>axis2</artifactId>
<version>${axis2.version}</version>
</dependency>
<!--Axis2 End--
</dependencies>
Step Two: Call the WebService interface using the Axis method
/**
* Test Refund processing
* @return
*/
public static void Refundhandle_test2 () {
try {
//Read Ur, namespace, method name
Propertiesutil proputil = new Propertiesutil ("Refundinf.properties") in the configuration file;
Properties pros = proputil.getproperties ();
String WebServiceURL = Pros.getproperty ("WebServiceURL");
String actionstr = Pros.getproperty ("Actionstr");
String actionname = Pros.getproperty ("ActionName");
String url = webserviceurl;
Options options = new options ();
EndpointReference targetepr = new EndpointReference (URL);
Options.setto (TARGETEPR);
Options.setaction (actionstr+actionname);//need to add this statement
ServiceClient sender = new ServiceClient ();
Sender.setoptions (options);
Omfactory FAC = omabstractfactory.getomfactory ();
String TNS = ACTIONSTR;
Omnamespace omns = Fac.createomnamespace (TNS, "");
Omelement method = Fac.createomelement (ActionName, omns);
Omelement symbol = fac.createomelement ("JSON", omns);
JSON string parameter assembly
Jsonobject obj = new Jsonobject ();
Obj.addproperty ("Orgbillno", "201806150939108");
Obj.addproperty ("transaction_id", "" ");
Obj.addproperty ("Hisrefundno", "2018061510081109");
Obj.addproperty ("Total_fee", "0.10");
Obj.addproperty ("Amount", "0.01");
Obj.addproperty ("Paychannel", "ZFB");
String AAA = obj.tostring ();
Symbol.addchild (Fac.createomtext (SYMBOL,AAA));//pass in a parameter value for the specified parameter name
Method.addchild (symbol);
Method.build ();
Omelement result = Sender.sendreceive (method);
SYSTEM.OUT.PRINTLN (result);
} catch (Axisfault Axisfault) {
Axisfault.printstacktrace ();
}
}
This allows the parameters to be passed to the. NET WebService service, which correctly obtains the interface return information
also note that after completing this task, I will try to use AXIS1 and httpclient Try calling the interface method
Axis2 calls the WebService interface implementation of. NET writes, specifying the parameter name