How to get events from wcf service loaded by mef to propagate exceptions to host (self-hosted) - wcf

I have a self-hosted WCF service which load its ServiceContracts with MEF. All works fine. I am also able to send error messages to the WCF Client, which is regarding the faults caused by the user. However I also want to capture all the exceptions that can be caused by the service itself and send them to the Windows service that hosts the WCF Services. In the Windows Service I would like to be able to use the logging system to write this exceptions to. I have already tried the example by David Anson. Another solution I came up with was by using MessageQueues, although I don't think it is a nice solution. Has anyone an idea how to solve this? Preferably with an example...

Related

MSMQ to WCF - automatic notification

I have an application that places messages on MSMQ, than I have a WCF service that I want to automatically read these messages from MSMQ.
I do not want to trigger my WCF service but I want it to be notified whenever a message is pushed on MSMQ. I have found some stuff related to WAS and netMSMQBinding, but the details seems a little unclear about automatic notifications from MSMQ to WCF.
Any help/direction in this regard? Thanks.
What is it that you're trying to achieve?
There is really no such thing as "be notified when a message is pushed on MSMQ". MSMQ uses a pull model to retrieve messages from a queue, so there always needs to exist some kind of "listener" that reads messages from the queue and processes them.
In this case, this "listener" is provided by the WCF NetMsmq or MsmqIntegration bindings automatically, so the programming model for a WCF service that is exposed over MSMQ is just like that of a regular one-way service.
As you state, you can either host that WCF service using your own custom host (such as a Windows service), or, in many cases, the preferred method will be to host that service in IIS 7.X/8.X through WAS.
The following sample shows how to host an MSMQ service in WAS: http://msdn.microsoft.com/en-us/library/ms752246(v=vs.110).aspx
Notice that you do need some specific configuration in IIS to be able to host non-HTTP services, which includes enabling the "Non-HTTP Service Activation" feature. The following articles will be useful to get this done:
http://blogs.msdn.com/b/tomholl/archive/2008/07/12/msmq-wcf-and-iis-getting-them-to-play-nice-part-1.aspx
http://blogs.msdn.com/b/tomholl/archive/2008/07/13/msmq-wcf-and-iis-getting-them-to-play-nice-part-2.aspx
http://blogs.msdn.com/b/tomholl/archive/2008/07/14/msmq-wcf-and-iis-getting-them-to-play-nice-part-3.aspx
http://blogs.msdn.com/b/tomholl/archive/2008/05/17/building-a-pub-sub-message-bus-with-wcf-and-msmq.aspx

Developing Wcf Callback service using netTcpBinding

I stuck in a problem regarding wcf Callback service.
I am trying to develop WCF Callback service using netTcpBinding, I successfully created this Callback Service using wsDualHttpBinding but when i try to achive same thing using netTcpBinding, I am always stuck in some problem.
sometimes it is "Contract requires Duplex, but Binding 'BasicHttpBinding' doesn't support it or isn't configured properly to support it."
or "This protocol does not support netTcpBinding"
so anyone can show me how to configure web.config file and how to overcome this types of error..
Thank you.
Without you supplying the code and config that you are currently using it is difficult to tell what is causing this error.
Maybe take a look at Duplex Messaging and TechNet: Creating a Duplex Service.

How do use WCF to communicate between an Application and a Windows Service?

I've gone through some tutorials on creating a WCF service. I'm using Visual Studio 2012. I got a very simple WCF Service Library (vb.net) and Windows Application (vb.net) communicating via WCF. That's a start.
However, my project requires I do the following:
My Windows Service - This is already an application that has it's tasks.
My Application - This is an application that is already developed as well.
I need the service to talk to the application. The service will need to send the following information to the windows application:
Status Updates
Metric Information (mostly integers for counts)
I need the application to send information to the service. It would need to send:
Reload Configuration command
Should be relatively simple, but I've never worked with WCF until today. So I have some questions...
Do I need to re-work my current windows service into a WCF Service?
Since it won't be in IIS, do I also create a WCF Service Library or do I roll this into the windows service somehow?
What is the best way to set up the different types of communication? (i.e., sending over specific metrics and reload commands)
Probably the main question is what components, in addition to my current windows service and application, will I need to make this work?
I hope that was clear :( I think I'm confusing it all... but I hope not
Your Windows service can host the WCF service. Similarly, if you want, your application can host a WCF service. The application could talk to the WCF service in the Windows Service, and the Windows Service's WCF could talk to the one in the application. Depending on the nature of the communication, you could also just use a callback channel to permit the Windows Service's WCF to call back to the application.
I suppose you should configure your WCF windows service to use named pipes. If your windows service is already built then the easiest way to do it would be to build another one as a WCF windows service and wrap the already existing functionality.
Hope I helped!

Creating a restful service in C# hosted by IIS

I want to create a restful web service that can accept json and returns json responses on a Windows server written in C#.
This particular service will actually have a long running background thread, so a WCF service hosted in IIS won't work (as far as I can tell, IIS will stop and restart the service on/after each request).
In general, I do not really even like WCF since I don't like dealing with generating proxy classes and updating service references down the road.
How can I accomplish this?
Well, with respect to WCF, is a technology already proven to help you build robust services, during your software design process you can design the service to keep state, hosting singleton instance, etc, so your impression of WCF services are somehow incomplete.
Now, regarding the restful approach, the technology used nowadays is called Web API, you can see some examples in the following website : http://www.asp.net/web-api , this will help you to avoid the tipical WSDL and generating proxies that you are talking about, and you can have bare-metal RESTful queries like "(http://myapp/orders/?id=1) that could return a json object with the orderid=1
Here you can have info for the instantiating mode in WCF services: http://msdn.microsoft.com/en-us/magazine/cc163590.aspx
hope it helps,

Creating a simple wcf service publishing it to my webhotel, and get it to work

This seems to be a recurring problem to me. I want to get started doing wcf services. I create a new Wcf Service Library, compile it, and publish it using FTP to my providers webhotel. But its not working. I somehow cant get access. I dont want some fancy security model - i just want to get a hole through to my simple webservice. Seems that its the part when i publish it to my webhotel (in a subdomain) that breaks the webservice - its working perfectly when starting it locally.
How to proceed anyone?
Often you need confguration information to host a service. If the service is hosted in IIS, then you need that configuration in web.config. Are you updating Web.config properly? Some hosters don't allow it.
To address this problem you can set up your IIS-hosted WCF service to read its config data from elsewhere.
I wrote a bit about my findings, this solved my issue: http://www.vikingworks.dk/post/WCF-Service-on-hosted-environment.aspx