Server Application Unavailable in ASP.NET 2.0

Hi,

I was getting this error when trying to open a asp.net 2.0 page.

However other applications developed in asp.net 1.1 were running fine.

Then realized that both of them were using the same Application Pool, so created a new application pool and assigned this new application pool to my asp.net 2.0 application.

That solved the issue.

“An application pool is a process that responds to web requests under IIS. An application pool does not have a setting for what type of ASP.Net applications will be run in it. Instead, it loads the appropriate libraries when an ASP.Net application is loaded in the process. Because the libraries for ASP.Net 1.1 and ASP.Net 2.0 are similar, but not the same, the application pool cannot respond to requests for both types of applications at the same time. This can cause sporadic behavior if you are using the server at the same time as another developer and you have applications using different versions of the framework in the same application pool”

Bye..

Advertisements

Consuming CurrencyConverter web service through JavaScript

Hi,

For getting the currency conversion rate we could use the following web service provided by Generic Objects Technologies Ltd.

Check out the web services provided by them

http://www.webservicex.net/WCF/webServices.aspx

To consume their currency converter web service

http://www.webservicex.net/CurrencyConvertor.asmx we could use the following JavaScript code

var xmlHttp;
function SoapCall() {
// creatng the xmlHttp object
xmlHttp = new ActiveXObject(“Microsoft.XMLHTTP”);
// Calling the web service using post and true means asynchronous call
xmlHttp.open(“post”, “http://www.webservicex.net/CurrencyConvertor.asmx”, false);
// Setting the request header to let the web service identify the soap request we would be sending

xmlHttp.setRequestHeader(“Content-Type”, “text/xml; charset=utf-8”);

xmlHttp.setRequestHeader(“SOAPAction”, “http://www.webserviceX.NET/ConversionRate”);

var soapRequest = “<?xml version=’1.0′ encoding=’utf-8′?> ” +
“<soap12:Envelope xmlns:xsi=’http://www.w3.org/2001/XMLSchema-instance&#8217; xmlns:xsd=’http://www.w3.org/2001/XMLSchema&#8217; xmlns:soap12=’http://www.w3.org/2003/05/soap-envelope’>&#8221; +
” <soap12:Body>” +
”   <ConversionRate xmlns=’http://www.webserviceX.NET/’>&#8221; +
”     <FromCurrency>USD</FromCurrency>” +
”    <ToCurrency>INR</ToCurrency>” +
”  </ConversionRate>” +
“</soap12:Body>” +
“</soap12:Envelope>”;

xmlHttp.send(soapRequest);
alert(xmlHttp.responseText);

}


Bye..

Reading querystring using javascript

Hi while searching for the same,

got the following javascript

q = location.search;

getParam = function(arg) {
if (q.indexOf(arg) >= 0) {
var pntr = q.indexOf(arg) + arg.length + 1;
if (q.indexOf(‘&amp;’, pntr) >= 0) {
return q.substring(pntr, q.indexOf(‘&amp;’, pntr));
} else {
return q.substring(pntr, q.length);
}
} else {
return null;
}
}

var objectId = getParam(‘oId’);

alert(objectId);

or better

function querySt(ji) {
hu = window.location.search.substring(1);
gy = hu.split(“&”);
for (i=0;i<gy.length;i++) {
ft = gy[i].split(“=”);
if (ft[0] == ji) {
return ft[1];
}
}
}

var pId= querySt(“pId”);
alert(pId);

http://ilovethecode.com/Javascript/Javascript-Tutorials-How_To-Easy/Get_Query_String_Using_Javascript.shtml

Here oId is the query string parameter whose value we need.

This works even if there are multiple query string parameters !

Bye…

Error : The conversion of a char data type to a datetime data type resulted in an out-of-range datetime value.

Hi,

I got this error while developing an asp.net page with Sql server as database,

On checking the sql query i found out that the date value was not being sent in the format expected by the database , so by changing the format within my query resolved the issue !

Initially it was calendar.ToShortDateString() and i changed it to 

Calendar1.SelectedDate.ToString(“MM/dd/yyyy”)

Bye…

Error : This application is already precompiled in ASP.NET

Hi,

I was getting this error while trying to build one of the web site in Visual studio, on some searching found out the error was because of an existing PrecompiledApp.config within the application folder!

On deleting that file and rebuilding the web site, everything was back on track !

Bye..

Gridview SelectedIndexChanged Showing no Data

It could happen if we are dynamically creating DataTable and bounding it to our GridView. Searching for it if found the following information on one of the blog

 

The GridView (and actually, all our data controls) does not save data items across postbacks.  This reduces ViewState (if the objects are even serializable) and enables garbage collection to happen and clean up your objects.  So, when you click the button to post back, the GridView has not called DataBind and therefore your data item isn’t there.  This is what you’ve discovered.

Selection is handled slightly differently than choosing an edit item, sorting, paging, or other functions: because those other functions require a change in the control tree or a query to the data source to get different data, they cause a DataBind to happen automatically at some point before the control renders again.  You can handle RowDataBound and get your data item.  Selection, however, doesn’t require new data or a different control tree (all that usually changes is the style properties on the row), so it will never call DataBind.  This makes selection very fast.  It also means you won’t get a DataBound or RowDataBound event unless you call DataBind yourself.  So you can’t use that event to get your data item unless you call it yourself.  If you need the data item, you can call DataBind yourself directly to get it, then handle OnRowDataBound, check the row index against the SelectedIndex, and get the data item.

However, this is kind of the shotgun method- it will get you what you want, but the performance has decreased because you’ve called DataBind again.  Also, if the data in the data store has been modified between your calls to databind, the row index that was the selected item may now point to a different row or just different data.  What data are you really looking for from the selected data item?  Is it just one or two fields?  If so, consider using DataKeyNames to store these fields, and then you can get to them via the DataKeys property.  If you don’t want to suffer the hit to ViewState from DataKeyNames, consider getting the data directly from the controls in the row of the GridView.

So I followed the suggestion highlighted in yellow and was able to retrieve the value for the selected row.

 

  protected void grdPropertyValues_SelectedIndexChanged(object sender, EventArgs e)

    {       

        GridViewRow row = grdPropertyValues.SelectedRow;

        // Get the selected row index

        iRownum = grdPropertyValues.SelectedIndex;

        // call the method that dynamically creates the DataTable and

        // bind the gridview to it

        BindConferenceDayToGrid(myList, grdPropertyValues);

    }

 

 

protected void grdPropertyValues_RowDataBound1(object sender, GridViewRowEventArgs e)

    {

        // getting the GridViewRow

        GridViewRow row = e.Row;

        // if RowType is DataRow and RowIndex is our selected row’s index

        if (e.Row.RowType == DataControlRowType.DataRow && row.RowIndex == iRownum)

        {       

                DataRowView drv = (DataRowView)e.Row.DataItem;

                Response.Write(“The value we need “+drv.Row[1].ToString());          

        }      

    }

 

That’s it ..

 

 

 

Publishing workflow as an ASP.NET Web Service.

 

The workflows developed using windows workflow foundation can be published as a web service. To publish a workflow as a web service, we are provided with two activities. WebServiceInput and WebServiceOutput activity.

 

To create a workflow to be published as a web service do the following

 

Create a new Empty Workflow Project.

 

Add a new interface class to the project which would be used by our WebServiceInput activity.

 

Suppose this is our interface class.

 

interface IAddInterface

                {

        int AddNumber(int firstNumber, int secondNumber);

                }

 

Now right click on the project and add a new Sequential Workflow.

 

Now drag and drop three activities. First WebServiceInput, Code and WebServiceOutput.

 

For webServiceInputActivity1 specify following properties.

 

InterfaceType –IAddInterface.

MethodName AddNumber

 

As soon as method is added we’ll see two new properties added over there one for each parameter specified in the interface method.

i.e. firstNumber and secondNumber.

 

Create two variables to bind with them and one more variable to hold the result.

 

  public int intFirstNumber;

  public int intSecondNumber;

  public int total;

 

 

Specify intFirstNumber, intSecondNumber for firstNumber and secondNumber property of webServiceInputActivity1.

 

Finally set IsActivating as true;

 

 

Now right click code activity and select generate handlers to create a handler method and specify the following code for it

 

private void codeActivity1_ExecuteCode(object sender, EventArgs e)

        {

            total = intFirstNumber + intSecondNumber;

        }

 

Now select webServiceOutputActivity1 and set its properties as following

 

InputActivityName = webServiceInputActivity1

 

ReturnValue = Activity=AddWebServiceWorkflow, Path=total (i.e. to total variable)

 

That’s it now we want to publish it as workflow.

 

For this right click the project and Select Publish as a web servcie option.

 

 

This would create a new webservice which would be named as worklflowProjectName.worfklowMethodName_WebService.asmx.

 

Now we could use it just like any other web service created using ASP.NET.

 

WebServiceInputActivity recieves input from the client using the webservice. It can be  associated with single web service method defined inside the interface. The WebServiceInputActivity can be followed by the set of activities which could be built in or custom activity. If the response has to sent back to the calling client than we need to make use of WebServiceOutputActivity.

Understanding and Using AJAX

Suppose this is our simple ASP.NET page i.e. MyPage.aspx which would be called using AJAX

Code for MyPage.aspx.cs

protected void Page_Load(object sender, EventArgs e)

{

// no data is passed

if (Request.QueryString[“myGetData”] == null)

{

Response.Write(“Hello World”);

}

// if GET method is used to call this page

else if (Request.QueryString[“myGetData”] != null)

{

Response.Write(“Hello “ + Request.QueryString[“name”].ToString());

}

// if POST method is used to call this page

else if (Request.Form[“myPostData”] != null)

{

Response.Write(“My Post Data is “ + Request.Form[“myPostData”].ToString());

}

}

Delete everything from MyPage.aspx page just keep the page directive otherwise html tags would also be sent as a part of response.

<%@ Page Language=”C#” AutoEventWireup=”true” CodeFile=”Mypage.aspx.cs” Inherits=”MyPage” %>

Now the javascript code to call the page asynchronously using AJAX. Comment/Uncomment the particular section of code to test the functionality

<script type=”text/javascript”>

var request=null;

function CreateRequest()

{

try

{

// create a new object to talk HTTP with a web server.

// XMLHttpRequest – works on Safari,Firefox, Mozilla, Opera , IE 7 and most other browsers

request=new XMLHttpRequest();

}

catch(trymicrosoft)

{

try

{

// Msxml2.XMLHTTP – Most version of IE support this

request=new ActiveXObject(“Msxml2.XMLHTTP”);

}

catch(othermicrosoft)

{

try

{

//Microsoft.XMLHTTP – but for some, we’ll need this other type

request=new ActiveXObject(“Microsoft.XMLHTTP”);

}

catch(failed)

{

request=null;

}

}

}

if(request==null)

alert(‘Error creating request object’);

else

{

// i.e. space with %20

// if no data is to be send

var url=“MyPage.aspx”;

// open-initialize the connection

// GET – specify how to send data to the server

// url- url to send the request

// asynchrounous – true

request.open(“GET”,url,true);

// telling the browser what to do with the server’s response

// i.e. the function to be called when response is received

// onreadystatechange- this property affects every ready state not just the one indicating

// that the server is finished with request

request.onreadystatechange=updatepage;

// send the request

// no data is required so send null

// for using send() to pass data to a server requires POST method for the request and need to specify content type

request.send(null);

// if data is to be send using GET i.e. as query string

var name=“MyName”;

// escape() function replaces characters like space with something that will work as a part of a request URL.

var url=“MyPage.aspx?myGetData=”+escape(name);

request.open(“GET”,url,true);

request.onreadystatechange=updatepage;

request.send(null);

// if more data is to be send than use post

var name=“MyName”;

var url=“MyPage.aspx”;

request.open(“POST”,url,true);

request.onreadystatechange=updatepage;

//setRequestHeader()- allows us to add information to the request usual intended for use by the server

// Content-Type – is the name of the request header

// application/x-www-form-urlencoded – the value of the request header

// this tells the server that the data is encoded like it would be in a request URL

// for passing XML content replace “application/x-www-form-urlencoded” with “text\xml”

request.setRequestHeader(“Content-Type”,“application/x-www-form-urlencoded”);

// specify the data to be send

// escape() function replaces characters like space with something that will work as a part of a request URL.

request.send(“myPostData=”+escape(name));

}

}

// updatepage – this function will get run every time the ready state changes

function updatepage()

{

// readyState=this property of the request object stores the current state

// if 4 means server is done with the request

// if 0 i.e uninitialized

// if 1 i.e open, the object has been created but the send method has not been called

// if 2 i.e. sent, the send method has been called.

// if 3 i.e. receiving , responseText is not available but some data has been received

// if 4 i.e. loaded, all the data has been received, responseText is available

if(request.readyState==4)

{

// check for the status send by the server

// if 200 i.e. everything is fine

// if 404 i.e. if the page specified in the url is not found

if(request.status==200)

{

var myResponse=request.responseText;

alert(myResponse);

}

else

{

alert(“Error! Request status is “ +request.status);

}

}

}

</script>

<input id=”Button1″ type=”button” value=”button” onclick=”CreateRequest()”/>

Bye…

Calling an ASP.NET web service asynchronously.

When we add a web reference to a web service behind the screen wsdl.exe is run which creates the proxy class. Proxy class contains both synchronous and asynchronous flavors of each web method.For simple HelloWorld() web method following methods are there in the proxy class

Public string HelloWorld()

Public string HelloWorldAsync();

Public string HelloWorldAsync(object userState);

We call the HelloWorldAsync() method which in turn calls the following method of the proxy class InvokeAsync()

// Summary:

// Invokes the specified method asynchronously.

// Parameters:

// methodName:

// The name of the method to invoke.

// parameters:

// The parameters to pass to the method.

// callback:

// The delegate called when the method invocation has completed.

protected void InvokeAsync(string methodName, object[] parameters, SendOrPostCallback callback);

HelloWorldCompletedEventArgsThis class is also created by wsdl.exe which contains the result of our operation.

Suppose this is our simple web service, we have introduced delay to understand the asynchronous behavior.

[WebMethod]

public string HelloWorld() {

Thread.Sleep(5000);

return “Hello World”;

}

Now to call the above webservice method asynchrously in a windows application client we need to do the following

Say we have want to call the HelloWorld method asynchronously on the click of the button,

private void btnCallService_Click(object sender, EventArgs e)

{

// Create the instance of the proxy class

Service myService = new Service();

// Register an eventhandler for HelloWorldCompleted event

// The eventhandler would be called when the request is

// completed

myService.HelloWorldCompleted += new

HelloWorldCompletedEventHandler(this.HelloWorldCompleted);

// instead of calling the synchronous HelloWorld() we need

// to call the HelloWorldAsync() method

myService.HelloWorldAsync();

}

void HelloWorldCompleted(object sender,HelloWorldCompletedEventArgs args){

// Display the reutrn value

MessageBox.Show(args.Result);

}

To call the above web method in an asp.net client we need to add the following attribute in the @Page directive

Async=”true”

Bye..