Showing posts with label C#. Show all posts
Showing posts with label C#. Show all posts

Thursday, April 21, 2016

WCF REST Service Error "Request Entity too large"

Recently I had this issue in my WCF service, this service was for file upload and download.

in uploading the file, WCF was throwing an error of Request entity too large. later after some searching on net, I have found to change the web.config for webhttpBinding, like below.

<system.serviceModel>

<bindings>
  
<webHttpBinding>
   
<binding
     
maxBufferPoolSize="2147483647"
     
maxReceivedMessageSize="2147483647"
     
maxBufferSize="2147483647" transferMode="Streamed">
   
</binding> 
  
</webHttpBinding>
</bindings>

which worked fine for me.

Wednesday, August 13, 2008

Custom Error Handling in C#


In C# we can handle custom errors by creating a CustomException class Which should be inherited by Exception class. Once the Custom Exception class is ready then in each code use try and catch block. In catch block throw a new exception for you CustomException class. In CustomException class we can write any code or logging information.


here is the Code snippet for Handling Custom Exception.




using System;

using System.Collections.Generic;

using System.ComponentModel;

using System.Data;

using System.Drawing;

using System.Text;

using System.Windows.Forms;

using ErrorHandling;


namespace ExceptionHandling

{

public partial class Form1 : Form

{

public Form1()

{

InitializeComponent();

}


private void button1_Click(object sender, EventArgs e)

{

try

{

int a =GetValue();

}

catch (CustomException ex)

{

MessageBox.Show(ex.Message);

}



}


private int GetValue()

{

try

{

int a = 0;

int b = 4;

int z = (b / a);

return z;


}

catch (Exception ex)

{

throw new CustomException("Devide by zero is a custom Message");

}

}



}


}


namespace ErrorHandling

{


[global::System.Serializable]

public class CustomException : Exception

{

//

// For guidelines regarding the creation of new exception types, see

// http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpgenref/html/cpconerrorraisinghandlingguidelines.asp

// and

// http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dncscol/html/csharp07192001.asp

//


public CustomException() { }

public CustomException(string message) : base(message) { }

public CustomException(string message, Exception inner) : base(message, inner) { }

protected CustomException(

System.Runtime.Serialization.SerializationInfo info,

System.Runtime.Serialization.StreamingContext context)

: base(info, context) { }

}


}




Because we can not handle the custom Error at first level of handling. So this is work around of that. If any body find any such kind of option please add the comment in this article.


Monday, July 7, 2008

Web User control in ASP.NET with AJAX


This is a application which shows that how to get chat data from server without refreshing the page. here in this application i have used ASP.NET framework 1.1 and with XMLHttpRequest object. i have created a Ascx control which you can use for your application to put a chat box at any position of your page.

There could be a better solution for chat box in web application but i found it good.

Downloads


Sunday, July 6, 2008

Code Snippet for Page Heading Comments

Introduction

This article/code snippet is use full in managing your code properly. like every class file should contain any comment about auther ,created date and other things. This Article contain two code snippet one is C# and other one is Vb.Net.

Background

Code Snippet are just xml file which we are using in your coding to display predefine code.

Using the code

every coding file (.cs or .vb) should contain the information about auther,created by namespace and other things.

Copy the attached file for following Locations
.
Location for Vb Code Snippet:
C:\Program Files\Microsoft Visual Studio 8\VB\Snippets\1033\application

Location for C# Code Snippet:
C:\Program Files\Microsoft Visual Studio 8\VC#\Snippets\1033\Visual C#

How to use The Code snippet.
For VB.NET
go to your any .vb page and right click at the top line of page.
then click on Insert Snippet. --> Select Application --> Select "#PageHeader"
then write down all the values mentioned at Snippet literals.
For C#
go to your any .cs page and right click at the top line of page.
then click on Insert Snippet. --> Select Visual C# --> Select "#PageHeader"
then write down all the values mentioned at Snippet literals.
if you still find any problem then feel free to talk with me.