Thursday

content length quota (8192) has been exceeded fix

to fix this error in Acessing WCF service:


The formatter threw an exception while trying to deserialize the message:
Error in deserializing body of request message for operation 'FreezeInvoices'.
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. Line 1,



do folowing :
1.Open web.config file and add these content under system.serviceModel:



<system.serviceModel>

<bindings>
<basicHttpBinding>
<binding name="Binding1" closeTimeout="00:11:00" openTimeout="00:11:00" receiveTimeout="00:10:00" sendTimeout="00:10:00" allowCookies="false" hostNameComparisonMode="StrongWildcard" maxBufferSize="9965536" maxBufferPoolSize="9524288" maxReceivedMessageSize="9965536" messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered" >
<readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />
<security mode="None" />
</binding>
</basicHttpBinding>
</bindings>



2.Find this line and add bindingConfiguration :

<endpoint address="" binding="basicHttpBinding" contract="Business.WebService.IService" bindingConfiguration="Binding1">

more...

Wednesday

python setdefault in indexing text file


indx={}
with open(filename) as f:
for n,line in enumerate(f):
for word in line.split():
indx.setdefault(word,[]).append(n)
#emit in alphabetical order
for word in sorted(indx):
print "%s:" % word
for n in indx[word]: print n,
print

more...

python property & dunder special methods


#property sample
class blah(object)
def getter(self):
return ...
def setter(self,value):
....
name=property(getter,setter)
inst=blah()

print inst.name #calls inst.getter()
inst.name=23 #like call inst.setter(23)


python special methods (dobleundescore aka dunder):
__new__ __init__ __del__ # ctor,init, finalize
__repr__ __str__ __int__ # convert
__lt__ __gt__ __eq__ # compare
__add__ __sub__ __mul__ # arithmetic
__call__ __hash__ __nonzero__ # ()
__getattr__ __setattr__ __delattr__ #
__getitem__ __setitem__ __delitem__ #
__len__ __iter__ __contains__ #
__get__ __set__ __enter__ __exit__
here's sample of using special methods

class fib(object):
def __init__(self): self.i=self.j=1
def __iter__(self): return self
def next(self):
r,self.i=self.i,self.j
self.j+=r
return r

for r in fib():
print r,
if r > 100: break
1 1 2 3 5 8 13 21 34 55 89 144

more...

python functions generators closures decorators



Types of arguments:



#default values:


def sub1( a,b='default',i=0)

named arguments


def info(spacing=15, object=odbchelper):

tuple (args,params)


def sumsq2(*a): return sum(x*x for x in a)

dictionary


def sumsq2(**a):



generators in python - used yield insted of return


def fibonacci()
i=j=1
while True:
r,i,j = i,j,i+j
yield r


for rabbits in fibonacci():
print rabbits
if rabbit > 100 : break
>>
1 1 2 3 5 8 13 21 34 55 89 144

Closures


def makeAdder(addend):
def adder(augend):
return audend + addend
return adder


a23=MakeAdder(23)
a42=MakeAdder(42)

print a23(100) , a42(100) , a23(a42(100))
>> 123 142 165


decorators



@<decor>
def <name>
#is like
def (name)
name = <decor>(<name>)


#or another example
@dec2
@dec1
def func(arg1, arg2, ...):
pass

#This is equivalent to:

def func(arg1, arg2, ...):
pass
func = dec2(dec1(func))

and singleton example


def singleton(cls):
instances = {}
def getinstance():
if cls not in instances:
instances[cls] = cls()
return instances[cls]
return getinstance

@singleton
class MyClass:
...


more...

XElement.Parse using and create xml with linq:

post can be found here

btw.I was surprised that there is windows 2003/2008 hosting
with .NET+SQL Server with complete support of asp.net+AJAX+LINQ
Also some windows hosting server have access FTP over SSL.

more...

linq transformation sample xml xelement.parse used


XElement project = XElement.Parse (@"
<Project DefaultTargets=""Build"" xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">
<PropertyGroup>
<Platform Condition="" '$(Platform)' == '' "">AnyCPU</Platform>
<ProductVersion>9.0.11209</ProductVersion>
</PropertyGroup>
<ItemGroup>
<Compile Include=""ObjectGraph.cs"" />
<Compile Include=""Program.cs"" />
<Compile Include=""Properties\AssemblyInfo.cs"" />
<Compile Include=""Tests\Aggregation.cs"" />
<Compile Include=""Tests\Advanced\RecursiveXml.cs"" />
</ItemGroup>
</Project>");

XNamespace ns = project.Name.Namespace;

var query =
new XElement ("ProjectReport",
from compileItem in project.Elements (ns + "ItemGroup").Elements (ns + "Compile")
let include = compileItem.Attribute ("Include")
where include != null
select new XElement ("File", include.Value)
);

query.Dump();

and results will be:

<ProjectReport>
<File>ObjectGraph.cs</File>
<File>Program.cs</File>
<File>Properties\AssemblyInfo.cs</File>
<File>Tests\Aggregation.cs</File>
<File>Tests\Advanced\RecursiveXml.cs</File>
</ProjectReport>



more...

Saturday

wcf 404 not found on .csv file (server 2003) .NET 3.0/3.5

To fix this 404 error when openening .csv file
in browser see
this post:
it has basic steps of wcf (Windows Communication Foundation) dot.NET 3.0/3.5 initialization on IIS 6.

Friday

get last date of month - csharp


private DateTime LastDayOfMonth(DateTime d)
{
DateTime d = new DateTime(d.Year, d.Month, 1);
return d.AddMonths(1).AddDays(-1);
}

more...

register wcf service on iis by servicemodelreg.exe

I reinstalled aspnet (just in case) this step may be omited:


C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727>aspnet_regiis.exe -i
Start installing ASP.NET (2.0.50727).
..........................
Finished installing ASP.NET (2.0.50727).



1.Run service modeling utility: ServiceModelReg.exe /i /x

C:\WINDOWS\Microsoft.NET\Framework\v3.0\Windows Communication Foundation>ServiceModelReg.exe /i /x

Microsoft(R) Windows Communication Foundation Installation Utility
[Microsoft (R) Windows (R) Communication Foundation, Version 3.0.4506.2152]
Copyright (c) Microsoft Corporation. All rights reserved.

Installing: Machine.config Section Groups and Handlers
Installing: System.Web Build Provider
Installing: System.Web Compilation Assemblies
Installing: HTTP Handlers
Installing: HTTP Modules
Installing: Web Host Script Mappings
Installing: WMI Classes
Installing: Windows CardSpace (idsvc)
Installing: Net.Tcp Port Sharing Service (NetTcpPortSharing)
Installing: HTTP Namespace Reservations



2. run it again with this key: ServiceModelReg.exe /s:W3SVC


C:\WINDOWS\Microsoft.NET\Framework\v3.0\Windows Communication Foundation>Service
ModelReg.exe /s:W3SVC
Microsoft(R) Windows Communication Foundation Installation Utility
[Microsoft (R) Windows (R) Communication Foundation, Version 3.0.4506.2152]
Copyright (c) Microsoft Corporation. All rights reserved.
Installing: Web Host Script Mappings



As optional you may refresh this :
c:\WINDOWS\Microsoft.NET\Framework\v3.5\WFServicesReg.exe /r
c:\WINDOWS\Microsoft.NET\Framework\v3.5\WFServicesReg.exe /c

http://social.msdn.microsoft.com/Forums/en-US/wcf/thread/95bdf2fa-3e2d-489d-8873-31f0da816577/
more...

Thursday

add google search to website

To add google search box please copy code below. (replace sourcefield.blogspot.com with your address)
Also you can get free virus protection from google within google pack.

<input class="BlogSearch" type="text" name="searchBox" id="blogSearchText" value="" onkeypress="return blogSearch(event, this);">
<input type="button" value="Search" onclick="return blogSearch2('blogSearchText');" class="BlogSearchButton">
<script type="text/javascript">

function blogSearch(event, oInput) {
var keyCode = (event) ? event.keyCode : keyStroke.which;
if (keyCode == 13) {
top.location = 'http://www.google.com/search?q=' + escape(oInput.value) + '+site%3Asourcefield.blogspot.com';
return false;
} return true;
}

function blogSearch2(oInputId) {
var oInput = document.getElementById(oInputId);
top.location = 'http://www.google.com/search?q=' + escape(oInput.value) + '+site%3Asourcefield.blogspot.com';
return false;
}
</script>

where to buy visual studio 2008

I downloaded Free 90-Day Trial from Microsoft and was defying all challenges with success :).
Now time has come today to buy, so I was looking for deals on studio in the market.
There is a lot academic versions software for students on "Academic superstore" for teachers students and schools.
First obvious thing I can buy standard edition or professional edition on Amazon, they have free shipping,
but there are a lot of other hot deals as well, let's compare prices:

Visual.EverythingOutlet from $149
SoftwareKing - from $149
AcademicSuperstore - from $195
Amazon - 249.99
buypcsoft has it from $679.95

I'm still looking for visual studio so if anybody did it , please share your experience.


more...

linq examples in linqpad

just downloaded linqpad, it contains a lot of examples linq to sql from C# 3.0 in a Nutshell book.
including linq grouping and linq join ,nice linq tutorial that allows to run your own linq queries.
more...

Monday

linq transactions support/Charp/dot.net 3.5

 [Test]
public void StoredProcedure_and_LinqUpdates_Test()
{

// dx is datacontext instance
dx.Connection.Open();
dx.Transaction = dx.Connection.BeginTransaction();


// calling stored procedure from linq here
var result = dx.PaymentServices_ApplyPaymentToAccount(89);


// updating objects from context
Invoice i = customerService.getInvoice(277);

i.DueDate = Convert.ToDateTime("11/5/2008");

// submitting changes and committing transaction
dx.SubmitChanges();
dx.Transaction.Commit();


// rollback transactions and
// no changes made in object or by stored procedure will be stored
dx.Transaction.Rollback();

}

more...

imagemagic add text to image

rem different types of text annotations on existing images rem cyan yellow orange gold rem -gravity SouthWest rem draw text and anno...