Tuesday, March 15, 2011

Calling OperationContract in SVC using JavaScript

I was attempting to use WebMethod in a masterpage. Since .Net doesn't support static inheritance, I was out-of-luck. The obvious alternative was to use web-service to do the job. Since I was using .net 4.0, I was hoping to utilize the SVC and not ASMX.

Here's how you can make it work:

1) add "myservice1.svc" using the "Add New Item" -> "AJAX-enabled WCF-Service" menu. Notice that it adds section to your web.config and also "myservice1.cs" into your App_Code.

2) create your method in the "App_Code/myservice1.cs" (sample method below). Warning! If you're using Web Site project as me, don't put anything in the ServiceContract's Namespace!

[OperationContract]
public void SampleMethod1(int param1)
{
// your code here
}

3) Next step is to register this service in your ScriptManager (in my case, I have it on my master page):

<asp:ScriptManager ID="ScriptManager1" runat="server">
<Services>
<asp:ServiceReference Path="~/myservice1.svc" />
</Services>
</asp:ScriptManager>


4) Finally JavaScript that will call the method:

myservice1.SampleMethod1(2);

It's really that simple - the ScriptManager makes the "myservice1" available and you just call the methods. Again, please note that there's no namespace.

ReportViewer 9 issues

I was stuck with ReportViewer version 9 for one of the projects and I had to resolve 2 major issues.

First issue was the incorrect rendering of the toolbar in Chrome and Safari browsers. At last I found a piece of JS which fixes that (it uses JQuery):

// fix reportviewer toolbar in Chrome / Safari
if ($.browser.safari)
{
$("#<%=rvw1.ClientID %> table").each(function (i, item)
{
$(item).css('display', 'inline-block');
});
}


Second issue was related to apparently well known problem in IE, where the control would render double vertical scrollbars in the report body. Again, I found some JS script fragments that helped me to solve the issue:

// fix the report body size to prevent double-scrollbars in IE
window.onload = function ()
{
var viewer = document.getElementById("<%=rvw1.ClientID %>");
var frame = document.getElementById("ReportFrame<%=rvw1.ClientID %>");
if (frame != null && viewer != null)
{
var reportDiv = eval("ReportFrame<%=rvw1.ClientID %>").document.getElementById("report").contentDocument.getElementById("oReportDiv");
reportDiv.style.height = viewer.style.height;
}
}


Sunday, March 13, 2011

Increasing size of VHD

It happened to me more than once that I've started VPC and only when almost done installing and cofiguring it, I found out that the initial size of the VHD is simply not enough. Well, there's a way to fix that!
You need VhdResizer tool to create a larger copy of the "small" disk. Then you attach that copy to the existing VPC as 2nd drive and extend the volume once booted up.