Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Parser Error : Could not create type

I have created webservice and published it on local machine. Then I have uploaded it on server.

Now while I tried to access webservice it gives following error :

Parser Error Message: Could not create type 'webservice.myservice'

Source Error: Line 1: <%@ WebService Language="C#" CodeBehind="myservice.asmx.cs" Class="webservice.myservice" %>

I tried This link but unable to solve my problem.

What should I do?

like image 886
Meghan Avatar asked Jun 03 '11 13:06

Meghan


3 Answers

I don't know if this is dragging something up from the dim and distant past, but I had this problem. I fixed it. So I thought I'd to share it.

When you create a web service in Visual Studio (I'm using 2010 but I'd imagine it's the same for others), it creates a file called Service1.asmx

You will be tempted to rename it to MyService.asmx (or whatever).

Then you'll look inside and see the line

public class Service1: System.Web.Services.WebService

which you'll change to

public class MyService: System.Web.Services.WebService

and then when you try running it, you get the error

Could not create type 'MyProject.MyService'

Because it still thinks the class is called Service1.

If you right click the .asmx file and select view markup, you'll see it still says:

<%@ WebService Language="C#" CodeBehind="MyService.asmx.cs" Class="MyProject.Service1" %>

change it to

<%@ WebService Language="C#" CodeBehind="MyService.asmx.cs" Class="MyProject.MyService" %>

save it, try it.

It worked for me.

like image 84
JohnW Avatar answered Nov 02 '22 16:11

JohnW


I had the same problem and looked for it for a long time!

I tried a lot of things including the following:

  • Frameword version incorrect
  • A whole list of things that could be wrong

None of those worked for me. After some searching, testing and cursing, I finally found the problem: The application (webservice) was incorrectly hosted.

Let me explain with a little background:

I had a project containing two solutions: One solution was the website that I made (html, javascript, etc), the other solution contained a folder with the business logic, the database model and the webservices. Obviously the webservices folder contained my .asmx files and code-behind for them.

  • Project
    • Data Core
      • Database Model
      • Business Logic
      • Webservices
        • myWebservice.asmx
    • Website

I was hosting these in the following way:

  • My website was hosted as a new site with the website folder as root folder
  • My webservices I was hosting as an application in my website, with the webservices folder as root

More visually:

  • IIS 7
    • My Website => Pointing at the "Website" folder
      • Webservices Application => Pointing at the "Webservices" folder in the Data Core

This resulted in the following url "http://website/webservices/myWebservice.asmx", which gave me the "Could not create type" error.

Now, after playing around a bit I tried hosting my webservice application starting with the data core as root, instead of the webservice folder.

Visually:

  • IIS 7
    • My Website => Pointing at the "Website" folder
      • Webservices Application => Pointing at the "Data Core" folder.

Obviously using the same url as before would give me a "File not found" error. However, using the following url "http://website/webservices/webservices/myWebservice.asmx",I finally got my working webservices page!

A small url breakdown:

  • http ://website/ => My website from the "Website" folder
    • webservices/ => Equivalent to the "Data Core" folder
      • webservices/ => The "webservices" folder in the "Data Core" folder
        • myWebservice.asmx => The webservice file in the "webservices" folder, in the "Data Core" folder

I assume that because I was hosting my webservices directly from the "webservices" folder in the Data Core, that the server could not find the compiled DLL of the webservices (which resides in the "bin" folder), since I was hosting at a deeper level.

After changing the configuration and hosting the webservices from the "Data Core" folder, the IIS server could "see" the bin folder and host the webservices succesfully. When using the correct url that is ^_^

I hope this is clear and helps you with you problems!

like image 28
Glenn Avatar answered Nov 02 '22 18:11

Glenn


Another thing that can cause the problem. Is not creating an application for the project through the IIS itself. If the code is already on the server navigate to it in IIS from the left Connections pane. If the web site directory is still a yellow folder icon (and not a globe icon) you need to right-click on it and choose Convert to Application otherwise follow these steps...

Start -> Search For IIS

Open It!!

Right Click on the Default Web Site or the web site you are planning to publish the service to it.

Add application... Enter an Alias ex. "MyWebService" ... Choose the physical path. in my case was C:\inetpub\wwwroot\MyWebService which is my default web site path.

Then when you publish through Visual Studio choose that folder. or just copy your code files to it.

like image 6
hasan Avatar answered Nov 02 '22 17:11

hasan