customized webhttpbinding for large messages

<endpointBehaviors>

<behavior name=”AspNetAjaxEndpointBehavior”>

<enableWebScript/>

<dataContractSerializer maxItemsInObjectGraph=”2147483647″ />

</behavior>

</endpointBehaviors>

</behaviors>

<bindings>

 

<webHttpBinding>

<binding name=”AspNetAjaxBinding” hostNameComparisonMode=”StrongWildcard” closeTimeout=”00:01:00″ openTimeout=”10:01:00″ receiveTimeout=”10:10:00″ sendTimeout=”10:01:00″ maxBufferPoolSize=”2147483647″ maxReceivedMessageSize=”2147483647″ bypassProxyOnLocal=”false”>

<readerQuotas maxDepth=”2147483647″ maxStringContentLength=”2147483647″ maxArrayLength=”2147483647″ maxBytesPerRead=”2147483647″ maxNameTableCharCount=”2147483647″/>

<security mode=”TransportCredentialOnly”>

<transport clientCredentialType=”Ntlm” />

</security>

</binding>

</webHttpBinding>

</bindings>

<services>

<service name=”Namespace.Classname” behaviorConfiguration=”ProxyServiceBehavior”>

<endpoint address=””

binding=”webHttpBinding” bindingConfiguration=”AspNetAjaxBinding”

contract=”IInteface” behaviorConfiguration=”AspNetAjaxEndpointBehavior” />

</service>

</services>

 

 

Get Start(first) Date for a week, month and quarter utility functions

Common Date Time utility functions for figuring out start (first) dates

Week:

public static DateTime GetWeekStartDate(DateTime dDate)        {
DayOfWeek day = dDate.DayOfWeek;

int days = day – DayOfWeek.Sunday;

DateTime start = dDate.AddDays(-days);

return start;

}

Month:

public static DateTime GetMonthStartDate(DateTime dDate)

{
int month = dDate.Month;
DateTime start = new DateTime(dDate.Year, month, 1);

return start;
}

Quarter:

public static DateTime GetQuarterStartDate(DateTime date)
{
int intQuarterNum = (date.Month – 1) / 3 + 1;

return new DateTime(date.Year, 3 * intQuarterNum – 2, 1);
}

when does code suck

I was reading this article on the net http://www.artima.com/weblogs/viewpost.jsp?thread=71730 and basically the author say if one of the items in the below are true, then our code sucks and I agree 🙂

1) Your code sucks if it isn’t testable.
2) Your code sucks if it’s hard to read.
3) Your code sucks if it’s not understandable.
4) Your code sucks if it dogmatically conforms to a trendy framework at the cost of following good design/implementation practices.
5) Your code sucks if it has duplication.

WCF known types gotcha

KnownType: if you use this at the base class level everything will work as expected

ServiceKnownType : one of the issue with serviceknowntype is that if you decorate it at the service implementation level(class) or the method implementation, it does not have any effect, the compiler does not throw any error, but during runtime the client call will fail(underlying connect closed), the solution is to always use the ServiceKnownType attribute on the service interface or the method in the interface.

Invoke Btstask from .net code

private static void InvokeBtsTask(string taskParams)
{
System.Diagnostics.Debug.WriteLine(string.Format(” Begin BTSTask with params {0}”, taskParams));
StringBuilder taskOutput = new StringBuilder();
Process btsTask = new Process
{
StartInfo =
{
FileName = “BTSTask.exe”,
Arguments = taskParams,
UseShellExecute = false,
RedirectStandardError = true,
RedirectStandardOutput = true,
CreateNoWindow = true
}
};
btsTask.Start();

while (btsTask.StandardOutput.Peek() > -1)
taskOutput.Append(btsTask.StandardOutput.ReadToEnd());

btsTask.WaitForExit();
System.Diagnostics.Debug.WriteLine(string.Format(“BTSTask exited with message {0}”, taskOutput.ToString()));

System.Diagnostics.Debug.WriteLine(string.Format(” End BTSTask with params {0}”, taskParams));

if(!taskOutput.ToString().Contains(“Command succeeded with 0 errors, 0 warnings”))
throw new ApplicationException(String.Format(“Error while executing BTSTask.exe with parameters {0} error message {1}”,taskParams,taskOutput.ToString()));
}