Tuesday, 24 February 2009

Creating Service Reference: Failed to generate code for the service reference

I was working on Windows Service that was consuming another WCF Windows Service. I created a Service Reference in Visual Studio 2008 and noticed that client code was not automatically generating. The error I was getting was

Error 4 Custom tool error: Failed to generate code for the service reference 'MyWindowsService'. Please check other error and warning messages for details.

The Windows Service I was working on was already full blown project with lots of references, so to limit possibilities I created another empty windows service and added Service Reference to one I need. Client code was generated with no problems! I decided to use new Windows Service as a base and added all required functionality to it and selected “Update Service Reference” and again it failed to generate a code!

image

After some time looking around there was an easy solution to fix a problem. You need to edit Service Reference Configuration by selecting “Configure Service Reference…” from right click menu.

image

In the dialog box Un-tick “Reuse types in referenced assembles” and click OK. Try to Update Service Reference. This worked for me!

References

.NET C# Broken WCF service reference in VS 2008

Friday, 13 February 2009

ASP.NET page validation and redirection to a new page

I was working on the ASP.NET web site where users register using form and get redirected to a different page on pressing submit button. Easy way to redirect to a new page is to use PostBackUr property of the button.

<asp:Button runat="server" ID="BtnSubmit"  Text="Submit" PostBackUr="newpage.aspx" />

Unfortunately this does not work if we need to handle button OnClick event. Solution is to use Server.Transfer or Response.Redirect of the Page control.

protected void BtnClick(object sender, EventArgs e)
{
        if (Page.IsValid)
        {
                // Do something ...

                Response.Redirect("newpage.aspx");
        }
}

Page.isValid is true if all validators on the page and in web controls returned valid. A very good explanation about the difference between Server.Transfer and Response.Redirect can be found in the link below.

Server.Transfer Vs. Response.Redirect

Friday, 6 February 2009

Getting Started with AJAX development and AJAX Control Toolkit

Developers who use Visual Studio 2008 know that AJAX already built into ASP.NET for .Net 3.5 Framework. All they need is to get AJAX Control Toolkit.

AJAX Control Toolkit .Net 3.5

How Do I: Get Started with ASP.NET AJAX? is an excellent video that helps to get started.

AJAX for .NET 2.0

If you are developing pure .Net 2.0 ASP.NET website or still using Visual Studio 2005 you need to get AJAX 1.0 and  AJAX Control Toolkit for .Net 2.0.

ASP.NET AJAX 1.0

ASP.NET 2.0 AJAX Templates for Visual Studio 2008

AJAX Control Toolkit for .NET Framework 2.0, ASP.NET AJAX 1.0

AJAX Tutorials and Documentation

AJAX Website has extensive number of Tutorials and Control Toolkit has a sample website that will be very helpful to make learning curve shorter.

ASP.NET AJAX Videos

ASP.NET AJAX Documentation

AJAX Control Toolkit Tutorials (C#)

ASP.NET Learning Centre

Deployment of AJAX enabled websites

Once development is finished and project need to be deployed to testing or production servers, install ASP.NET AJAX 1.0 on the server if you are deploying ASP.NET 2.0 website. ASP.NET 3.5 website will require only .NET 3.5 runtime installed on the server. There is no need to install AJAX toolkit as long as toolkit DLL is distributed in bin folder.