Webservice Error: Could not create type ‘AWebService’

Description:

This one had me seriously stumped for over an hour.
I had created my webservice code file (.cs) and after creating the .asmx file I got an exception reading, ‘Could not create type ….’ .

My .asmx file contained the following directive :

<%@WebServiceLanguage="C#"CodeBehind="~/App_Code/aWebService.cs" Class="aWebService" %>

See solution below ads


Solution
This error occurs when the code specified by the CodeBehind attribute is enclosed within a namespace.

My code was as follows.

namespace MyWebService
{
public class aWebService : System.Web.Services.WebService
{
public SysAdminSvc()
{

…………. blah blah blah

As you can see my code is within the namespace MyWebService …. PROBLEM !!!

Remove enclosing namespace.(MyWebService)

The correct way of specifying a namespace for this code is using the Webservice attribute as follows.

[WebService(Namespace = "http://www.xhydra.com")]

Yes I know this is a newbie- type error but I am learning a lot of stuff daily.

HAPPY CODING

technorati tags ,

3 Responses to “Webservice Error: Could not create type ‘AWebService’”

  1. Jorge Says:

    I have encountered this error several time and the above is just one of the many causes of this error.

  2. steve Says:

    I had this exact error, but the cause was not the above - it wasn’t the namespace deal you describe above. There are several possible causes, as Jorge says.

  3. moderator Says:

    The error itself is as specific as stating that ‘car will not start’ .
    This article suggests one of the possible causes that car will not start.

    If you have checked your car and this is not the reason it wont start then…. why dont you move along then

Leave a Reply