WebService Client SetTimeOut

Source: Internet
Author: User
Tags wsdl

One: The client generated by eclipse, based on axis

Client_sub.getoptions (). Settimeoutinmilliseconds (1000*60);

Client_sub represents a stub object on a client.

such as: Org.apache.axis.client.Call _call=createcall ();

II: Based on Xfire

Service model = new Objectservicefactory (). Create (Taskservice.  Class);

Xfireproxyfactory factory = new Xfireproxyfactory (Xfirefactory.newinstance (). Getxfire ());

Taskservice service = (taskservice) factory.create (model, URL);

Client client =client.getinstance (service);

Client.settimeout (10000);

Client.setproperty (Commonshttpmessagesender.http_timeout, string.valueof (10000));

Client.setproperty (Commonshttpmessagesender.disable_keep_alive, "true");

Client.setproperty (Commonshttpmessagesender.disable_expect_continue, "true");

Another kind

Simpleserviceserviceclient serviceclient= New Simpleserviceserviceclient ();

SimpleService Serviceport = Serviceclient.getsimpleserviceport ();

Httpclientparams params = new Httpclientparams ();

Params.setparameter (Httpclientparams.use_expect_continue, Boolean.false);

Set Connection Timeout

Params.setparameter (Httpclientparams.connection_manager_timeout, 2L);

Set Response timeout

Params.setintparameter (Httpclientparams.so_timeout,2);

Client client = client.getinstance (Serviceport);

Client.setproperty (Commonshttpmessagesender.http_client_params, PARAMS);

System.out.println (Serviceport.concatenate ("Xfire1", "Xfire2"));

Three: Based on CXF

    1, the client of the stub generated in CXF, in the following manner (CXF2.1.1):

  Where Simpleserviceservice is the automatically generated stub class.

Simpleserviceservice srv = new Simpleserviceservice ();

SimpleService Serviceport = Srv.getsimpleserviceport ();

    Timeout setting

Client cl = clientproxy.getclient (Serviceport);

Httpconduit http = (httpconduit) cl.getconduit ();

Httpclientpolicy httpclientpolicy = new Httpclientpolicy ();

Httpclientpolicy.setconnectiontimeout (10000);

Httpclientpolicy.setreceivetimeout (1000);

Http.setclient (Httpclientpolicy);

Serviceport.concatenate ("111", "2222");

Quad: JAX-ws

//3,JAX-WS clients: Also use CXF's clientproxy to control HTTP connections:

URL wsdlurl = new URL ("file:///D:/JAVAWorkspace/Repository/prjCXFWS/src/wsdl/prjCXFWS.wsdl");

QName serviceqname = new QName ("http://test.cxfws.com/", "Simpleserviceservice");

QName portqname = new QName ("http://test.cxfws.com/", "Simpleserviceport");

Service service = Service.create (Wsdlurl, serviceqname);

//set Handler

Service.sethandlerresolver (new Requestorderhandlerresolver ()); simpleservice port = (simpleservice) service.getport (Portqname, SimpleService.  Class);

  Timeout setting

Client cl = clientproxy.getclient (port);

Httpconduit http = (httpconduit) cl.getconduit ();

Httpclientpolicy httpclientpolicy = new Httpclientpolicy ();

Httpclientpolicy.setconnectiontimeout (10000);

Httpclientpolicy.setreceivetimeout (1000);

Http.setclient (Httpclientpolicy);

System.out.println (Port.concatenate ("Srt1", "Srt2"));

WebService Client SetTimeOut

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.