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.
Related
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.
I am a newbie developer to WCF and Windows services. I do know c#. The scenario requires various custom applications running on Windows 7 to call methods in another application. It is a client/server relationship, all running on the same computer. The server must be able to notify each client (one at a time) when a specified condition occurs.
I need to develop the server code only.
Would the following be an acceptable solution:
Make the server a windows service that uses WCF. The server could notify the clients by using a different named pipe for each client ?
Thank you...any suggestions would be appreciated.
Just use duplex communication over tcp/named pipes/msmq/http (WSDualHttpBinding) channel.
AFAIK you need two ports (in/out) for duplex over http
I would ditch wcf altogether. Although as Brian says, you can use the duplex bindings, these are complicated at best.
If it's all going to run on the same computer, why do you even need client/server? Just build a single client which does everything you need.
That is a acceptable solution and should work fine.
Other option for consideration (in the spirit of learning) is creating a Routing Service as an intermediary service which spawns the calls to multiple services. So in your scenario, your client would call the routing service and the routing service will in turn call each of your service
The following link should provide more information on routing service...
[Routing Service][1]
http://msdn.microsoft.com/en-us/library/ee517423.aspx
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
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.
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