Using web service internally in web service - web-services

What do people generally do when a web service has a bunch of methods and one method wants to use one of the other methods? Calling the method as any other external caller would do seems like a waste of resources.
Eg:
[Web Method]
public BlahObject GetBlah() {
}
[Web Method]
public String Blah2() {
var blah = GetBlah(); // this will involve serializing, deserializing, etc.
}

It depends on where your service resides and the level of decoupling you are expecting.
Also if both the services are in the same hosting environment and if you need to call methods of one service from another frequently - then of course you need to rethink about the granularity of your service design.
Directly calling a service from other service would provide you a highly decoupled solution - but with a performance impact. If all the services under your control - best thing is to design the service interface more carefully to avoid such calls...

I am not familiar with C# but you should be able to call the method directly without going through the web service api.
Even you can re factor your code to have web method separately and function method separately. Then you can call the function methods directly from any method.

Related

Can a service call another service inside its code?

Following is a point mentioned in a presentation slide related to SOA, and it confuses me with the concepts of service orchestration and service choreography. To enable service choreography, shouldn't a web service be able to call another web service?
SOA builds applications out of software services. Services comprise intrinsically
unassociated, loosely coupled units of functionality that have no calls to
each other embedded in them.
In theory, a service can do anything it needs to do to accomplish its job. So there doesn't seem to be a good reason to forbid using a second service to do your work. Why reinvent the wheel?
In practice, the issue is more complicated. If you start calling other services on your own web server, then you'll eventually starve it of resources. At best, "real" clients will have to wait a bit longer for their answers while your web service server plays with itself.
Another issue is recursive loops: Service A calls B calls C calls A calls B ... you get the idea. A small change in one service can introduce such a loop without anyone noticing and it can sit there for a long time until it suddenly kills your server.
That is why you should build micro services in a hierarchy inside the server (i.e. below the web service layer - this is not exposed to clients). Those micro services can use each other in a top-down manner (to avoid the loops). Unit tests then make sure they behave properly.
Lastly, such reuse is very slow. Each HTTP request takes a lot of resources to create, send, parse and process. Calling an internal method directly can be 10 - 10000 times faster.
These are the main reasons why the services exposed by a single server shouldn't reuse each other via the "public client API".
Note: There are web services which build new services by using existing ones. IFTTT - "If This Then That" is one such beast.
You could adopt every concept according to your needs. In my current project we have a separate module that is responsible for the Orchestration. This is required since in real life usage, scenarios can be very complicated. So in order to be close to the actual management of your system, you need to have such one.
Another advantage of this approach is that the Separation_of_concerns is kept. Also aligns the business request with the applications, data, and infrastructure that you have. It defines policies and service levels through automated workflows, provisioning etc.
Orchestration is critical in the delivery of Cloud services too. As they are networked to allow sharing of data-processing tasks, centralized data storage, and online access to services or resources.

Is there an open source project that uses Hoplon and that handles web authentification?

I am looking for something similair to noir-auth-app but made with hoplon.
Thanks!
You can look at some very basic authentication code in the castra-chat demo.
Authentication in Castra is done via annotations on the RPC endpoint functions. These annotations become assertions when the function is called as the endpoint of an RPC call, but not when called from the REPL or from another function. Think of it as a way to inject code into the function only when the function is being called by the client. This architecture has a few benefits:
Authentication becomes a type of precondition on the RPC functions themselves, but since they're implemented as annotations on the functions they are not coupled to the concerns of the RPC functions.
Authentication implemented in this way is turing-complete: any authentication scheme that can be imagined can be implemented in your application directly, as a clojure library. Lisp Can Do It (tm). Just believe :)
You can compose RPC functions without needing to mock state, because only the annotations of the endpoint the client called directly are evaluated.
You can call RPC endpoints in the REPL or from tests without needing to mock state. Of course, if you wish to test the preconditions that's possible from the REPL also.

A lot of calls for to the WebService on the same time in asp.net

I have a .net web method like this:
[WebMethod]
public string HelloWorld1(string emri)
{
return emri;
}
If for example 80 users call this web service in the same time from another platform(andorid application or whatever) what will happen? Is there a possibility for a deadlock or maybe for each user there will be an object using this web service?
What happens in general if there are many calls on the same time for such a web service?
Whole books are written on this subject.
There is no risk of deadlock for your piece of sample code as it simply returns the value that the caller passed in.
Briefly, for a real web service where callers presumably would access some shared resource(s), like databases and such, you would protect those resources with appropriate locking so that two users don't get an opportunity to change the same data at once.

Stateless EJB question

We have a stateless EJB that is behind a webservices (EJB3), this EJB also loads a EntityManager that is passed in calls that it makes. With that I have a question.
Do simultaneous call to the webservice use the same EJB or is there different instances? I ask this especially concerning the use of the EntityManager, which is injected.
Thanks
Is up to the Application server to use the same or different. You may think as if they were different.
Now, if you're injecting it I assume you have it declared as an instance variable, this is a very bad idea for an stateless EJB, because well. It should not have state.
Instead of inject the EntityManager, let the app server do its work, and you just take it from the context. Each method call from a stateless belongs to a transaction and won't interfere with others calls.
In summary: Assume they are different instances, and don't inject your self those kind of objects. Take them from the context where the app server is responsible to leave them.
I hope I've understand properly your question.

Stateful Web Services

I'm building a java/spring application, and i may need to incorporate a stateful web service call.
Any opinions if i should totally run away from a stateful services call, or it can be done and is enterprise ready?
Statefulness runs counter to the basic architecture of HTTP (ask Roy Fielding), and reduces scalability.
Stateful web services are a pain to maintain. The mechanism I have seen for them is to have the first call return an id (basically a transaction id) that is used in subsequent calls. A problem with that is that the web service isn't really stateful so it has to load all the information that it needs from some other data store for each call.