Showing posts with label web services. Show all posts
Showing posts with label web services. Show all posts

Saturday, April 17, 2010

ASP.NET Enable Session in Web Service Methods

Ever tried accessing session variables in Web Service methods? It won't work unless you add a little property in the WebMethod header of the functions.

For example, the basic hello world:

[WebMethod(EnableSession=true)]
public void HelloWorld()
{
    ...
}

Just add the statement EnableSession=true and you'll be able to access session variables found normally in aspx pages like the following sample.

string userid = Session["userid"].ToString();

Thursday, January 28, 2010

Change Web Service name in ASP.NET

For example you have a Web Service named AAAWebService


And you want to change its name to let's say BBBWebService. If you open your code and change it like this..

public class BBBWebService : System.Web.Services.WebService

{

}

... and then run it, you would get an error like this...







The solution is to right click on your web service asmx file and click view markup.




Change the name here and you're done.

<%@ WebService Language="C#" CodeBehind="AAAWebService.asmx.cs" Class="Web_Services.BBBWebService" >



-k