Jean Paul's Blog

There are 2 types of People in the World, One who Likes SharePoint and..

  • Microsoft MVP

  • MindCracker MVP

  • CodeProject MVP

  • eBook on SharePoint 2010

  • eBook on Design Patterns

  • eBook on Windows Azure

  • NLayers Framework @ CodePlex

  • MSDN Forums

  • .Net vs. Java

    Due to Public Demand
  • Advertisements

Posts Tagged ‘wcf’

WCF Large Data Upload Problem and Resolution

Posted by Paul on April 11, 2012

While dealing with large data using WCF services you might have encountered the following error message.


Type: ProtocolException

Message: The remote server returned an unexpected response: (400) Bad Request.

Problem: The message size was exceeded and it resulted in reconstructing the message at server side.  So the incomplete message lead to Protocol Exception.


The solution is to increase the Received Message Size for the service.  Please do the following.

1. Add the following tags inside the service configuration.

  maxReceivedMessageSize=”2147483647″  maxBufferSize=”2147483647″

2. Build the service

3. Update the client consumer with the new service reference


// Interface

namespace WCF_LargeUpload
    public interface IService1
        int Save(DataSet ds);

        DataSet Get();

// Service

namespace WCF_LargeUpload
    public class Service1 : IService1
        public int Save(System.Data.DataSet ds)
            return ds.Tables[0].Rows.Count;

        public System.Data.DataSet Get()
            DataSet ds = new DataSet();
            ds.Tables.Add(new DataTable() { });
            ds.Tables[0].Columns.Add(new DataColumn() { ColumnName = “Id”, DataType = typeof(int) });
            ds.Tables[0].Columns.Add(new DataColumn() { ColumnName = “Name”, DataType = typeof(string) });

            for (int i = 1; i <= 1000; i++)
                ds.Tables[0].Rows.Add(1, “A lengthy Name for the Item”);

            return ds;

// Server Config

<?xml version=”1.0″?>

    <compilation debug=”true” targetFramework=”4.0″ />
        <binding name=”NewServiceBinding”   maxReceivedMessageSize=”2147483647″  maxBufferSize=”2147483647″>
          <readerQuotas maxDepth=”2147483647″ maxStringContentLength=”2147483647″ maxArrayLength=”2147483647″ maxBytesPerRead=”2147483647″ maxNameTableCharCount=”2147483647″/>
          <security mode=”None”>
      <service behaviorConfiguration=”NewServiceBehavior” name=”WCF_LargeUpload.Service1″>
        <endpoint  address=”” binding=”basicHttpBinding” bindingConfiguration=”NewServiceBinding”
          contract =”WCF_LargeUpload.IService1″>

        <behavior name=”NewServiceBehavior”>
          <serviceMetadata httpGetEnabled=”true” />
          <dataContractSerializer maxItemsInObjectGraph=”2147483647″ />
          <serviceDebug includeExceptionDetailInFaults=”true” />
    <serviceHostingEnvironment multipleSiteBindingsEnabled=”true” />
    <modules runAllManagedModulesForAllRequests=”true”/>


// Client Console Application

namespace ConsoleApplication1
    class Program
        static void Main(string[] args)
            Service1Client client = new Service1Client();

            DataSet ds = new DataSet();
            ds.Tables.Add(new DataTable() { });
            ds.Tables[0].Columns.Add(new DataColumn() { ColumnName = “Id”, DataType = typeof(int) });
            ds.Tables[0].Columns.Add(new DataColumn() { ColumnName = “Name”, DataType = typeof(string) });

            for (int i = 1; i <= 1000; i++)
                ds.Tables[0].Rows.Add(1, “abcdefghijklmnopqurstuvwxyzabcdefghijklmnopqurstuvwxyzabcdefghijklmnopqurstuvwxyzabcdefghijklmnopqurstuvwxyz”);

            int result = client.Save(ds);


This post confirms my ownership of the site and that this site adheres to Google AdSense program policies and Terms and Conditions: ca-pub-9482913752970808


Posted in C# | Tagged: , , | Leave a Comment »

Windows Azure – WCF Hosting Methods

Posted by Paul on November 14, 2011

In the previous article we have experimented the ways of WCF hosting in Windows Azure. In this article I would like to summarize the important points of WCF service exposing in Windows Azure.

There are multiple ways of hosting WCF service in Windows Azure.

WCF Hosting


Web Role

Hosted inside IIS with pooling and caching facilities

Worker Role

Self Hosted with more control


Self Hosting, Relayed connectivity through Service Bus

Let us examine them closely.


Method 1: Web Role Hosting

In the Web Role hosting, the WCF service is hosted inside IIS. This will give the advantages of IIS to the WCF service.

  • Identity Management
  • Recycling
  • Caching
  • Pooling
  • Logging

The Service creation will be much easier in this method as Visual Studio provides the templates for Service (.svc files). We need to create a new .svc file and place it in the web role project. The host names and ports are configured by the deployment and we can access the service through a browser.

The metadata end points are also automatically added. This saves a lot of amount of work from the developer side.

Method 2: Worker Role Hosting

Here the developer has to perform more work in creating the service contracts by defining the attributes in the contracts and implementation.

This method is advised if more control is needed over the service. We can easily configure the protocols in this way. In this case a corporate port has to be opened to expose the service while using the worker role.

Method 3: Hosting through AppFabric

In this method the WCF service is exposed through the Service Bus service feature of Windows Azure AppFabric. We can choose this option if we need to connect two disconnected applications.

This method is self hosted and more configurations needed. Here we can connect two disconnected applications using the Service Bus namespace. The namespace identifies the subscription and will be used for billing purposes on the cloud.

The Service Bus provides the following features:

  • Connectivity between disconnected applications
  • Higher Availability

Relay Service

There are two modes of connectivity in the Relay Service.

· TcpRelayConnectionMode.Relayed

· TcpRelayConnectionMode.Hybrid

The default mode is Relayed and here the service and client is connected through the relayed service.

Relayed Mode Connectivity

The following picture depicts the process in the Relayed mode.

The steps involved are following:

Step 1: The WCF Service authenticates and registers with the Relayed Service using the namespace and Provider keys.

Step 2: The Client authenticates with the Relay Service

Step 3: Client invokes a method using the Relay Service

Step 4: The Relay Service redirects the call to the registered WCF service.

Hybrid Mode Connectivity

In the Hybrid way of connectivity the client can communicate directly to the service. First the client connectivity starts as Relayed as usual and then if there is possibility of connecting directly to the service it will be provided.


In this article we have discussed the various WCF exposing methods in Windows Azure like web role, worker role and through AppFabric Service Bus.

Posted in C# | Tagged: , , | Leave a Comment »