I need notifications (which comes from a WCF service callback) in my web application even when the browser is not opened.
The notification source / event I will get from a WCF service callback from WCF service hosted in the network.
I came across the Web Push API and Service Workers concepts which gives me the intended behavior (notify when even browser is closed).
Push API can send the notification to service worker and then it can process.
Only service worker can get activated even when browser is not opened for notifications.
I doubt whether I can host WCF service for the service callback even when browser is closed in contrast to service workers.
How to achieve this scenario? notifications which I get at WCF service callback in my webapp -> pass to push api -> service worker -> Notification Display.
Related
I am working on a project to improve the performance of WCF service. We have WCF service hosted on IIS server.
I went through various articles to understand the End to End flow from WCF client to request processing by WCF service.
Kindly clarify the below questions:
What happens in IIS when the WCF request comes from the client?
How the IIS identifies the request is for particular WCF service (assume that there are multiple WCF services hosted in the IIS)?
How IIS is delegating the request processing to WCF service?
Who is responsible for creating the WCF service instance?
How the ASP.Net worker threads come into WCF service processing request?
What is the role of Application pool settings in WCF service request processing?
The requests to the WCF service that is hosted on IIS are handled by WAS (Windows Activation Service) which decouples the activation architecture from IIS.
WAS is responsible for processing the requests / response for WCF service.
Here is the high level of what goes on when a http request arrives for a WCF Service hosted on WAS
Requests are first received by the http.sys kernel.
A new WAS service is responsible for configuring application pools,
among other things.
The WWW Service is responsible for activating application pools and
requests queues to process incoming requests. In addition, this
service has a new HTTP Listener Adapter that forwards requests to the
HttpHandler to process the request (without the need for
aspnet_isapi.dll).
Keeping above points in mind, here are the best answers that I can come up with.
Assuming your WCF service is listening on HTTP protocol
1. What happens in IIS when the WCF request comes from the client?
Everything happens in WAS not IIS.
When a protocol listener ( HTTP.sys) picks up a client request, WAS determines if a worker process is running or not. If an application pool already has a worker process that is servicing requests, the listener adapter passes the request onto the worker process for processing. If there is no worker process in the application pool, WAS will start a worker process so that the listener adapter can pass the request to it for processing.
The listener adapter is part of WAS. The request then flows into the worker process’ (w3wp.exe activated by WAS) app domain that has HTTP module and HTTP handler (without the need for aspnet_isapi.dll) that process this request.
2. How the IIS identifies the request is for particular WCF service (assume that there are multiple WCF services hosted in the IIS)?
Its not IIS its WAS that creates a worker process instance (w3wp.exe) and loads application’s code along with other components / network protocols in that worker process. The incomming request has an endpoint address that contains the WCF service name. Also the SOAP message contains the method and the service (class) name which is called by the client. The Channel Dispatchers and Endpoint Dispatchers use this information to activate the class instance and call the target method.
Channel and Endpoint Dispatchers
3. How IIS is delegating the request processing to WCF service?
Again its WAS that delegates the request to particular WCF service which it identifies when the request comes in.
4. Who is responsible for creating the WCF service instance?
Dispatchers are responsible for accepting new channels, receiving messages, operation dispatch and invocation, and response processing. The answer for question # 2 describes this.
5. How the ASP.Net worker threads come into WCF service processing request?
In IIS 7 and later, Windows Process Activation Service (WAS) manages application pool configuration and worker processes instead of the WWW Service.It manages application pools and worker processes for both HTTP and non-HTTP requests.
HTTP Listener adapter is responsible for bridging requests between WAS and ASP.Net worker process. For HTTP requests the adapter is provided by www services (w3svc).
6. What is the role of Application pool settings in WCF service request processing?
All of the applications inside an application pool share a common set of run-time characteristics. For example, they all run under the same version of the common language runtime (CLR) and they all share a common process identity. Each application pool corresponds to an instance of a worker process (w3wp.exe). Each managed application running inside of a shared application pool is isolated from other applications by means of a CLR AppDomain.
Once the request arrives at the ServiceHost process, WCF channel dispatchers picks it up and forward to the particular endpoint dispatchers which intern call the method (endpoint) that is responsible to processes the request.
References:
Learning WCF: A Hands-on Guide By Michele Leroux Bustamante
http://devproconnections.com/net-framework/iis-and-was-hosting-architecture
https://msdn.microsoft.com/en-us/library/ms734677(v=vs.110).aspx
https://msdn.microsoft.com/en-us/library/ms789006(v=vs.110).aspx
https://msdn.microsoft.com/en-us/library/ms734665.aspx
https://www.iis.net/learn/get-started/introduction-to-iis/introduction-to-iis-architecture#WAS
All ,
I have a doubt on the Request response pattern... Assume the following is my scenario
1.I have a service running on Windows Azure. This service can be called by users to execute a command.
2.I have a client applications that is running on my intranet. This client application will execute the command . The computer in which the client application is running is connected to internet , but does not have a static IP i.e machine cannot be accessed directly via the internet
3.I am planning to use Azure Service Bus through which my service on Windows Azure can communicate with the client application to execute....
In this scenario, can i use Request/response messaging i.e can the service post a message and expect a response from the client
OR
Should i use command queue for each client , the Service will push the command to be executed on a queue , the client will poll the queue and execute a command
Any help is appreciated
Since you are using WCF (based on the tag), you should consider using Service Bus Relay calling the WCF service asynchronously.
I assume you want to use Relaybinding here, using WCF.
Your web service (which is behind NAT, firewall devices, etc) is only opening outbound connections in that case. The service is listening on a registered endpoint in the cloud (that is accessible for him, because of credentials and protocol). All incoming service calls are sent over that port/socket. The response will then be sent back over the outgoing port again.
If the IP Address of your service changes, it wil register itself again (by listening on the same registered endpoint) and you can reach that service transparantly.
Another way you can achieve request/response in an asynchronous fashion, is through queues. This does not require any open connection between your client and your service and can happen fully asynchronous. This can be achieved by sending a message to the request queue for your specific service (with a Correlation Id). And when that service has processed that message, it can send the response to the response queue of your application, using sessions. A good example of this pattern can be found on Alan Smith's blog: http://www.cloudcasts.net/devguide/Default.aspx?id=13051
I'd like to build an app based on WCF service and Win8 as presentation layer. I will have messaging capabilities in the app so any user must see updates on the tile (when new messages arrive). As I understand I need to use "Push notifications service" mechanism somehow to update all client s tiles with new arrived messages? How would app work? It should call directly to WCF service and then WCF service should call to push notifications service, or firstly Win8 calls to notification service which calls to WCF? Can somebody clarify me how all this stuff can communicate with each other? Perhaps I should think about WCF Duplex approach? Is it possible to make WCF service to be Push notification service as well?
You can use the
The Windows Push Notification Services (WNS). Your app requests a notification channel. Then it will call the WCF service to send it that channel. The WCF service will send a POST request to the notification channel (which is a URI) in order to notify the app. The data of the request is in XML format (you can read about it in the link).
The Windows Push Notification Services (WNS) enables third-party
developers to send toast, tile, badge, and raw updates from their own
cloud service. This provides a mechanism to deliver new updates to
your users in a power-efficient and dependable way.
It involves these steps:
- Your app sends a request for a push notification channel to the Notification
Client Platform.
- The Notification Client Platform asks WNS to create a notification channel.
This channel is returned to the calling device in the form of a Uniform
Resource Identifier (URI).
- The notification channel URI is returned by Windows to your app.
- Your app sends the URI to your own cloud service. This callback mechanism is
an interface between your own app and your own service. It is your
responsibility to implement this callback with safe and secure web standards.
- When your cloud service has an update to send, it notifies WNS using the
channel URI. This is done by issuing an HTTP POST request, including the
notification payload, over Secure Sockets Layer (SSL). This step requires
authentication.
- WNS receives the request and routes the notification to the appropriate
device.
I've followed the instructions from https://github.com/SignalR/SignalR/wiki/Hubs
entitled "Broadcasting over a Hub from outside of a Hub".
I got this method working from within an MVC Action in the same project. Requesting the Action sends the update to connected clients.
My problem is that I need to be able to send updates from another project, in particular a WCF Web Services project. My app has an API and a web component and when API users make calls that change things, these updates need to be pushed out to the Web clients via SignalR. And calling a web service with the same code as my Test Action doesn't work.
I also tried the same code inside an nunit unit test that didn't work either.
What do I need to do to make this same method described on the Wiki work for a WCF Project?
The easiest solution is probably to provide an API on your Web Application (use MVC or the new WebAPI) that broadcasts to all connected clients. Any other application (an NT Service, an NUnit test, ...) can call that API if it wants to send a message to the clients.
You can't expect SignalR to do anything if you aren't hosting a Hub either in a Web Application running under IIS, or another application hosting it directly.
If you need two-way communication from your separate application to your clients then simply make your application into a SignalR client too and have it communicate via the Web Application hosted SignalR to the clients and have it listen to messages from them too.
For example, here's how I have configured a complex Service + WebSite + Clients solution (ignore the purple for now):
The Live Web Server allows NT Services to connect and create SignalR Groups. NT Services send to those groups. Web browsers connect to a group and receive messages send to that group. In effect the middle box becomes a pubsubhub.
I cannot get exactly what you aim. But if I understood correctly you're trying to send some kind of notifications raised inside WCF services to SignalR clients.
If that's the case; I can suggest you my approach:
I have some WCF services and a SignalR hub in the same application server. IMHO, the best way to communicate WCF with SignalR hub is by using MSMQ.
When a notification occurs inside a WCF service, it puts the notification payload into MSMQ.
On the other end, SignalR hub listens the same queue. When a message put into the queue, it gets the content and broadcasts to the hub clients. Very easy and straightforward. No extra service/hub call at the server side.
SignalR hub can listen for new queue items by using System.Messaging.MessageQueue#ReceiveCompleted method. When this event raised, SignalR hub gets the queue item and broadcasts to its clients.
Can I listen to a WCF event from a web client? Is this possible? I am not talking about call backs, I want the WCF service to raise and event and the web client to be able to listen. Is there a good example of this in C#?
There are no events in WCF. If you want mimic event you still have to call some operation exposed on all clients = you must call WCF service or callback exposed on client.
What do you mean by web client? Do you mean javascript code running in web browser? In such case no you can't achieve that with WCF. You can only use AJAX calls from borowser and continuously poll the service for possible "event".
If you mean ASP.NET application then the answer is theoretically yes, practiacally it will be pretty hard. The reason is that in ASP.NET you handle only current HTTP request by some handler - for example Page. The lifetime of the handler is only for serving the single request. Due to that using duplex service doesn't make to much sense because for receiving callbacks by duplex service your client proxy must live. If you open the proxy in Page it will die after serving the request. If you open the proxy in separate thread you must somehow corelate incomming callbacks to actual client but the client still have to poll the web server to be notified about callbacks. Similar situation will be with exposing the service on ASP.NET application.
Difference between asynchronnous and duplex calls is big. In asynchronnous pattern single request always have single response. Resonse is not sent without request. In duplex pattern you can make single request and receive thousands callback from server.