Using Axis2 to invoke a WebService interface instance (Java) with a username and password

Source: Internet
Author: User
Tags wsdl

There are some interface methods that need to be called by the partner company due to work needs. Adjusted for an afternoon before the tune, write down, to make memo, no nonsense, direct code.

Import Javax.xml.namespace.qname;import Org.apache.axis.client.call;import Org.apache.axis.client.service;public                Class Orderprocessclient {public static int getres (String user,string pwd,string orderno,string xmlstr) { try {//xml address (WSDL end) String endpoint = "HTTP://WC                                       F.V-GROW.COM/ETRADE/ORDERPROCESS.SVC?WSDL ";                    Service service = new service ();                    Call Call Service.createcall ();                    Username Password Authentication call.setusername (user);                    Call.setpassword (PWD);                    Call.getmessagecontext (). Setusername (user);                                            Call.getmessagecontext (). SetPassword (PWD);                    Call.settargetendpointaddress (endpoint);      A: First line targetnamespace value B: Call Method name Call.setoperationname (new QName ("http://tempuri.org/", "Accept");               Call.setusesoapaction (TRUE);                                         The Wsdl:input wsaw:action value Call.setsoapactionuri ("Http://tempuri.org/IOrderProcess/Accept") inside the called method; A: The first line targetnamespace value B: The parameter name must be the same as the parameter name of the. NET setting Call.addparameter (n EW QName ("http://tempuri.org/", "MsgId"), Org.apache.axis.encoding.XMLType.XSD_STRING, Javax.xml.rpc.ParameterMode.OUT)///interface parameter Call.addparameter (new QName ("http://tempuri.org/", "OrderNo"), org.apache.axis.encoding.xmltype.xsd_string,javax.xml.rpc.parametermode.in)///interface parameter Call.addparameter (n EW QName ("http://tempuri.org/", "Xmlstr"), Org.apache.axis.encoding.XMLType.XSD_STRING, Javax.xml.rpc.ParameterMode.IN)///parameters of the interface//set return type Call.setreturnt                        Ype (Org.apache.axis.encoding.XMLType.XSD_INT); Pass a parameter to the method, and call the method int i = (Integer) call.invoke (New Object[]{orderno, xmlstr});             return i;             } catch (Exception e) {e.printstacktrace ();        } return 2;              public static void Main (string[] args) {String user = "username";              String pwd = "password";              String OrderNo = "123";               StringBuilder xmlstring = new StringBuilder ();              Xmlstring.append ("<order orderid= ' 123456 '/>");        System.out.println (Getres (user,pwd,orderno,xmlstring.tostring ())); }}

Jar Package: http://download.csdn.net/detail/xlb744868186/8410873

Using Axis2 to invoke a WebService interface instance (Java) with a username and password

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.