Web service call process

Source: Internet
Author: User
Tags http request soap object model stub

1. Do not call web service through client stub

Suppose we do not want to call a web service through client stub. We can create a lowlevelclient. java file in the simpleservice project and put it into the com. ttdev. ss. lowlevel package:

 

Define the makerequest () method:

 

Run the program file and work properly. This program uses the underlying api called axiom (axis2 object model. In general, it is easier to understand that client stub is not used. However, if you need some special custom operations, you must use axiom to implement them.

2. Check the soap message again.

Next, let's look at the real soap message. How can we see the actual soap message? We need to use a program named "tcp monitor. Its working principle is shown in the following figure. Tell the client to use tcp monitor as the destination of access. When the client needs to send a request message, the message will be transmitted to tcp monitor. Tcp monitor prints the received message to the console and forwards the message to the real destination address (real destination is web service ). When the web service returns a response message, the message is first transmitted to tcp monitor. Tcp monitor responds to a message and forwards the message to the client.

 

As we have discussed the principle above, how can we implement it? Download the binary distribution of tcp monitor. The hypothetical package is tcpmon-1.0-bin.zip. Decompress the package to c: tcpmon. In the command line window, enter the directory c: tcpmonbuild and run the file tcpmon. bat:

 

Note that running the file c: tcpmonbuildtcpmon. bat does not work normally. You must run it in the current folder c: tcpmonbuild. After the program is running, a window appears, entering data as prompted below:

 

Click add to open a new tab page (as shown in the following figure). tcp monitor listens to Port 1234. Select "xml format. This method prints the content of tcp connection (an http request containing a soap request) in xml format.

 

On the client, we need to inform you that the endpoint address is localhost: 1234. For example, in the class file lowlevelclient. java:

    

Code
Public class lowlevelclient {

Public static void main (string [] args) throws axisfault {

Serviceclient client = new serviceclient ();

Options = new options ();

Options. setto (new endpointreference (

Http: // localhost: 1234/axis2/services/simpleservice ));

Client. setoptions (options );

Omelement request = makerequest ();

Omelement response = client. sendreceive (request );

System. out. println (response. tostring ());

}

...

}

 

 

Run the program in tcp monitor and you will see the following message:

 

Similarly, in simpleclient, you can use the specified endpoint address to overwrite the default one:

Public class simpleclient {

Public static void main (string [] args) throws remoteexception {

Simpleservicestub service = new simpleservicestub (

"Http: // localhost: 1234/axis2/services/simpleservice ");

Concatrequest request = new concatrequest ();

Request. sets1 ("abc ");

Request. sets2 ("123 ");

Concatresponse response = service. concat (request );

System. out. println (response. getconcatresponse ());

      }

}

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.