August 21, 2014
Hot Topics:
RSS RSS feed Download our iPhone app

Creating a Service with Windows Communication Foundation and LINQ to SQL

  • August 1, 2008
  • By Paul Kimmel
  • Send Email »
  • More Articles »

Finally, add an Imports statement for your service, create an instance of the service client object, and invoke the service. Listing 4 demonstrates.

Listing 4: Add a reference to the service, create the client wrapper object, and call the method—GetCustomer—defined by the service contract.

Imports CallService.CustomerServiceReference

Module Module1

   Sub Main(

      Dim service As CustomerServiceClient = _
         New CustomerServiceClient

      Console.WriteLine(service.GetCustomer("ALFKI").CustomerName)
      Console.ReadLine()

   End Sub

End Module

I didn't count the number of lines for the whole sample, but it's not very many. What is interetsing is that the example goes from a console client, through a service, to a SQL Server database with very modest effort. The upshot is you get to focus on the problem space and the enhancements to the .NET framework do a lot of the heavy lifting for you.

Note
Updates are supported by sending the Customer back to the service, attaching it to the DataContext, and calling SaveChanges. For roundtrip examples, stay tuned for future articles or pick up a copy of my book LINQ Unleashed for C#. The book is self-explanatory, so VB programmers should be able to decipher the C# code.

Summary

In this article, you touched up generics, extension methods, interfaces, services, LINQ to SQL, SQL Server, and distributed programming but the technical effort on the programmer's part is relatively modest.

Ten years ago, to do the same thing might have taken a week of effort. In .NET 3.5, more of the plumbing is handled by the framework and that's a very good thing.

About the Author

Paul Kimmel is the VB Today columnist for www.codeguru.com and has written several books on object-oriented programming and .NET. Check out his upcoming book LINQ Unleashed for C#; preorder your copy today at Amazon.com. Paul Kimmel is an Application Architect for EDS. You may contact him for technology questions at pkimmel@softconcepts.com.

Copyright © 2008 by Paul T. Kimmel. All Rights Reserved.





Page 3 of 3



Comment and Contribute

 


(Maximum characters: 1200). You have characters left.

 

 


Sitemap | Contact Us

Rocket Fuel