What is Proxy that is created at the client side - web-services

This is the Documentation from Oracle Docs. I want to clarify certain jargon based questions.
On the server side, the developer specifies the web service operations by defining methods in an interface written in the Java programming language. The developer also codes one or more classes that implement those methods. Client programs are also easy to code. A client creates a proxy (a local object representing the service) and then simply invokes methods on the proxy.
In The first Bold lettered sentence,
Are these classes, the Implementation classes of the Web service ?
Second Bold lettered,
will the client create the object of those service implementation classes? If yes, how come? Will JAX WS transport the complete service implementation class code which is # server to the client?
I am very new to the concept of web services. if my doubt is silly please bear with me. Thanks!

First point. Yes you code the implementation of the web service. However this is just limited to the business logic you wish to execute you don't have to go code the low level boiler plate code like creating a HTTP socket etc.
A simple class that is exposed as a web service will look like this:
#Webservice()
public class CalculatorWS()
{
#WebMethod(#operationame="add")
public int add(#WebParam(name="i") int i, WebParam(name="j") int j)
{
//this is where you code your implementation
return i+ j;
}
}
A client proxy class does NOT transfer the implementation across the wire. It just creates a proxy that you can use to call the implementation.
You can learn all about it step by step by following this tutorial. It is easy one to understand and follow and will answer all of your questions.

Related

C++: Creating Web Services

This is a design suggestion I would like to have from the C++ Web Service experts here.
I'm working on a C++ Windows DLL that currently is used by a exe. The plan is to create a Web Service and expose the functions in the DLL to the web.
From what I researched so far, I came across some libraries that will enable a C++ application to access REST APIs. Buy in my case, Am looking to create a Web Service that will expose the functions in the C++ DLL.
Am looking for something that doesn't involve too much learning curve and can be implemented easily.
Some of the C++ functions currently take vectors as inputs and return a huge vector.
So the capability to input and output large amounts of data is needed. i.e., the exposed Web Service functions should be able to have vectors as arguments passed to it.
Hope to get some valuable suggestions.
Would recommend WCF web service if it's a windows DLL. You can always call C++ functions from C# code.
A simple WCF API will look something like this
[OperationContract]
[WebGet(UriTemplate = "/Test/{name}")]
string Test(string name);
In the *.svc.cs file the implementation goes
public string Test(string name)
{
return "Hello " + name;
}
And to call C++ functions use the dllimport.
Let me know if you need any further help.

C++ wrapper class for C# class calling a web service

So, I've written a web service in c#, which has a method for signing a hash. This web service is a WCF Service application.
Then, I've created a c# Console application where I've written a function to consume this web service.
The declaration of the function which calls the web service is that:
class Program
{
public byte[] callWS(string alias, byte[] myHash,string myPassword)
{
IhashSignSVCClient client = new IhashSignSVCClient();
byte[] signedData= client.SignandReturn(alias, myhash, myPassword);
if (signedData != null)
{
Console.WriteLine(signedData);
return signedData;
}
return null;
}
}
This web service works fine. Now I want to build a c++ wrapper class over this c# method, because I want to call this web service from unmanaged code and I thought that creating a c++ wrapper class will be a good idea. Can anyone help me with a kind of a structure of this wrapper class? I haven't understood very well the conversions between c++ and c#. I've created a C++ CLR class library, with a ref class which will contain my c++ method to call this c# method, but I still have some problems with the type of parameters of this function.
If you want to stick to native (unmanaged) C++ (instead of using C++/CLI), your best option might be WWSAPI as that can call a WCF service directly from C++. Although since it's a C-based API, it's a bit of a nuisance to use from C++.
Otherwise, there is extensive documentation about C++/CLI here; in particular marshaling.

Poco websocket server example

I want to create an application that consists of a web based front-end and a c++ back-end. My choice is to use websocket protocol in order to achieve data transfer between them.Specifically the front end will trigger some measurements that will be done in the back-end and eventually return and store the relevant values in the front-end. I decided for the websocket protocol implementation to use poco library and specifically I came across the following example https://github.com/pocoproject/poco/blob/develop/Net/samples/WebSocketServer/src/WebSocketServer.cpp. However since I haven't totally grasped the factory concept in C++ I haven't figured out the role of class RequestHandlerFactory.Is it possible for someone to explain what is the role of the aforementioned class and regarding my implementation (front-end -> trigger back-end -> back-end do measurements ->back-end returns the value to front-end in order to be depicted in a web-based gui) do I need to make any modifications to make this work for my case ?
As you might have read in the sample, there are two implementations derived from HTTPServer. So depending on the type of connection requested by the client (WebsocketRequest, PageRequest) one can return the appropriate HTTPServer. The work of factory class is to handle the incoming request, decide which class should handle it (depending on the connection requested).
Since you would be requesting to exchange data and not a request to display a HTML document, you should go for WebSocketRequestHandler. Yes it can be done. You might want to remove the PageRequestHandler since you wouldn't be using it.

What is best design pattern for handling rpc requests?

I'm now developing a json-rpc project in C++. I've not decided yet how I handle rpc's requests. From the client side, server receives jsons like below.
{"method":"App1hoge", ...}
{"method":"App1fuga", ...}
{"method":"App2foo", ...}
The server side handles some applications, App1, App2, etc. So I think I should design ApplicationRule class for each class. In this case, App1Rule and App2Rule classes are needed. And I should also design ApplicationRuleManager for handle each rule. But I'm not sure how I design ApplicationRuleManager.
In general, how should I design the relationship between ApplicationRuleManager and each ApplicationRule? Strategy pattern is familiar with this case?
Any help would be appreciated.

Does SOAP have "remote objects"?

SOAP is continuing to confuse me.
In RMI, there are remote objects, which live on the remote server. You can pass them around, but this will just create stubs locally. The stubs delegate all method calls over the wire.
This is quite different from pure data objects, which are serialized and sent as a copy.
Are there remote objects in SOAP? From what I have seen so far (did not dig deep, though), there are complex objects that can be passed around (as arguments or return values), but those are "just" data carriers.
You may find it helpful to read up on the WebServices standards such as WS-I Basic Profile,
which say things like:
SOAP 1.1 defines a message exchange
model for processing of messages.
In other words this is is about passing messages between different systems.
As a client of a SOAP service you have no idea whether or not there are objects at the other end and (at least in common practice) the payloads you receive do not give you back reference objects on which you could invoke further remote messages. For example if you had (in concept)
Order getOrder( int orderId )
and Order looked like
Order { int orderId;
Customer { String name, String TelephoneNumber ... }
}
There Customer "object" there has no methods you invoke that result in remote work.
The SOAP interface has payloads expressed purely in terms of data.
Lanaguge bindings, to enable us to code (for example) Java to invoke a SOAP/HTTP give us local proxies objtecs for the service, but that does not imply an RMI-like remote object model.
Since SOAP is language agnostic, there can't be any remote objects. Which language should be be in?