Loading thread for Windows Form Application? - winforms

I am currently developing a windows form application as the subscriber for my WCF service and a asp.net application as the publisher for the service.
Whenever I launch the service or the client, and attempt to "Connect" (AKA subscribe) to the service, it would take awhile to load before it displays a successful message or exception handling. And while the thing "loads", the windows form sort of "hangs" temporary until the thing loads finish.
Is it possible to create a loading effect while they are "loading" to feedback to the user? Anyone can guide me on how to actually start developing this effect.
Thanks!

You can use asynchronous service calls. Before calling the asynchronous call you can show graphical representation of this and in the completion of the asynchronous call you can stop displaying the progress of the call.
Refer to this link to know how you can call the wcf service asynchronously.

Related

Read parameters from Java client in WPF application

I have created WCF service in .net.
It is called by Java client, how do I read parameters when service is being called?
Here is my code:
public string getMethod(string id, string name)
{
string str = name;
return str;
}
Here is my WPF application code, I have added web reference:
WebReference.Service1Soap client = new WebReference.Service1Soap();
string str = client.getMethod(id, name);
How do I read values of "id" and "name" called from Java client?
I am stuck here, please help me please!!
Any help would be greatly appreciated.
Thanks!!
The simplest way:
Run a local instance of the service in debug mode, or attach the visual studio debugger to WCF service host process.
Put a breakpoint in the getMethod() service operation code
Call the service with the java client.
Check the values using a watch or just mouseover.
EDIT.. from comments...
but I have set debug point, still it is not happening
That means that your java client call is not being made successfully. If your java client cannot call the service then you need to sort that out first. Please post a new question to address this, or there are plenty of stuff on google: https://www.google.co.uk/webhp?sourceid=chrome-instant&ion=1&espv=2&ie=UTF-8#q=problem+calling+wcf+from+java
I need those parameter values in WPF application and I have to read
it. How to do it?
You can't send a message to a service and then have that data relayed to another client (WPF) unless you use callbacks via a duplex binding like wsDualHttpBinding, which is not a nice solution in my opinion. More reading here: http://www.codeproject.com/Articles/491844/A-Beginners-Guide-to-Duplex-WCF
If your java client needs to call into a WPF then you'll need to use ServiceHost inside your WPF application and host a WCF service from there. Look here for an example: http://blogs.msdn.com/b/brunoterkaly/archive/2013/11/01/wcf-service-hosting-how-to-host-a-wcf-service-from-inside-a-windows-presentation-foundation-application.aspx
EDIT 2
From Java, service client has been made successfully, and it is
getting the response. But how do I read parameters, and is there any
way or code, that "we come to know that .net service is being called".
Then the only thing you can do is either host the WCF service inside your WPF application, or use a duplex WCF binding on the service, and have the WPF application subscribe by registering a callback delegate. This way the service can call back to the client when something happens (a call is made).
Alternatively you could use a shared database which is updated with the call values when the java client makes the call. Your WPF app can then poll or use a SqlDependency to know when the data has changed.

NLog's WebService target: How to sequentially send the requests?

I use NLog's WebService target in Silverlight and run into a problem if the logging service is unavailable.
What happens is that all calls to the logging service hang for a long time until they time out.
This is firstly ugly and secondly problematic in the face of a request limit, which I have under my given circumstances. After the request limit is reached due to several pending logging requests, the application also fails to make requests that are not logging related.
Ideally I'd like a WebService target that sends the requests sequentially, but I can't configure it to do that, can I?
Since I have full control about the logging server I could also move to a different target, but I'd rather have a purely configuration-based solution.
Some time back I implemented a logging target like that for Silverlight. We were using Common.Logging for .NET and it did not support Silverlight. So, we ported part of Common.Logging to Silverlight and implemented a "logging service adapter" to send our logging messages to a logging service. I implemented a logging queue using the producer/consumer pattern. Maybe you will find it useful.
In the end, the project that I was working on when I implemented this didn't go anywhere, so this particular piece of code is not in use.
Using WCF service via async interface from worker thread, how do I ensure that events are sent from the client "in order"

WCF blocking call

I am using WCF DataService I have a method:
[OperationContract]
public List<string> GetAges()
{
return _registrationData.GetAges();
}
on my client side, I instantiate it this way:
_registrationDataServices = new RegistrationDataServiceClient();
it now exposes a delegate
_registrationDataServices.GetAgesCompleted += GetAgesCompleted;
and a function call:
_registrationDataServices.GetAgesAsync()
the problem with this is that the call to the service will be asynchronous and the results comes in the delegate function, I want to be able to call the service and wait (block) until the results come back, how can this be done using WCF ?
I have to use a wcf, because I have a silverlight application that needs data from a database, the WCF is being called from a .NET assembly as my data access layer.
It is a very bad practice to call web service from a Silverlight/WPF application synchronously. The sync call would hang your UI until the web service call has ended, which will cause bad user experience.
However, if you're still up for it, here is a very helpful link.
Don't call it synchronously -- you will block the UI thread. Users usually think their software has crashed if the UI is frozen.
Ideally you would make a modal busy indicator that animates and shows 'progress' while you wait for the call to come back, and it goes away when you receive the Completed event.
Even if you were still convinced that blocking the UI thread was OK in your case, you can't actually call it synchronously! It was designed this way for a reason - go with the flow.

WPF application freezes on first WCF call

I have WPF application that needs to access WCF service at start ( login window ). Each time application runs on Windows 7 it freezes on login until gets a responce from WCF. Is there any way to design this process differently?
It sounds like you need to make your calls asynchronously. Either start the call on a new thread (preferably using a Task), or call the WCF service using an asynchronous design pattern.
Put the WCF call in a background thread
There are two causes for something perceived as "freezing" when carrying out WCF Service Calls:
Calling the service in a synchronous fashion will block your UI thread until the call has completed. This bad and the reason why Silverlight forbids synchronous calls and forces you to follow the Begin/End Async pattern for any kind of RPC - be it WebRequest or WCF Layer. By default the async methods are not generated when adding a service reference to your WPF project but you can turn it on using Configure Service Reference.
The second cause is less obvious. The initial service client instantiation can take almost 3 seconds - even on fast machines. That's why you are well advised to QueueWorkUserItem the proxy instantiation and the BeginXXX call even when using the async pattern.
If you need the response from this service call to start the application, you can use a background thread to call this service and handle the return value. While this thread is consuming the service you can display your window or a splash screen.
If you don't need the retrun value from this service method you can use [OperationContract(IsOneWay=true)] on your service. So that you don't need to worry about threading and stuff.
You're calling a WCF call on the main thread, Therefore it will appear to crash.
You can either, put it in a thread and call it at the start of your app.
Put it in a background process ( if you're in visual studio you can drag this off the tool bar)
You can do threads quite easily by defining a Thread, then defining a threadstart, passing in your login WCF call, and the call thread.start(); and pass in your threadstart you defined.
A background worker is pretty similar, you can put your code in the backgroundWorker1_DoWork() method
Or make your WCF call Async, so it will send off the login response, and your login code will call on the "OnTaskCompleted" method( you could also put it on a new thread as well, but don't really have to)
Try this thread for Async WCF calls
How to make a call to my WCF service asynchronous?

Using ASP.NET session state with Silverlight (PRISM)

The scenario:
I have a PRISM application developed in Silverlight (4), and I'm using a ASP.NET server side application to host several web-services (which, in turn, accesses WCF-services, but that's not really important here). The Silverlight application must be able to call the web services cross-domain (meaning that the web services isn't necessarily on the same server hosting the silverlight application).
The Silverlight application consists of several modules, each accessing the ASP.NET web-services.
I do not have much experience with Silverlight and PRISM, but as far as I can see, this is not a very unusual scenario...
The problem:
My challange is, that when 2 different modules access the web-services, I get 2 new sessions on the web-server. I would have thought that since both modules live on the same HTML-page (and then also in the same browser session), they would get the same session on the web-server...?
I have tried to make the web-service Proxy-client globally available in the container (using Unity), by registering an instance (using Container.RegisterInstance), and then getting this instance whenever a module needs to make a web-service call (using Container.Resolve), but this doesn't seem to help.
However, any calls made within the same module always gets the same session on the server.
Can anyone see what I'm missing here...?
Thanks!
Jon
Looks like I found my own answer.
The problem was that my application was firing multiple web-service calls upon startup (the different PRISM-modules working independently). And when several calls were made before any responses was given from the web-server, no session (and hence no "ASP.NET_SessionId" cookie was provided) back to the client before subsequent calls were made.
My solution was to make sure I make one call (async as always), for example to a simple Ping-like web-service, then hold all other calls to the web-server until this response is back. Then, all subsequent calls are given the same Session on the server (because now they all contain the "ASP.NET_SessionId" cookie in the header).
In pratice, this call is made by the PRISM-shell, and no modules are beeing loaded before I receive the reponse. Then I'm absolutely sure that none of the other modules get trigger-happy before I have a session-state on hand.
Still, if anybody sees any other problems with this solution, I'm more than happy to hear from you.
Thanks!
Jon

Resources