Wcf call from one method to another method in the same service - wcf

Can a wcf call be made from one service method to another method in the same service, exactly when the first method has returned a response? This is required as i need to trigger a call to an external service once the first call being made by that external service has returned a response back to them. Some kind of a trigger that would initiate a call to them, without them calling my method again.

Related

How to use WCF client within a for loop in C#

I am using a WCF Client to make service calls. I am making multiple calls to the same endpoint within a For-loop, I have specific question on whether I should be reinitializing the client inside for loop every time(with open() and close()) or Should I be doing it outside of loop? Also, How do I handle the exception scenario where the client gets aborted and I have to continue making calls further.
Im not 100% convenced if its a duplicate question.
How to handle WCF connection when calling method in loop
and multiple calls to WCF service method in a loop (using the same proxy object) causing timeout
However, you do not need to reinitialise the client proxy object inside the loop. In your for loop just call the WCF service method.
For the exceptions, I would wrap the WCF Service method call inside the loop into try-catch block and another one to wrap from outside the loop or the method calling this one.
Note: Its only when the the WCF service method is called the conneciton is attamptted to be established and the message is sent across the wire. So captureing the method call inside the loop is recomended.

Fetch data from web Services in android

Currently i am working on an app which require data from web services to update the list View according to that data received. what should i do to fetch that data without letting user know.Should i use Asynchronous Task class or service ,Looking forward to your answers.
Yes, you may use asynchronous task (AsyncTask) to get the data (json) store it in a variable/array and then add it in your listview.
AsyncTask has four steps:
doInBackground: Code performing long running operation goes in this method. When onClick method is executed on click of button, it calls execute method which accepts parameters and automatically calls doInBackground method with the parameters passed.
onPostExecute: This method is called after doInBackground method completes processing. Result from doInBackground is passed to this method.
onPreExecute: This method is called before doInBackground method is called.
onProgressUpdate: This method is invoked by calling publishProgress anytime from doInBackground call this method.
for further details: http://www.compiletimeerror.com/2013/01/why-and-how-to-use-asynctask.html#.UtP-OfQW1QA

Calling a Service in Periodical Intervals

I Want a service call to happen whenever another service was started.
Here is the Scenario. I have a WCF service called abc.svc hosted on IIS. I want a method called "MyMethod" from xyz.svc to get called when abc service is hosted & from then On I want "MyMethod" to trigger at periodic intervals.
Tried calling the "MyMethod" in the Appplcation_start event of abc. But I am getting Endpoint not found exceptiopn when trying to create a serviceclient for the service xyz.svc. Can some one suggest the best solution to this use case.

Force a client to call a method on the service?

I'm wondering if there's any way to force a client to call a specific method on a duplex WCF service. My situation is this, my service implementation is going to keep a collection of subscribers. The problem with this approach is, what if the client doesn't call Subscribe()? I was thinking that in my client interface, I'd have a method called Subscribe, but that doesn't get me anywhere since the code to actually call the service can still be left out of the implementation. Is this possible?
Thanks!
Duplex WCF service uses WCF session so you can mark your Subscribe method with:
[OperationContract(IsInitiating=true)]
void Subscribe();
All other methods will have IsInitiating=false and because of that Subscribe method will have to be the first method called to start a new session. You can also have special method with IsTerminating=true to close the session.

WCF OperationContext

I'm developing a WCF service and if there is an error I want to serialize the incoming parameter from the original method that was called on the service. I am using IErrorHandler to catch all exceptions.
My initial thoughts were that I will store the serialized parameter in OperationContext.IncomingMessageProperties so that I can access it from the HandleError method. However, as this isn't run on the original thread I believe the OperationContext will be null, so I am considering accessing it from the ProvideFault method.
Does this seem feasible? And will it work with OneWay service calls?
Not sure I can really help you much here, but let me try:
on your client, your code basically calls a method and passes it parameters. The WCF stack on the client side then converts that into a SOAP message (typically with an XML body, but could be binary, too) with headers and all and then sends that message across the wire to the server to be processed.
The server then attempts to deserialize that message into an object and attempts to call a message on a server implementation object. That method on the server object will most likely have the same parameters again, as the client - however, there's a possibility that the call will fail before that method even gets called.
So what I'm trying to say is: you can't rely on the fact that your server-side method with its parameters really gets called - there might have been a problem with e.g. authentication, the message format, a missing header or something else, that causes the server side to fail and throw an exception even before the server-side method ever gets called.
In the end, in the IErrorHandler, there's no way I would know of to get a hold of the message and/or the method and its parameters - all you can get are the error that occured on the server, and you can use that to turn it into a SOAP fault.
What you could do - both on the client and the server side - is create a new behavior that plugs into the WCF stack, and that records the methods being called and the parameters being passed into them - by implementing a class that implements the IParameterInspector interface of WCF. But that only will get called if the message on the client and the server will get properly deserialized and the server-side method really gets called.
Check out some of these links for more info on WCF extensibility:
How to: Inspect or Modify Parameters
WCF Extensibility: Parameter Inspectors
IParameterInspector in WCF
Extending WCF with custom behaviors
Hope this helps a bit!
Marc