GZip Encoder WCF XmlDictionaryReaderQuotas MaxStringContentLength 8192 Error

 

I used a MessageEncoder from Microsoft samples that you can find on this link.

But when i processed big message it didn't work for an error similar to this:

The maximum string content length quota (8192) has been exceeded while reading XML data. This quota may be increased by changing the MaxStringContentLength property on the XmlDictionaryReaderQuotas object used when creating the XML reader.

I found some solutions but every solutions doesn't work, so I changed code for resolve problem:

Go to file GZipMessageEncodingBindingElement in class GZipMessageEncodingBindingElement, find method ApplyConfiguration and change it as follow:

 

//Called by the WCF to apply the configuration settings (the property above) to the binding element
public override void ApplyConfiguration(BindingElement bindingElement)
{
GZipMessageEncodingBindingElement binding = (GZipMessageEncodingBindingElement)bindingElement;
PropertyInformationCollection propertyInfo = this.ElementInformation.Properties;
if (propertyInfo["innerMessageEncoding"].ValueOrigin != PropertyValueOrigin.Default)
{
switch (this.InnerMessageEncoding)
{
case "textMessageEncoding":
TextMessageEncodingBindingElement encoder = new TextMessageEncodingBindingElement();
encoder.ReaderQuotas.MaxStringContentLength = int.MaxValue;
binding.InnerMessageEncodingBindingElement = encoder;
break;
case "binaryMessageEncoding":
BinaryMessageEncodingBindingElement binEncoder = new BinaryMessageEncodingBindingElement();
binEncoder.ReaderQuotas.MaxStringContentLength = int.MaxValue;
binding.InnerMessageEncodingBindingElement = binEncoder;
break;
}
}
else {
TextMessageEncodingBindingElement encoder = new TextMessageEncodingBindingElement();
encoder.ReaderQuotas.MaxStringContentLength = int.MaxValue;
binding.InnerMessageEncodingBindingElement = encoder;
}
}

It works for text encoding and binary encoding.

Bye

Antonio

Posted 30 December 2009 12:03 AM by antrad | no comments
Filed under:
Setup of CruiseControl.NET with TFS 2005 under a 64bit server

I installed CC.NET under TFS for enable build server for continuous integration. This is my experience…

Used Tools:
CruiseControl.NET (Versione 1.4.2.14) CC.NET
Plugin per CC.NET per TFS (http://www.codeplex.com/TFSCCNetPlugin)
Client TFS Explorer TFS 2005
CC Tray (Client Windows for CC.NET)

Download and install CC.NET (remember version info). Later download plug-in for TFS integration with CC.NET from Codeplex. The only operation required is copying DLL into CC.NET install folder (server). This tool manage getting latest version from TFS.
Later we must change CC.NET configuration file.This is an example:
<cruisecontrol xmlns:cb="urn:ccnet.config.builder">
<project>
<name>Devenv project</name>
<triggers>
<intervalTrigger seconds="60"/>
</triggers>
<modificationDelaySeconds>60</modificationDelaySeconds>
<sourcecontrol type="vsts" autoGetSource="true" applyLabel="true">
<server>http://tfsserver:8080</server>
<project>$/Casillo.SOA</project>
<username>user</username>
<password>password</password>
<domain>mydomain</domain>
</sourcecontrol>
</project>
</cruisecontrol>
In the <sourcecontrol> section we indicate all information about connection to TFS. I used Reflector too because I wanted see all option of this DLL…it uses attributes for map informations.
In my experience I used a 64bit server, in this case we need to force CC.NET for to be execute in 32 bit context. We can do this using this command:
corflags.exe 32bit+ ccnet.exe
from VS 2008 command prompt.
After we need to download TFS 2005 Cliente Explorer, because we will use some DLL for access to TFS. After unzip TFS 2005 client .img file (I used a freeware program called ExtractNow).
Some DLL need to installed under GAC (gacutil /i file.dll under VS command prompt):
Microsoft.TeamFoundation.Client.dll
Microsoft.TeamFoundation.Common.dll
Microsoft.TeamFoundation.Common.Library.dll
Microsoft.TeamFoundation.dll
Microsoft.TeamFoundation.VersionControl.Client.dll
Microsoft.TeamFoundation.VersionControl.Common.dll
Microsoft.TeamFoundation.VersionControl.Common.Integration.dll
Microsoft.TeamFoundation.WorkItemTracking.Client.Cache.dll
Microsoft.TeamFoundation.WorkItemTracking.Client.DataStore.dll
Microsoft.TeamFoundation.WorkItemTracking.Client.dll
Microsoft.TeamFoundation.WorkItemTracking.Client.Provision.dll
Microsoft.TeamFoundation.WorkItemTracking.Client.QueryLanguage.dll
Microsoft.TeamFoundation.WorkItemTracking.Client.RuleEngine.dll
Microsoft.TeamFoundation.WorkItemTracking.Proxy.dll

Now you can use CCTray client for connect to CC.NET. It will work if everything is ok. Now we need to configure CC.NET for build our projects. We can do this using MSBuild, the official building tool from Microsoft used by Visual Studio (pay attention to correct version of MSBuild for .NET Framework 2.0,3.0 or 3.5).
This is a complete example from my experience:
<project>
<name>Example1</name>
<triggers>
<intervalTrigger seconds="240"/>
</triggers>
<modificationDelaySeconds>120</modificationDelaySeconds>
<sourcecontrol type="vsts" autoGetSource="true" applyLabel="true">
<server>http://tfs:8080</server>
<project>$/CA.Example1</project>
<username>user</username>
<password>pwd</password>
<domain>mydomain</domain>
<workingDirectory>C:\WorkingDirectory\example1\</workingDirectory>

</sourcecontrol>
<tasks>
<msbuild>
<executable>C:\Windows\Microsoft.NET\Framework\v3.5\MSBuild.exe</executable>
<workingDirectory>C:\WorkingDirectory\example1workingDirectory>
<projectFile>Example1.sln</projectFile>
<buildArgs> /p:Configuration=Debug</buildArgs>
<targets>Build</targets>

</msbuild>
</tasks>
<publishers>

</publishers>
</project>

I used to build debug configuration and no prebuild or post build task.CC.NET support post build tasks and some other things, you can do the same with VS pre build and post build tasks if you want.
Have fun!
Antonio
Using VS on big projects

I am working on a very large and complex project on a 64bit workstation, I had several problem with Visual Studio at first. I found some tips that I want to share...First of all if you don't need too many features you can start vs in safe mode:

devenv /safemode

in VS command prompt (working on services with WCF this is ok). I disable Resharper too...:(

Later you can use this hack (you can find more in info in Steve Herman's Blog) for improve Visual Studio memory.

This is the procedure:

Windows XP: Backup the boot.ini file and then put the /3GB switch in your boot.ini. (more information on the /3GB option)

Vista: run the following from the Visual Studio command prompt (Brad Rutkowski has the full scoop):

   1:  BCDEDIT /Set IncreaseUserVa 3072

If you are on a 64bit pc this step are not required.

Using the Visual Studio command prompt, navigate to C:\Program Files\Microsoft Visual Studio 9\Common7\IDE\

execute the following command:

   1:  editbin /LARGEADDRESSAWARE devenv.exe

 

Bye 

Antonio

Introduction to TDD,IOC and AOP

Some other slides about other hot topics in ALTNET Community.

Bye 

Antonio

Slides about DDD and ALTNET

 I was speaker in an internal event in my new company (CodeArchitects). We discussed about DDD and ALTNET philosophy.

I posted slides on slideshare.net.

Bye

Antonio

About SQL Server MCTS exam

 Friday I passed exam 70-431 about SQL Server 2005. It was a long exam and different by .NET exams. In fact there are 35 questions and it is not important for final evaluation, I am not sure but it is useful only for to be ready for performace evaluation. Performance evalution is based on 12 simulations. You must resolve simulations with SSMS and arguments are about backups,Linked Servers,triggers,query,CLR Assembly...

If you need more info about contact me.

Tonio

About Repository pattern and Nhibernate

I am working on a new project for an intranet application. I am using NHibernate and DDD. I created a simple Repository structure...It user Windsor IOC container for instance repository (of course you can implement your with LINQToSQL or a Fake repository for testing). This is interface and implementation:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Jobbing.DAL.Repository
{

//Repository Interface
public interface IRepository<T>
{
void Save(T obj);
void Update(T obj);
void Delete(T obj);
T Load<T>(object id);
T GetReference<T>(object id);
void DeleteAll(IList<T> objs);
void UpdateAll(IList<T> objs);
void InsertAll(IList<T> objs);
IList<T> GetAll<T>();
IList<T> GetAllOrdered<T>(string propertyName,bool Ascending);
IList<T> Find<T>(IList<string> criteria);
void Detach(T item);
IList<T> GetAll<T>(int pageIndex, int pageSize);
void Commit();
void Rollback();
void BeginTransaction();
}
}

//Implementation of NHibernate Repository

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections;
using NHibernate;
using NHibernate.Expression;
using NHibernate.Engine.Query;
using NHibernate.Mapping;

namespace Jobbing.DAL.Repository
{
public class NHibernateRepository<T> : IRepository<T>
{
private ISession session;

public NHibernateRepository()
{
//session = NHibernateHelper.GetCurrentSession();
session = NHibernateSessionManager.Instance.GetSession();
session.BeginTransaction();
}

#region IRepository<T> Members

public void Save(T obj)
{
session.Save(obj);
}

public void Update(T obj)
{
session.Update(obj);
}

public void Delete(T obj)
{
session.Delete(obj);
}

public T Load<T>(object id)
{
return session.Load<T>(id);
}

public T GetReference<T>(object id)
{
return session.Get<T>(id);
}

public void DeleteAll(IList<T> objs)
{
for (Int32 I = 0; I < objs.Count; ++I)
{
Delete(objsIdea);
}
}

public void UpdateAll(IList<T> objs)
{
for (Int32 I = 0; I < objs.Count; ++I)
{
Update(objsIdea);
}
}

public void InsertAll(IList<T> objs)
{
for (Int32 I = 0; I < objs.Count; ++I)
{
Save(objsIdea);
}
}

public void Detach(T item)
{
session.Evict(item);
}

internal void Flush()
{
session.Flush();
}

public IList<T> GetAll<T>(int pageIndex, int pageSize)
{
ICriteria criteria = session.CreateCriteria(typeof(T));
criteria.SetFirstResult(pageIndex * pageSize);
if (pageSize > 0)
{
criteria.SetMaxResults(pageSize);
}
return criteria.List<T>();
}

public IList<T> GetAll<T>()
{
return GetAll<T>(0, 0);
}

public IList<T> Find<T>(IList<string> strs)
{
System.Collections.Generic.IList<ICriterion> objs = new System.Collections.Generic.List<ICriterion>();
foreach(string s in strs){
ICriterion cr1 = Expression.Sql(s);
objs.Add(cr1);
}
ICriteria criteria = session.CreateCriteria(typeof(T));
foreach (ICriterion rest in objs)
session.CreateCriteria(typeof(T)).Add(rest);

criteria.SetFirstResult(0);
return criteria.List<T>();
}

//public IList<T> GetByCriteria<T>(IList<ICriterion> objs, int pageIndex, int pageSize)
//{

// ICriteria criteria = session.CreateCriteria(typeof(T));
// foreach (ICriterion rest in objs)
// session.CreateCriteria(typeof(T)).Add(rest);

// criteria.SetFirstResult(pageIndex * pageSize);
// if (pageSize > 0)
// {
// criteria.SetMaxResults(pageSize);
// }
// return criteria.List<T>();
//}

//public IList<T> GetByCriteria<T>(IList<ICriterion> objs)
//{

// return this.GetByCriteria<T>(objs, 0, 0);
//}

public void Commit()
{
if (session.Transaction.IsActive)
{
session.Transaction.Commit();
}
}

public void Rollback()
{
if (session.Transaction.IsActive)
{
session.Transaction.Rollback();
session.Clear();
}
}

public void BeginTransaction()
{
Rollback();
session.BeginTransaction();
}

#endregion

#region IRepository<T> Members


public IList<T> GetAllOrdered<T>(string propertyName, bool Ascending)
{
Order cr1 = new Order(propertyName, Ascending);
IList<T> objsResult = session.CreateCriteria(typeof(T)).AddOrder(cr1).List<T>();
return objsResult;

}

#endregion
}
}

On CodeProject you can find more info about helper for NHibernate and module for Open-Session-In-View.
Bye
Antonio
Posted 25 October 2008 12:51 PM by antrad | 1 comment(s)
Filed under:
Head First Design Patterns: Template Method

 Template Method...here it is:

Defines the skeleton of an algorithm, deferring some steps to subclasses. Template Method lets subclasses redefine certain steps of an algorith without changing the algorithm's structure.


using System;
using System.Collections.Generic;
using System.Text;

namespace TemplateMethod
{
    /// <summary>
    /// Abstract class
    /// </summary>
    public abstract class CaffeineBeverageWithHook
    {
        public void prepareRecipe()
        {
            boilWater();
            braw();
            pourInCup();
            addCondiments();
        }

        public abstract void braw();
        public abstract void addCondiments();

        public void boilWater()
        {
            System.Console.WriteLine("Boiling water...");
        }

        public void pourInCup()
        {
            System.Console.WriteLine("Pouring into cup...");
        }
    }
}


using System;
using System.Collections.Generic;
using System.Text;

namespace TemplateMethod
{
    /// <summary>
    /// Concrete class
    /// </summary>
    public class CoffeeWithHook : CaffeineBeverageWithHook
    {
        public override void braw()
        {
            System.Console.WriteLine("Dripping Coffee through filter...");
        }

        public override void addCondiments()
        {
            System.Console.WriteLine("Adding sugar and milk...");
        }
    }
}


using System;
using System.Collections.Generic;
using System.Text;
using TemplateMethod;

namespace test
{
    class Program
    {
        static void Main(string[] args)
        {
            CaffeineBeverageWithHook obj = new CoffeeWithHook();
            obj.prepareRecipe();
            System.Console.ReadLine();
        }
    }
}

Bye
Antonio
Silverlight free controls

 I am not a fun of client side tecnology but Silverlight is really interesting. Here you can find some free controls.

Bye

Antonio

Head First Design Patterns: Command Pattern

Again Desgin Patterns...

Command Pattern:Encapsulate a request as an object, thereby letting you parametrize clients with different requests,queue,or log requests, and support undoable operations.

Command Pattern in C#:

 

//Command interface
using System;
using System.Collections.Generic;
using System.Text;

namespace Command
{
    public interface ICommand
    {
        void Execute();
    }
}

using System;
using System.Collections.Generic;
using System.Text;

namespace Command
{
    //Concrete Command
    public class LightOffCommand : ICommand
    {

        #region ICommand Members

        public void Execute()
        {
            throw new Exception("The method or operation is not implemented.");
        }

        #endregion
    }
}

using System;
using System.Collections.Generic;
using System.Text;

namespace Command
{
    /// <summary>
    /// Concrete Command
    /// </summary>
    public class LightOnCommand : ICommand
    {
        Light lg;
        public LightOnCommand(Light my)
        {
            this.lg = my;
        }
        #region ICommand Members

        public void Execute()
        {
            this.lg.On();
        }

        #endregion
    }
}


using System;
using System.Collections.Generic;
using System.Text;

namespace Command
{
    /// <summary>
    /// Null command, concrete command
    /// </summary>
    public class NoCommand : ICommand
    {
        #region ICommand Members

        public void Execute()
        {
            System.Console.WriteLine("No command");
        }

        #endregion
    }
}

using System;
using System.Collections.Generic;
using System.Text;

namespace Command
{
    //Receiver
    public class Light
    {
        private string _DescLight="Light";

        public string DescLight
        {
            get { return _DescLight; }
            set { _DescLight = value; }
        }

        public Light(string place)
        {
            this._DescLight = place;
        }
        public void On()
        {
            System.Console.WriteLine(this.DescLight + " is ON.");
        }
        public void Off()
        {
            System.Console.WriteLine(this.DescLight + " is OFF.");
        }
    }
}

using System;
using System.Collections.Generic;
using System.Text;

namespace Command
{
    /// <summary>
    /// Invoker
    /// </summary>
    public class RemoteControl
    {
        ICommand[] onCommands;
        ICommand[] offCommands;

        public RemoteControl()
        {
            this.onCommands = new ICommand[7];
            this.offCommands = new ICommand[7];
            for(int i=0;i<7;i++){
                this.offCommandsIdea = new NoCommand();
                this.offCommandsIdea = new NoCommand();
            }
        }

        public void stCommand(int slot, ICommand on,ICommand off)
        {
            this.onCommands[slot]=on;
            this.offCommands[slot]=off;
        }

        public void onButtonPushed(int slot)
        {
            this.onCommands[slot].Execute();
        }

        public void offButtonPushed(int slot)
        {
            this.offCommands[slot].Execute();
        }
    }
}

Bye 
Antonio
Head First Design Pattern :Decorator

 This is C# code for Decorator. For more info see into book...

 

//Base abstract class
using System;
namespace Decorator
{
    /// <summary>
    /// Base class for Beverage. It represents the Component
    /// </summary>
    public abstract class Beverage
    {
        string _Description;

        public string Description
        {
            get { return _Description; }
            set { _Description = value; }
        }

        public abstract double CalculateCost();
    }
}

//Concrete class
using System;
using System.Collections.Generic;
using System.Text;

namespace Decorator
{
    /// <summary>
    /// Concrete class for Component
    /// </summary>
    public class Coffee : Decorator.Beverage
    {
        
        public override double  CalculateCost()
        {
            return 1;
        }
    }
}

//Base abstract class for decorator
using System;
using System.Collections.Generic;
using System.Text;

namespace Decorator
{
    /// <summary>
    /// Class for Decorator
    /// </summary>
    public abstract class CondimentDecorator : Decorator.Beverage
    {
        public abstract string Description
        {
            get;
            set;
        }
    }
}

//Decorator concrete class
using System;
using System.Collections.Generic;
using System.Text;

namespace Decorator
{
    /// <summary>
    /// Concrete decorator
    /// </summary>
    public class Mocha : Decorator.CondimentDecorator
    {
        Beverage bev;

        public Mocha(Beverage b)
        {
            this.bev = b;
        }

        public override double CalculateCost()
        {
            return this.bev.CalculateCost() +0.20;
        }

        public override string Description
        {
            get
            {
                return "Mocha";
            }
            set
            {
                throw new Exception("The method or operation is not implemented.");
            }
        }
    }
}

Bye
Antonio
Head First Design Patterns: Observer Pattern

I am reading this book and it is very useful for repeat GOF Design Patterns. But I found that source code is Java. But we prefer C# :P...

So I will implement all main patterns in C#...

I post here code about Observer:

 

//Subject
using System;
using System.Collections.Generic;
using System.Text;

namespace Observer
{
    public interface ISubject
    {
        void RegisterObserver(IObserver o);
        void RemoveObserver(IObserver o);
        void NotifyObservers();
    }
}

using System;
using System.Collections.Generic;
using System.Text;

namespace Observer
{
    public interface IObserver
    {
        void Update(double temp, double humidity, double preasure);
    }
}

using System;
using System.Collections.Generic;
using System.Text;

namespace Observer
{
    public interface IDisplay
    {
        void Dispay();
    }
}

//Subject Code
using System;
using System.Collections.Generic;
using System.Text;

namespace Observer
{
    public class WeatherData : ISubject
    {
        double _humidity;

        public double Humidity
        {
            get { return _humidity; }
            set { _humidity = value; }
        }
        double _preassure;

        public double Preassure
        {
            get { return _preassure; }
            set { _preassure = value; }
        }
        double _temperature;

        public double Temperature
        {
            get { return _temperature; }
            set { _temperature = value; }
        }

        /// <summary>
        /// Observers
        /// </summary>
        System.Collections.Generic.IList<IObserver> objs = new System.Collections.Generic.List<IObserver>();
        #region ISubject Members

        public void RegisterObserver(IObserver o)
        {
            objs.Add(o);
        }

        public void RemoveObserver(IObserver o)
        {
            objs.Remove(o);
        }

        public void NotifyObservers()
        {
            foreach (IObserver obj in objs)
                obj.Update(this._temperature, this._humidity, this._preassure);
        }

        #endregion
    }
}

//Observer code
using System;
using System.Collections.Generic;
using System.Text;

namespace Observer
{
    public class CurrentDispaly : IObserver,IDisplay
    {
        double _humidity;
        double _preassure;
        double _temperature;
        ISubject subject;

        public CurrentDispaly(ISubject sub)
        {
            //Istanzia l'oggetto e lo aggiunge come Observer
            subject = sub;
            subject.RegisterObserver(this);
        }
        #region IObserver Members

        public void Update(double temp, double humidity, double preasure)
        {
            this._temperature = temp;
            this._preassure = preasure;
            this._humidity = humidity;
            this.Dispay();
        }

        #endregion

        #region IDisplay Members

        public void Dispay()
        {
            System.Console.WriteLine(this._humidity + " " + this._preassure + " " + this._temperature);
        }

        #endregion
    }
}

Bye
Antonio
Thank you uCertify

 Last week I passed exam 70-529. I passed with 953/1000 at first attempt. I used uCertify training kit. This training kit was really useful with a lot of questions and reviews, simulations and practices. It contains MSDN tips too. I used some other demo versions but I decided to choose and buy uCertify because it was the best one.

Thank you

Bye

Antonio

Calculate file hash

A little code snippet for calculte file hash:

 

public

string CalculateHash(string file)

{

 

 

try

{

 

 

MD5 obj = MD5.Create();

 

 

byte[] bytes;

 

 

using (FileStream fs = new FileStream(file, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))

{

int index = 0;

long fileLength = fs.Length;

 

 

if (fileLength > Int32.MaxValue)

 

 

throw new IOException("File too long" );

 

int count = (int)fileLength;

bytes =new byte[count];

 

 

while(count > 0)

{

 

 

int n = fs.Read(bytes, index, count);

 

 

if (n == 0)

 

 

throw new InvalidOperationException("End of file reached before expected");

index += n;

count -= n;

}

}

 

 

byte[] val = obj.ComputeHash(bytes);

 

 

ASCIIEncoding ascii = new ASCIIEncoding();

 

 

return ascii.GetString(val);

}

 

 

catch (Exception)

{

 

 

return null;

 

}

}

Bye

Antonio

Posted 17 July 2008 02:02 PM by antrad | no comments
Filed under:
Nice post about CSS and Rounded Corners

This is an useful link...I am not a great designer with web graphic :-)

Bye

Antonio

More Posts Next page »

This site

Search

Go

This Blog

Syndication

Sponsors

  • MaximumASP
  • Breaking News
  • Find a Job
  • Social Bookmarking
    Tidebuy Reviews
    Online Shopping
    asp.net hosting
    UK online local dating