Friday, June 28, 2013

WCF Performance Engineering.

It starts with converting a specification into running model and then time passes, gradually with many changes the system becomes cumbersome due huge data .Time comes when system start falling apart. We try to cut corners where things needs changes end up doing something very worse. Well to cut long story short..Here I m talking about the performance improvement that requires revisit and too be looked very carefully. I have been working with the team where they faced issues related to time out, memory leakage or stack overall etc. These all boils down to design which is not profound or not taken factors such as performance, scalability, security etc. But to get these factors in place there is trade-off between them.

Quick Key factors that we should look at high level.
1. Check the design has chatty communication. Too many server calls, wcf calls via sql DB calls. etc..
Reduce them bulk calls if possible.

2. Check the IIS level configuration such as App Pool Overlap recycle, worker processor thread, etc.
http://msdn.microsoft.com/en-us/library/ee377050.aspx
3. First more most thing, do profiling of code, optimize code that is there.

3. BasicHttpBinding vs WShttpBinding
Check your design and end objective choose among them appropriately.

4. Check for WCF throttling. ConcurrentInstance, Concurrentsession and ConcurrentRequest.

http://blogs.msdn.com/b/distributedservices/archive/2010/03/23/wcf-services-appear-hung-due-to-maxconcurrentsessions-limit-being-hit.aspx

http://blogs.msdn.com/b/wenlong/archive/2009/02/08/why-only-two-concurrent-requests-for-load-testing.aspx

http://blogs.msdn.com/b/rickrain/archive/2009/06/26/wcf-instancing-concurrency-and-throttling-part-3.aspx

http://msdn.microsoft.com/en-us/library/vstudio/hh323713(v=vs.100).aspx



maxConcurrentInstances="200" maxConcurrentSessions="200" />
 
 

Thursday, June 27, 2013

Templatised MVC Razor By Phill Haack

This templatised MVC Razor Html helper comes handy when we have complex View where data representation is required in tables or any list form. Phill Haack has given good example to help you with this construct. I m trying to rewrite everything, but to keep reference handy in my blog for future reference and development. I like the way custom iterator being used and passed as calling func with html writer as output.

Reference:
http://weblogs.asp.net/nmarun/archive/2011/02/28/templated-razor-delegates-phil-haack.aspx
http://haacked.com/archive/2011/02/27/templated-razor-delegates.aspx

I find this useful.


 


Thursday, June 20, 2013

MVC 4 Razor Quick Learning Book


Sr.No
Code Type
Syntax
1
Looping
@for(var i = 0; i < 10; i++){
  This is record @i
}
@foreach(Order order in OrderCollection) {
  @order.Cost
  @order.Quantity
}
 
 
2
Html Decode
@Html.Raw("

b>santosh

")
3
@Escape
 
We met @@time sharp!
4
Function
@functions{
  public bool isFooBar(string foo, string bar){
    return foo == bar;
  }
}
@{ var foo = "black";
  if(isFooBar(foo,"black")){
    Yup
  }
}
 
3
Switch Case
@switch(condition){
  case 1:
    @item.BodyText
    break;
  case 2:
    @item.Children.First().BodyText
    break;
  default:
    break;
}
 
4
Condtional
@if(item.HasValue("bodyText"){
  @item.BodyText
}else if(item.IsNull("bodyText")){
  this item is null
}else{
  Some other text
}
 

MVC Ajax JQuery
If we suppose want to load view based on Request received through ActionResult Controller .Then we can do that using following symantics

Public ActionResult Index()
{
if(Request.IsAjaxRequest()==true)
{
return Partial("XYZView",Model);

}
else
{
return view(Model);
}
}
ViewBag Vs ViewData

viewBag

is more cleaner dictionary to store dynamic data object.


Controller :
public ActionResult Foo
{
    ViewBag.FirstName="santosh";
    ViewBag.LastName="Poojari";
} 
View

@{
    var firstName = ViewBag.FirstName;
    var lastName = ViewBag.LastName;
}


ViewData


Controller :
public ActionResult Foo
{
    ViewBag["FirstName"]="santosh";
    ViewBag["LastName"]="Poojari";
}

View
@{    var firstName .= ViewData["FirstName"];    var lastName = ViewBag["LastName"]; }

Model

@model MVC4.Customer
This is declared at the top of view to include or reference the model. This is viewModel binding.
Once we do that we allow Model keyword to act as strongly typed viewmodel.
so now we can access Customer objectproperty  using
Hello @Model.CustomerName !

Expression: Foreach



    @foreach(var item in Model.Products) {

  

  •    @item.Name1

       @item.Upc1

      
      

  • }


    @if (Model.Count() > 0){    
            You've got data!    

    }

    _ViewStart.cshtml

    This is a bootstrap file that is applicable to all views in the solution.
    @{    Layout = "~/Views/Shared/_Layout.cshtml";
    }
    @{  
      if (HttpContext.Current.User.Identity.IsAuthenticated)   
     {      
        Layout = "~/Views/Shared/_Layout.cshtml";    
     }   
     else    
     {        
        Layout = "~/Views/Shared/_AnonLayout.cshtml";      
     }
    }

    @Html.Partial- Partial View

    Just partial page details _logOnPartial.chtml

    @Html.Partial("_LogOnPartial")

    @Html.RenderPartial-Partial View

    It used to call Controller with input parameter from view. The return type of controller would be Render.PartialView(PartialViewName.chtml)
    View
    @Html.RenderPartial("PersonName", Model.Person);
    Controller
    public ActionResult PersonName(string person)
    {
        return Render.PartialView(_LoginPartial);
    }

    @Html.RenderAction- Partial View

    View
    @Html.RenderAction("ListPartialView", "ProjectControllerMethod", new {personId = Model.Person.Id});
    Controller

    public ActionResult ProjectControllerMethod(int personID)

    {

        return View()

    }

    @Html.Action

    @Html.ActionLink

    @Html.ActionLink("Home", "Index",
    "Home")

    @Url.Action

    @Html.Raw ("

    Introduction

    ")

    Declarative HtmlHelper

    @helper Highlight(String value){    <span style="background-color: yellow">@value</span>}
    @Highlight("Foo")
    @helper CalcAndFormat(int a, int b, Func<intint, int> calc){    var sum = calc(a, b);    

    if(sum % 3 == 0)    
     {       
     @Highlight(sum.ToString())       

    else 
    {        <span>@sum</span>    }   

    }


    @* Outputs “27” with yellow highlighting *@
    @CalcAndFormat(3, 9, (a, b) => a * b)
    @* Outputs “50” with no highlighting *@ 

    @CalcAndFormat(2, 4, (a, b) => a * b + 42)

    Note:Spark Engine is more powerful than Razor.

    Reference :http://www.code-magazine.com/article.aspx?quickid=1103041&page=5

    Thursday, June 13, 2013

    MVC 4 Razor - Report Viewer Control RDLC Reporting

    I've been struggling to render the RDLC in MVC 4 or any version using Razor view chtml. If your project is in traditional Asp.net and you planning to rewrite in mVC in a view to reuse most of the component as is then you've to be bit conscious. If you have extensively used RDLC and reportviewer control and then you migrate to mvc architecture .Beware this is not possible in MVC razor view. You can very well get MVC response output in pDF,excel.(****.mind it not in html ) as  adownload then there is options available.
    http://weblogs.asp.net/rajbk/archive/2009/11/25/rendering-an-rdlc-directly-to-the-response-stream-in-asp-net-mvc.aspx

    But if you want to rendered it in html or embed in partial view as we have reportviewer control in asp.net this is not possible to achieve. In such case you can end up evaluating other third party component. Micro assessment of each migrating component plays a crucial role. I had my bite of troubles , hope you don't fall in same situation. MVC asp.net needs to get matured unlike silverlight we have the case. I keep my finger cross and I personally feel MVC asp.net and javascript with HTM5 rocks.

    Bye for now.