Ahmet Karakaya
Ahmet Karakaya

Reputation: 10139

Webservice client creation approach

I am using following approaches to create web service client. I could likte to know if connection between client and server is established after creating stub instance like followings. Otherwise Is connection between client and server established after invoking Remote method calling such as stub.xxxmethod(), myervicePort.xxxMetho()

RPC/Encoded
stub = new MyWsRPCPortStub(new URL(), new MyWsRPCLocator());
stub.setTimeout(pdbTimeout);

Document/Literal
MyServicePort myervicePort = service.getMyServicePort();

After learning the above question I am going to decide when stub instance will be created? I mean there will be two ways:

1- create only one stub instance in application ,I mean I will use singleton pattern

2- create stub instance before invoking a method call each time

What if I use only one stub instance with multithread appiication, each thread open difference sockets at the same time while invoking stub.xxMethod()

At the same time T1->stub.xxMethod() T2->stub.xxMethod() T3->stub.xxMethod()

Upvotes: 0

Views: 155

Answers (1)

M..
M..

Reputation: 900

First of all the approcahes you have mentioned to consume web service in a client do not depend on wether the web service style is RPC or Document Literal. The client is the same for both styles. These styles merely determine how the SOAP message exchanged between client and server is structured. A post to get started on it:- here.

Messages are sent between the client and server using the SOAP protocol running over HTTP. Hence the communication between client and server should be mainly looked at as a normal HTTP request/response model rather than when and how the connection between them is established and maintained which is the job of underlying TCP protocol; and the API in the web service client and the underlying OS completely abstract away these details for us.

However if you would like to know when a HTTP request is made by a web service client; you can trace it using any of the packet capture tools like 'wireshark' for example.Typically if you have a web service with just one method; there is usually a HTTP GET request made when you use the Service service = Service.create(url, qname) api and a HTTP POST on YourWSInterface.xxxmethod().

About when to create a stub; in a multithreaded environment; if you are going to use the BindingProvider on the client stubs to set data(and not just mere read only calls) before sending to the webservice; yes; you would need some syhcnronization in the client code(with a single instance) or create a pool of client proxies(multiple pooled instances); depending on the requirements of your app.

I hope i have answered the question.

Upvotes: 1

Related Questions