WCF Silverlight Service Reference - silverlight

I have added a ServiceReference to my Silverlight app. I have called it, WcfServiceReference. I can code the following
using ( var client = new WcfServiceReference.WcfDataServiceClient( ) )
{
client.GetSpendDataTotalAsync( Guid.NewGuid( ) );
}
I was thinking I should be able to reference client.GetSpendDataTotal (not Async), but it isn't available. However, it is in the app - I can find it in my service... Probably something obvious?

Silverlight only allows you to consume WCF services using async methods. The general idea is that synchronous calls to external services tie up the UI thread and leave your app unresponsive until they return. Take a look at this question and this blog post for more discussion on Silverlight and why you're guided into using async service calls. To quote from the blog post, "the whole purpose of the plug-in architecture only permitting async requests is so that plug-ins would not be able to lock up the browser".
Eric Lippert gives an excellent explanation/discussion of the problem of background work tying up the UI thread in this MSDN Magazine article about the upcoming async-await pattern. Definitely worth reading.
The main thing to remember here is that regardless of how much useful work might be happening in the background, if the UI is unresponsive the app is doing nothing as far as the user is concerned. Using asynchronous WCF service calls in Silverlight allows you to do something else with the UI whilst waiting for the result rather than leaving the user wondering why they can't do anything.

Silverlight doesn't allow non-asynchronous calls to services. When you code Silverlight access to WCF services, think Asynchronous.

Related

How to run a SPA with javascript disabled - server side rendering?

We have a website that's running AngularJS 1.*
but one of our main clients are military personnel and they frequently attempt to use the site via Department of Defense computers. These, of course, have javascript disabled.
I've heard of doing server side rendering, but the majority of the examples and research just mention using it for the initial load. We would need the entire site to run off that principle. Essentially acting like an old MVC site. Is this even possible? And I don't mean with just angularJS. Angular 2(5, whatever version we're on now), or react. I just really don't want to back track to .net MVC
Edit: I realize this is, for all intents, a silly question. I was just hoping there was some awesome new tech that had solved the issues that would be present in even attempting this (as stated below, data-binding. I realize this concept completely defeats the purpose of SPAs)
Thanks anyways. I may just delete this question. Didn't have too many expectations to begin with.
This is very possible! Don't let the rest of the people here fool you.
We have a few websites that work just fine with or without JavaScript enabled. My company website https://bitgenics.io is a React app. If you disable your JavaScript the only thing that won't work is the client-side video player.
Now I have no experience with Angular 1 (and I have heard SSR is hard there), but support should be better in the later versions of it.
Getting the GETs to work is the first challenge. But the next one is that you have to have a fallback for your HTTP POSTs. SPAs often use straight REST calls to do any state changes, but you can't do that because it requires JS on the client.
So your forms have to a fallback of a regular FORM post. So you might need some server-side logic to receive these POSTs and respond with a Server-Side Rendered page again.

Should I use Angular for a local only NW.js project?

I want to build a mid-size application using NodeJS and NW.js (formerly known as node-webkit). The application will grab some data from the internet but isn't talking with one special service which is under my control.
Is it a good idea to use AngularJS nevertheless or is the MVC approach of Angular oversized if there isn't neither a database nor a webservice on the controller layer?
I think Angular would be really fine for databinding and GUI handling, but I'm not sure if it's the right approach for this kind of application.
I see no reason not to use Angular in an nwjs project. I do it myself in the app I just finished building. It's a local-only deck tracking app for hearthstone that never communicates over the internet at runtime. It only ever monitors a log file that is generated by the Hearthstone game. Since the way I'm display information to the user is still technically a web page with a full DOM, Angular makes perfect sense since I'm already comfortable using it.

Enhancing my WCF service with asynchronous calls?

I am currently developing a WCF service in a windows form application. There would be a simple GUI screen with 2 buttons, "Start" and "Stop". Whenever I attempt to start the service, the UI of the application would temporary hangs until it loads finish. Is it possible to add a loading effect to it? And how can I do that.
Still pretty new in this area. Would welcome any comments!
Is there any good tutorials out there that teaches how can I enhance this issue?
I have read the MSDN blog tutorial from Rick Rainey Making asynchronous service calls from a WinForm client but it is not really that of a good tutorial.
Just to clarify, my WCF service is a publish subscribe framework and I think I do not need to be able to call the operations asynchronously. All I want to know is how do I initiate the connection asynchronously.
Is it possible to add a loading effect to it? And how can I do that.
For this you can use duplex service contract.
Also, since your application is a subscription application you might want to look into pushing data to your application from the WCF service. Here's a nice example and although it's for Silverlight I think it might be useful to you:
http://weblogs.asp.net/dwahlin/archive/2008/06/16/pushing-data-to-a-silverlight-client-with-wcf-duplex-service-part-i.aspx

Async Calls to Entity Framework

Anyone found a good way to make asynchronous calls to the db via entity framework? Use background worker thread? This is a WPF application.
I know in RIA services there is a loadcompleted event that does not seem to exist in entity framework's object context.
Thanks!
I've written a blog post about async calls via commanding in a WPF application
http://devblog.terminto.com/2010/11/03/threading-as-command-in-mvvm/
At work I use the same technique and do calls to DB (EF4).
Is this useful, or are you asking about more entity framework-specific async methods?

webservice upload and progress

Please help me with this one, I'm not sure what the correct, or best approach is. Basically I have a webservice which takes a byte stream, enabling a c# winform application to upload files to the webservice.
What I need is for the winform to upload in the background one file at a time (using basic multithread, it tries to upload them all at once). I also need to drop in there a progress bar.
How should I do it? Any ideas? I have the feeling it should be fairly straight forward. I think the application should start a new thread for the first file, wait until it's finished then dispose of the thread, create a new one for the next file and so on.
It completely depends on the technology you are using on the client side to access the web service.
If that technology allows for customization of the client proxy to the point where you can intercept transmission of messages (WCF allows this, I can't recall how much the old web services reference does), then you should be able to add your hook to see when the bytes are processed/sent.
Based on bookstorecowboy's comment about using the old "web reference" functionality in .NET, I believe that it generated proxies that derive from the SoapHttpClientProtocol class.
This being the case, I would recommend creating a custom class that derives from the SoapHttpClientProtocol class, overriding the GetWriterForMessage method. In this, you are supposed to return an XmlWriter given the Stream that is passed as a property on the SoapClientMessage parameter.
You would also create a custom class that derives from Stream which takes a Stream instance and forwards all the calls to that instance.
The only difference is that in the Write methods, you would fire an event indicating how many bytes were written.
You would then get the Stream that is exposed on the SoapClientMessage passed to the GetWriterForMessage and wrap it in your custom Stream implementation. You would also connect your event handlers here as well.
With that stream, you would create the XmlWriter and return it.
Then, for your proxies, you would use this new class that derives from SoapHttpClientProtocol and have the proxies derive from that.
As for ASP.NET 2.0 web services ("Old web services ") you could add web services extension to alter and extend it's behavior .
You could also add custom Http module .
It allows you aceess up to the stream level .
see Soap Extensions,Http Modules

Resources