Host Service to listen Responses from Web Service in UWP - wcf

In UWP I can not host service using ServiceHost class as it is not available.
Can anyone provide any alternative to host a service that implements a contract and listens on a specified URL?
My requirement is to host a service with a URL that implements a contract on which my web service will send responses.

I haven't heard a way in UWP which can host a service with a URL. UWP technology can consume app service, but it cannot create a URL. UWP can also consume WCF service, but it seems you cannot make ServiceHost work as expected( can you explain more about this part? If app service can help you achieve your job, I recommend that you can use app service directly instead of webservice).
So finally what I can think about is to handle network communications in background with the help from backgroundtask and related triggers. Please have a look at the following doc:
Network communications in the background
In short, as the doc has mentioned, it's the following:
"Apps use background tasks and two main mechanisms to maintain communications when they are not in the foreground: The socket broker, and control channel triggers. Apps that use sockets for long-term connections can delegate ownership of a socket to a system socket broker when they leave the foreground. The broker then activates the app when traffic arrives on the socket, transfers ownership back to the app, and the app processes the arriving traffic."
There are some samples which may helpful to you but you need to choose the appropriate sample by your own scenario:
SocketActivityStreamSocket sample
ControlChannelTrigger StreamWebSocket sample
ControlChannelTrigger HttpClient sample

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

Request/response messaging pattern - Azure Service Bus

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

Devicemanager connected clients WCF?

I am working on a web application which acts like a Devicemanager. Clients can register with the devicemanager and connect to the devices that the manager provides.
I was thinking of using a duplex WCF service for the device connection/disconnection.
Is WCF the correct technology to use?
I will need the clients to be constantly registered to be able to connect/disconnect.
Duplex WCF service implements callback function in web services world.
With callback client sends request to server with some kind of reference to its own method that should be called by server when time came. This allows server to communicate with client when server think it is necessary.
You situation contains no need for callback implementation because process is always controlled by client:
Clients can register with the devicemanager
Clients can connect to the devices that the manager provides
So answer for Duplex is NO (if my understanding of your question is correct)
Should you use WCF – YES.
WCF is right technology if you want to set up communication channel between two applications and TCP/IP is too low level for your needs.

Discover locally running WCF from WP7

I have a WCF service running inside Windows Service and it is located on my local network. What I want is to be able to discover WCF from my Silverlight app on my WP7 (on the same network).
I know there a Discovery feature in WCF, however it requires to UDP, which is not supported on WP7. So are there any other ways to discover local WCF?
I also do not know prior to launching WCF the IP address of the WCF service.
The solution I came up with, is to use Sockets as on WP7 they support multicast.
So set up would like this:
Desktop service - Windows Service hosting WCF and small Socket app
which listens on specific port.
WP7 client - before connecting to WCF
a broadcast would be sent using Sockets to find out an IP address of
the machine which runs WCF, when got a response connect to WCF.
For a WCF Service to be referenced in a WP7 project the WCF Service MUST be a BasicEndpoint
You could provide a basic endpoint that exposes a kind of catalog service. It doesn't have to implement UDDI but it could be a custom protocol to suit your needs and return addresses of web services.
This way you only need to know a single address. Of course you can cache returned addresses and query the catalog service only when you are not able to connect.

how to selfhost wcf without iis

Reading up on WCF we have self hosting option available , one limitation here is we have to manage the host process lifecycle ourselves. What I am exploring here is to run the service without IIS and do a self hosting.
Few things come to mind
- How will request management work here. In case of IIS it manages the request and give control to dotnet on a particular thread. In absence of IIS do we need to write code ourselves to manage incoming requests ( say on a tcp port ) or WCF provides some classes to manage request and spawn threads to process each thread.
I am aware that in case of self hosting this needs to be a windows service. In case of self hosting how can me tap on the number of simultaneous requests on the sever , it can be managed by limiting the thread pool ? or we can configure this via wcf ?
Thanks
dc
Self-hosting does not require a Windows service. You can self-host inside a console application if you so desire. It's just that Windows services are a good solution for self-hosting if you require 24/7 access but do not want to, for whatever reason, use IIS.
Managing the lifecycle of the host process is not a big deal. I use a Windows service to host a WCF service. I simply start my WCF service in the OnStart() callback of my Windows service, like so:
private ServiceHost _host;
protected override void OnStart(string[] args)
{
_host = new ServiceHost(typeof(CalculatorService));
_host.Open();
}
Likewise, I close the WCF service in the OnStop() callback of my Windows service:
protected override void OnStop()
{
if (_host != null) _host.Close();
}
This effectively ties the lifecycle of the WCF service to the lifetime of the Windows service. You could do something similar in any kind of application - console, Windows Forms app, etc. For example, in the OnLoad() callback of your Windows Forms app, start the ServiceHost for your WCF service and close it when exiting the app. Simple enough.
WCF gives you a lot of flexibility on how to handle incoming requests. For example, you could make your WCF service a singleton, which means that you'll have one and only one instance of your WCF service. In this case, all incoming requests are handled by this one instance. But you can also have your WCF service handle each incoming request with a new instance of your WCF service. This allows your service to scale better, but will likely require you to synchronize any access to your backend data storage, e.g., database. You can control this behavior using the InstanceContextMode property of the ServiceBehaviorAttribute on your WCF service.
As I read your question again, it sounds like you're just learning WCF, so I hope none of this has overwhelmed you. Check out my answer to this SO question for some links that you may find helpful.
To answer your specific question, the WCF hosting infrastructure will spin up a HTTP listener that works with HTTP.SYS (the same thing IIS uses) which will listen for traffic on the specific port/address you configure.
For any other questions, I'm sure this section in MSDN will answer them.