Application hanging when the WCF client communicating with the server - wcf

I am a beginner with WCF. When I am running the application, it works, but while the client communicates with the server, the application hangs and I can't do anything in the application while it starts communicating. Can you suggest some ideas to rectify this?

Setup an own thread to do the WCF call, one possibility is to use the Thread class, see
http://msdn.microsoft.com/en-us/library/system.threading.thread.aspx
Please note that you have to take special precautions if you process/display result coming back from a WCF call, because this will then be outside of your main UI thread (if you do not use a SynchronizationContext etc...)

The WCF Data Services client API has built in methods to call WCF Data Services asynchronously: http://msdn.microsoft.com/en-us/library/dd756365.aspx

Related

Service fabric and WCF

We are planning to redesign our services to micro services using service fabric, I have some questions that I hope you can help me with, here we go:
Communication Stack
All our services are on WCF using net.tcp so in theory we can reuse the WCF Communication stack but I'm not sure that's the best way, what are the differences between the default communication stack and the WCF one?
Extensibility
We have a lot of implementation using the extensibility points of WCF, if we choose the WCF communication stack can we still use this? We are basically using IServiceBehavior,IOperationInvoker, OperationContext and ServiceSecurityContext for this:
1. Security ServiceSecurityContext/OperationContext to get the IP and if the call is in the intranet the domain account who is making the call, I checked in StatelessServiceContext but could not find any property where i could get this info.
2. Parameters and time IOperationInvoker to log the parameters of the method and how much it took to finish the operation, reading this it appears that if implement the Start/Stop methods the time duration is done automatically, what I'm not sure is if this will work in the context of an attribute and with IErrorHandler when an error happens.
3. Notifications IErrorHandler to log the exception and then send an email to the developer team, we are currently doing this using an SMTP server, is there a better way to send notifications in azure?.
Thanks for your time
Answering this:
Communication Stack
Never did a comparison in performance between the default listener and WcfCommunicationListener but we opted for WCF to reuse all our components and as a first version to understand how service fabric works.
Extensibility
Security All the code worked the same, we needed to make some changes to the way the context works, but all the info needed was there (plus some data on the node it was running)
Parameters and time We used Azure Service Profiler with our own implementation of Microsoft.Diagnostics.Tracing.EventSource capturing the data using IOperationInvoker, awesome
Notifications IErrorHandler continued to work but we used sendgrid for the emails.

WCF Service calling a Java Service. Should it be async?

I currently have an application whereby a user makes a request to my ASP.Net UI, which in turns makes an async call into a WCF service to keep the ASP.net thread free.
The WCF service is essentially a translation module, sat on the restricted network, and bridging the DMZ to the Trusted network. This service calls out to a Java service, which will hit the DB, and I currently have this as a synchronous call.
My WCF services are setup with ConcurrencyMode.Single, and InstanceContextMode.PerCall, so I guess that when I run out of threads on the service host, I'll start backing up requests because the UI is calling async, allowing the user to send multiple requests.
Should I be calling the Java service as an async task, like I do in the UI?
async-await is almost always a good idea. It doesn't really matter which IO you are using (in this case a network call to a java service) as long as it can benefit from treating it as an asynchronous by releasing threads while waiting for IO to complete.
Of course you would get a bigger benefit by also making the java service fully asynchronous, but it isn't necessary.

How to find out the address of multiple clients connected to a WCF duplex service?

I am currently developing a WCF duplex Service for 2 clients. The first client would be an asp.net webpage which upon receiving a posting, it will send the data over to the service. When the service receives the data, it will then AUTOMATICALLY send it to the second client which is a winform app through the callback channel...
To make it simpler.
Asp.net will invoke the wcf
The wcf will reside on the iis server, same as the asp.net
WCF will require to send a data to the windows form application that is running on a client side. Only 1 instance of this application will be run at a time.
Your service should know nothing about the clients attached to it. Doing so pretty much breaks the intention of WCF.
A better solution might be to have your clients subscribe to "events" that your service can fire off. Or maybe the client can provide some information in their requests that indicates a service and method to call back to when needed.

WCF Service - Asynch Operation or Queued Messaging

I have a WCF service hosted as Windows Service with most of its methods currently defined as:
[OperationContract(IsOneWay = true)]
But, now I need to send response back to the calling Web application for these service methods.
Now, because service methods are bit heavy (FYI, they are reporting methods that needs to do mail merge for a no. of records), I am thinking to either queue them or to process asynchronously, so essentially when the request is sent to the service it should save the request to database/queue, returning Request-Id to calling Web application.
In the mean-time, WCF service can just process incompleted requests from the queue or database.
Then either calling Web application can ping WCF service for status of request because it has Request-Id or
WCF service can ping back to calling app when the process corresponding to a Request-Id is completed.
To achieve above, can anyone please guide what changes I need to make to my WCF service (which currently has all one way operation)?
Also, please guide me whether I need to go for Asynch operation or message queuing?
Thank you!
Of course, going Async is simple:
remove the OneWay on the OperationContract in question and regenerate your Service WITH Async methods. There's a reason why Silverlight forces you to use Async operations. They do force you to rethink your UI.

WCF Service to WCF Service Communication

I am trying to create a number of WCF services. These services will expose certain public methods and require to consume each other (i.e. call WCF Service methods from another WCF Service)
Is there any good reference tutorial material that I can refer to for this?
Thanks all in advance!
Consuming a web service in another web service is no different to consuming it in any other client. You create a proxy and make your call so all the general WCF documentation and tutorials will apply.
However, this is usually not a good practice - although sometimes is unavoidable in an SOA. Services must be consumed by clients and they should not call each other unless they have to.
There are a host of problems that can happen. First of all, a service has to wait for the result of a synchronous call from one or more services to return and your service thread will be locked until those calls are finished. If one call takes long, the other service will take long as well and you will have scalability issues.
Let the client call these services. If a call requires data from another service, get the client to make the call and get the data and then make the call again.