Have you ever wonder, how do you actually program on the server side to handle the requests by the client? And how do a client know that his uploading request has been complete before proceeding to the another one? There are several approaches for the solution. Here, I introduce how to create WCF (Windows Communication Foundation) web service in Silverlight, which involves lesser code.
How to Create a WCF Web Service:
a) Right-click your ASP.NET website, add the Silverlight-enabled WCF Service template.
b) Create a new method (with the OperationContract attribute)
c) Right-click your Silverlight project -> Add Service. Click Discover button. Then Click OK button.
After you have add a service reference, Visual Studio actually creates a proxy class that you can interface with the Web Service. The proxy class is named after the original Service class name + the world Client at the end.
How to use or call the WCF Web Service:
Import the namespace for the service reference. In Silverlight, all web services are asynchronous. That means after you have called the method to fire it, it returns immediately and proceed to the next line of code. When the response is received, you handle the event inside the MethodNameCompleted.
A standard order of using the web service is as follow:
Service1Client myService = new Service1Client();
myService.BeginUploadCompleted += new EventHandler<System.ComponentModel.AsyncCompletedEventArgs>(myService_BeginUploadCompleted);
myService.BeginUploadAsync(...);
That's all, simple, right?
Silverlight 6 with Free ASP.NET Hosting
Try our Silverlight 6 with Free ASP.NET Hosting today and your account will be setup soon! You can also take advantage of our Windows & ASP.NET Hosting support with Unlimited Domain, Unlimited Bandwidth, Unlimited Disk Space, etc.