Call ASMX or WCF service from another WCF service - c#

I have a windows service (WCF service with Windows authentication and netTCPBinding) which is consumed by WPF application. Now, I have a requirement to call another service hosted on separate machine (it can be ASMX or WCF service) from my windows service.
I would like to know
a) Is it the correct practice to call one web service from another or should i call it from my WPF application
b) If i have to call this service from my windows service what all things I need to consider and any pitfalls I should be aware of like authentication, bindings.
Any links showing similar implementations will be helpful
Thanks

a) There is no reason you shouldn't but be sure you wrap any errors that can happen in your other service, dot let errors from your downstream service bubble up to your calling (WPF) application.
b) Nothing you wouldn't have encountered in your Calling application, like timeout issues. Make sure your Client to service timeout caters for the timeouts of the service to downstream service.
Also, can I suggest from experience, try and stick to the ChannelFactory pattern http://msdn.microsoft.com/en-us/library/ms734681(v=vs.110).aspx.

Related

What's a general way to provide an emergency mode for a wcf service

I have a iPad which is using WCF service.
The WCF service is loading some background data for every 10 seconds.
Sometimes background loading process fail and all the data and service methods become dysfunctional.
How can I provide a 'kill switch' to take every mobile service method down and provide a brief message (or send a mail) automatically when being called?
Is it possible to implement in the service setting or should I do something else?
If you find your WCF service is in an bad state, you can call HttpRuntime.UnloadAppDomain. See also Recycling WCF Web Service on IIS

Call a WCF Service from client side

I am going to create a WCF service(IIS host) and it will be called from client side javascript code.
When I call a WCF from client side, is the WCF a WCF library or WCF application type?
For example:
I have the javascript below.
function AddFunds() {
var postObject = {
myID: myObject.myIDNumber,
LocationID: myObject.LocationID,
fundsToAdd: CurrencyFormatted($("#txtAddFunds").val())
};
$.post('/OrServices/myService.svc/AddFunds',
JSON.stringify(postObject)
).success(AddFundsResult);
}
In the beginning, I have to create WCF Service "myService.svc", but I am not sure if it is a library or application or doesn't matter.
this answer describes the difference:
A service application includes a website host already setup for you. A service library is a library of services that a host can reference and startup.
If you start with a service library (recommended) you can then choose
any host you wish (a windows service, IIS/ASP.NET, or even a console
application) and you'd just reference your library from your new host.
Choosing a Service Application limits your host to just IIS/ASP.NET
(though this might be ok for your purposes, but will limit the
protocols you can use).
Edit: Changes in IIS since I wrote this allow for a wider variety of
protocols on ASP.NET activated services, so choosing a service
application is much less limiting than before.
if your only going to host in IIS then I would recommend to just use a Service Application. As a lot of the work is done for you.

wcf implementation for interprocess communication

I have developed a .NET UI and windows service which communicate with each other using WCF through the NetNamedPipeBinding protocol. I chose NetNamedPipe because it is the best and efficient choice for interprocess communication on the same machine.
However, one of the key requirements of the application is that the UI should be able to send actions to the windows service and vice versa asynchronously. This means that the windows service should be able to call back the .NET UI application without the need for the .NET UI application to connect to the windows service first.
Keeping this in mind, I have hosted a WCF service in the windows service and a separate WCF service in the .NET UI application so that they can communicate asynchronously without the need to keep the communication channel always alive.
I would like to know if this makes good design sense.
I would appreciate your comments on the same.
Thanks in advance.
Subbu
Hosting another WCF service in the client to receive calls from the main WCF service is not a good idea. You need to use WCF duplex communication (as Subbu posted) aka WCF callback.
WCF: Duplex Operations and UI Threads
The problem with this approach is that your service needs to connect to the client as a host.
A better option would probably be to setup a WCF Callback when you first startup the client. The service can then use the callback for service to client notifications. For details, see this MSDN article which shows using WCF callbacks.
WCF Callback allows server to drive events to the client. See a short and simple example here: A simple WCF Callback example

WCF Service And Windows Service

I have a WCF service which serves as a remote file/folder browser. We also plan on having a Windows Service that will serve as 3 functions.
Windows Service will start the WCF service so it can do its job (part of the same project)
Windows Service will Upload some data to an SQL server every few minutes based on a timer + many other methods like this
WCF will Receive a request to run a method as requested by an asp.net client via WCF and then ask the windows service to run a method and return a result to WCF and pass back the result to ASP.net.
Item 3 is the problem. How is a windows service supposed to talk to a WCF Service (and Vice-Versa) service that both run on the same machine and are essentially the same application running as one. is it over WCF again?
Possibly i am going about this all wrong. Hopefully someone may be able to help
thanks
Damo
WCF Services may be hosted within Windows Services. See http://msdn.microsoft.com/en-us/library/ms750530.aspx. The specific example they give is for a console application, but the same concept applies.
When self hosting, you can eiter specifiy a type that will be instantiated when a client connects to the service , or you pass the instance that your clients will use when they hit the service. In either case, you can instantiate the same class or access the instance passed to ServiceHost to call methods on the service, though they would not go through the WCF pipeline. The WCF Service class can get a reference to the Windows Service class and access methods on that to allow for callbacks to occur without another trip through the WCF stack.
Alternatively, if you do not wish to self-host or your application uses WCF specific calls in the service, you can create a wcf client in the service in the same way as you would on a desktop application. Simply add a service reference as normal and use callbacks to hop back to the Windows Service code.
The first answer is correct.
I'll suggest also consider the following: if you don't have the windows service to host that wcf service, then go on with exposing new one in there. There are other options as well, but those are going lower level, so WCF is the easies and safest option. The same time - its quite elegant solution.

Examples of long-polling in ASP.NET combined with WCF service monitoring?

We have a number of Windows services running in our system (built in C#). We use WCF to communicate with them and control them, since WCF offers very convenient communication with these processes.
Right now in our Windows GUI for managing, monitoring and troubleshooting the services, we simply register callbacks and receive notifications when a message is available from the service. Obviously this application is stateful and WCF provides the ability for the local delegate to be called when the maintained connection to the service indicates.
In our web application which users actually use, we'd like to use long-polling to have a status area on the web page (iframe, AJAX, whatever) which shows any issues which the services are reporting. We'd like to use a long-polling or other technique which minimizes actual polling on the network.
The problem we are running up against is that we need something to make the long-polling HTTP request against which will somehow always be running in IIS and which itself can be WCF-connected to our services and which can convert the event/delegate-based WCF response into a blocking-style long-poll response. It feels like a chicken-and-egg situation that some component in our system is always going to be in a loop, polling - and that's exactly what we are trying to avoid.
Does anyone have an example of doing this?
Well, if your services present with WCF, why not simply consume the WCF services with javsacript? Then you remove your IIS servers from the equation completely. if a user wants to see what the services are doing then they can retrieve the information directly from the service.
Here's a blog with someone showing how to do this:Call wcf service from Json

Categories

Resources