Showing posts with label WCF. Show all posts
Showing posts with label WCF. Show all posts

Sunday, November 9, 2014

.NET Book : Visual Studio 2013 Expert Development Cookbook

Friends, It gives me immense pleasure to tell you that my new book "Visual Studio 2013 and .NET 4.5 Expert Development Cookbook" has been released few days back. It is the continuation to my previous book "Visual Studio 2012 and .NET 4.5 Expert Development Cookbook" which has released last year. In this post, I will discuss some of the interesting parts of the book and help you understand what exactly you are expected to learn from this book. It has been tremendous effort for last 1 year which let me release this book for you. I hope this book will stand out to your expectation.

After tremendous success on my first book, presenting the next version of the book. Visual Studio 2013 enables you to develop and manage consumer-focused and business-oriented apps. It provides best-in-class tools that propel developers to create new apps or evolve existing ones. In conjunction, .NET 4.5 provides expansive capabilities for developers to work on all forms of apps and services, from client to mobile and from web to cloud, enabling them to focus solely on business logic rather than architecture.

This practical guide teaches you how to work with new changes in technology under the arena of .NET. It provides in-depth analysis and expert advice on various elements of .NET, applying them in code using detailed practical examples, and helping you understand the entire technology in easy, small steps. This book provides solutions to common development problems that you as a developer often face, thereby helping you to adapt the latest technologies as well as get grips on modern app development using .NET 4.5.


Visual Studio 2013 Expert Development Cookbook

What you will learn from this book

  • Get to grips with Visual Studio 2013 IDE and its various components utilizing its tools to debug your code better
  • Get to grips with Visual Studio 2013 IDE and its various components utilizing its tools to debug your code better
  • Understand the Windows Phone 8 development environment and gain practical experience on app development on the platform
  • Create service-oriented applications using WCF and study advanced use cases on implementing a RESTful service with WCF
  • Test your application inside Visual Studio 2013 IDE and advanced use case scenarios to handle testing issues
  • Effectively utilize the various components of Team Foundation Server for better management of code
  • Extend Visual Studio 2013 IDE to add your own custom changes enhancing your experience
  • Discover the advanced usage of cloud computing with Windows Azure and its various components

Tuesday, April 5, 2011

Azure Camp Kolkata on 10th April 2011



  • Entry is Free on First come - First Server Basis.
  • Total Number of seats : 30
  • Attendees need to bring their own laptops with internet connection for Hands - On Labs and access to Windows Azure. Check Laptop Specification.
  • Attendees need to register for free trial for Azure Portal which needs International Credit Card for sign up. Details for this offer is available at http://www.microsoft.com/windowsazure/free-trial/
  • Please visit campaign website to know contest details. http://www.wholeadstomorrow.com/


Schedule

City                    : Kolkata
Date                   : 10th April 2010
Venue                :  Microsoft Corporation (I) Pvt. Ltd. L & T Chambers 4th Floor,
                             16 Camac Street,
                             Kolkata - 700017                    Map

See More about  Venues and Timings


SPEAKERS


Abhishek Sur

Microsoft MVP - Client APP DEV 2011 Codeproject
MVP, Associate | DotNetFunda MVP | Kolkata .NET Star | Writer | Technology Evangelist
| Geek | Speaker
www.abhisheksur.com


Abhijit Jana

.NET Consultant at Microsoft | Former Microsoft
MVP - ASP.NET | CodeProject MVP, Mentor, Insiders| Technology Evangelist | Author
| Speaker | Geek | Husband
www.abhijitjana.net



`For any Query : contact@abhisheksur.com

Be there !!!

Sunday, October 3, 2010

Building a CRUD in RESTful Services of WCF

WCF is being popular day by day. Many of us is building services using WCF and want other application made on different architecture to communicate or inter operate with each other. REST or Representational State Transfer is a Design Pattern to build a service so that it works the same way as service works but it will eventually use Web Request - Response mechanism to communicate between clients rather than using SOAP messages.  In this post, I will give you a step by step approach how you could build your own WCF service using REST.

What is REST ?

REST abbreviated as Representational State Transfer is coined by Roy Fielding is a Design pattern for Networked system. In this pattern the Client invokes a Web request using an URL, so the basic of REST pattern is to generate unique URI to represent data.

If you look into Roy Fielding's quote on REST it says :
"Representational State Transfer is intended to evoke an image of how a well-designed Web application behaves: a network of web pages (a virtual state-machine), where the user progresses through an application by selecting links (state transitions), resulting in the next page (representing the next state of the application) being transferred to the user and rendered for their use."

That means REST is intended for Web applications where the browser invokes each request by specifying unique Uri.

REST Based Services


Download Sample Application - 200KB

Saturday, September 25, 2010

Progress Streamed File download and Upload with Resume facility


For distributed applications, WCF is the most easy and rich component.I like to use WCF as it is very easy to implement and also provides built in functions to handle with Complex problems. One of such interesting thing that I found in WCF is the support for Streaming while sending data from the service.

WCF allows you to send Byte streams through the communication channel or even allows you to implement a service that might take the stream start location from the service call and send the stream from a certain location. It allows you to use normal HttpBinding to support streams which is capable download or upload in connected Client - Server architecture. Hence there will be not timeouts for sending or receiving large files. In this article I will show you how you could use Streaming to ensure your files are downloaded or uploaded correctly.

Once I read Demitris solution for File upload and download it made me very easy to adjust the code and enhance it further with more flexibilities.

Lets first create the service step by step :

Service

  1. Create a Service Application and name it as WCFCommunicationService
  2. The first thing that you need to do in order to create a service is ServiceContract. So once you create a Service Library, you need to delete the existing Service1 and IService1 files from the solution and add a new Interface. 
  3. Create Two method, one for FileDownload and another for FileUpload. Lets see how the service definition looks like :
Contract

[ServiceContract]
public interface IFileTransferLibrary
{

    [OperationContract()]
    void UploadFile(ResponseFile request);

    [OperationContract]
    ResponseFile DownloadFile(RequestFile request);
}

The Contract defines the methods that are exposed to outside. The ServiceContract defines the interface which will have the members which are available to outside. The OperationContract identifies the exposed members. In the above contract the IFileTransferLibrary has two methods, UploadFile which takes an object of ResponseFile and DownloadFile which returns an object of ResponseFile.

[MessageContract]
public class ResponseFile : IDisposable
{
    [MessageHeader]
    public string FileName;

    [MessageHeader]
    public long Length;

    [MessageBodyMember]
    public System.IO.Stream FileByteStream;

    [MessageHeader]
    public long byteStart = 0;

    public void Dispose()
    {
        if (FileByteStream != null)
        {
            FileByteStream.Close();
            FileByteStream = null;
        }
    }
}

[MessageContract]
public class RequestFile
{
    [MessageBodyMember]
    public string FileName;

    [MessageBodyMember]
    public long byteStart = 0;
}

If you see the classes RequestFile and ResponseFile, you will see that I have used MessageContract instead of DataContract for my complex types. It is important. AS I am going to send the data streamed to the client, I need to send the data into packets. DataContract will send the whole object at a time while Messagecontract sends them into small Messages.It is also important to note that I have used IDisposable for ResponseFile to ensure that the Stream is closed whenever the connection is terminated.

Another important note is you need to use Stream as MessageBodyMember. The stream data will always transferred in MessageBody and you cannot add any other member into it. Thus you can see I have put all other members as MessageHeader.

For Both UploadFile and DownloadFile the Stream is taken from the ResponseFile object. The byteStart element of RequestFile ensures from where the the downloading should start and hence helps in Resuming a half downloaded file.  Lets see how to implement this :

public ResponseFile DownloadFile(RequestFile request)
{
    ResponseFile result = new ResponseFile();

    FileStream stream = this.GetFileStream(Path.GetFullPath(request.FileName));
    stream.Seek(request.byteStart, SeekOrigin.Begin);
    result.FileName = request.FileName;
    result.Length = stream.Length;
    result.FileByteStream = stream;
    return result;

}
private FileStream GetFileStream(string filePath)
{
    FileInfo fileInfo = new FileInfo(filePath);

    if (!fileInfo.Exists)
        throw new FileNotFoundException("File not found");

    return new FileStream(filePath, FileMode.Open, FileAccess.Read);
}
public void UploadFile(ResponseFile request)
{
           
    string filePath = Path.GetFullPath(request.FileName);
            
    int chunkSize = 2048;
    byte[] buffer = new byte[chunkSize];

    using (FileStream stream = new FileStream(filePath, FileMode.Append, FileAccess.Write))
    {
        do
        {
            int readbyte = request.FileByteStream.Read(buffer, 0, chunkSize);
            if (readbyte == 0) break;

            stream.Write(buffer, 0, readbyte);
        } while (true);
        stream.Close();
    }
}

If you see the code, you can see how I have used byteStart to start sending Bytes for the file. This ensures the file download to have resume facility. You can also implement the same for UploadFile too.

Download FileTransfer Sample - 161KB

Wednesday, September 15, 2010

How to create a WCF service without Visual Studio

WCF is the first step in building a truly service oriented application for you. It is the most important when working with distributed architecture. The sophisticated design of WCF made me think of using it always when I need any Web service to be installed in the server. Visual Studio is capable of creating its own configuration settings that helps in developing our application with ease. But what if you don’t have Visual Studio? In this post I am going to implement one of the most basic WCF service without using Visual Studio and show you how to interact with the service. Lets do it step by step:

Server Side

Steps to create the Service definition (Contract):

  1. Open Notepad and add namespace System and System.ServiceModel. We need ServiceModel to specify a WCF service
  2. For WCF service we need to create an interface which will act as a proxy to the client.  From the client, we need to replicate the proxy object and build the same interface again. After we declare the Interface we mark the Interface with ServiceContract, and the method to be exposed to outside using OperationContract.
  3. Next we create a concrete class for the same to define the class implementing the interface.
So our server is Ready.

[ServiceContract]
public interface IOperationSimpleWCF
{
    [OperationContract]
    string MySimpleMethod(string inputText);
}

public class OperationSampleWCF : IOperationSimpleWCF
{
    public string MySimpleMethod(string inputText)
    {
        Console.WriteLine("Message Received : {0}", inputText);
        Console.WriteLine(OperationContext.Current.RequestContext.RequestMessage.ToString());
        return string.Format("Message from Server {0}", inputText);
    }
}


Steps to host the service (Address , Binding):

To host the service in the server you need to know three inputs:

  1. Binding : This indicates how the service will be hosted.  For  basic soap operation with no security we need HttpBinding. We can also use other bindings as well.
  2. Address : Represents the location to host the service. When the service is hosted you can specify the qualified service path where the service will be hosted.
  3. Host the service using ServiceHost and Open the connection.
Download Sample Code - 47KB


Author's new book

Abhishek authored one of the best selling book of .NET. It covers ASP.NET, WPF, Windows 8, Threading, Memory Management, Internals, Visual Studio, HTML5, JQuery and many more...
Grab it now !!!