Java calls webservice instances

Source: Internet
Author: User

 

Java code

Import java. util. Collections list;

Import java. util. List;

Import java. util. Map;

Import java. util. Vector;

 

Import javax. xml. namespace. QName;

 

Import org. apache. axis. client. Call;

Import org. apache. axis. client. Service;

 

Public class MyWebServices

{

Private String url = "http://www.mxtong.net.cn/GateWay/Services.asmx"; // address that provides the interface

Private String soapaction = "http://tempuri.org/"; // domain name, which is defined on the server

Public MyWebServices ()

{

String userids = "876890 ";

String Account = "admin ";

String Password = "******";

String Phones = "134 *********; 1234 ";

String Content = "hello, this is a test! This is a test! ";

String SendTime = "Maid 16:07:00 ";

String SendType = "1 ";

String PostFixNumber = "1 ";

Service service = new Service ();

Try {

Call call = (Call) service. createCall ();

Call. setTargetEndpointAddress (url );

Call. setOperationName (new QName (soapaction, "DirectSend"); // you can specify the method to call.

Call. addParameter (new QName (soapaction, "UserID"), // set the parameter to be passed

Org. apache. axis. encoding. XMLType. XSD_STRING,

Javax. xml. rpc. ParameterMode. IN );

Call. addParameter (new QName (soapaction, "Account"), // set the parameter to be passed

Org. apache. axis. encoding. XMLType. XSD_STRING,

Javax. xml. rpc. ParameterMode. IN );

Call. addParameter (new QName (soapaction, "Password"), // set the parameter to be passed

Org. apache. axis. encoding. XMLType. XSD_STRING,

Javax. xml. rpc. ParameterMode. IN );

Call. addParameter (new QName (soapaction, "Phones"), // set the parameter to be passed

Org. apache. axis. encoding. XMLType. XSD_STRING,

Javax. xml. rpc. ParameterMode. IN );

Call. addParameter (new QName (soapaction, "Content"), // set the parameter to be passed

Org. apache. axis. encoding. XMLType. XSD_STRING,

Javax. xml. rpc. ParameterMode. IN );

Call. addParameter (new QName (soapaction, "SendTime"), // set the parameter to be passed

Org. apache. axis. encoding. XMLType. XSD_STRING,

Javax. xml. rpc. ParameterMode. IN );

Call. addParameter (new QName (soapaction, "SendType"), // set the parameter to be passed

Org. apache. axis. encoding. XMLType. XSD_STRING,

Javax. xml. rpc. ParameterMode. IN );

Call. addParameter (new QName (soapaction, "PostFixNumber"), // set the parameter to be passed

Org. apache. axis. encoding. XMLType. XSD_STRING,

Javax. xml. rpc. ParameterMode. IN );

Call. setReturnType (new QName (soapaction, "DirectSend"), Vector. class); // data type to be returned (custom type)

// Call. setReturnType (org. apache. axis. encoding. XMLType. XSD_STRING); // (standard type)

Call. setUseSOAPAction (true );

Call. setSOAPActionURI (soapaction + "DirectSend ");

Vector v = (Vector) call. invoke (new Object [] {UserID, Account, Password, Phones, Content, SendTime, SendType, PostFixNumber}); // call a method and PASS Parameters

For (int I = 0; I <v. size (); I ++)

{

System. out. println (v. get (I ));

}

} Catch (Exception ex)

{

Ex. printStackTrace ();

}

}

Public static void main (String args [])

{

MyWebServices pw = new MyWebServices ();

}

}

Author "sljackson"

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.