Parser Error : Could not create type
Asked Answered
G

6

39

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?

Grandson answered 3/6, 2011 at 13:42 Comment(7)
Have you uploaded the dll or .cs/vb page with the asmx page? It appears as if you are missing the code behind class?Jillion
Yes I have uploaded all files in zip format. And unzipped on server.Grandson
As far as I know the error literally means that the page can't find the code. Does the rest of the site work.. if there is any? Generally if it runs fine locally, then something has not been copied properly.Jillion
Here is a pretty good step by step walk through to resolve your error. cjvandyk.com/blog/Lists/Posts/… Your problem is most likely caused by mis-configured IIS site.Insouciance
may be you didnt install proper framework on serverWilds
This error occurs when you have your project folder under your virtual folder on IIS.Drowsy
Response to the comment right above. Having it in a Virtual Directory of IIS or within the main directory of IIS still gives the same error.Loving
D
57

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.

Disentail answered 16/11, 2011 at 12:20 Comment(5)
Thanks, I thought I was on the right path for fixing this and this answers confirms that. However, its not MyProject.MyService its MyNamespace.MyService. I guess I must be another visitor from the past as "This question is closed as it is unlikely to help any future visitors". Bollocks.Indicant
This definitely helped me. I am trying to understand Web Services before getting into WCF.Brigettebrigg
I had this issue and I had a different problem, so here is the solution for other frustrated people out there. If you change the build target folder, it will stop working. You have to copy the output of the build back to .\bin\Sarcophagus
It should be noted that the class name should include the proper namespace, and changes to the namespace will also have this same effect.Alice
Great job btw, thats when perfection leads to errors =)Adai
C
8

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

I tried a lot of things including the following:

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!

Comber answered 20/1, 2012 at 14:43 Comment(0)
T
6

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.

Tenth answered 15/11, 2014 at 18:7 Comment(1)
Thanks @hasan! You saved me a lot of time!Oas
T
0

I'm fairly certain this is just a summary of what Glenn said, but I ran into this issue because my application was created from the directory one level too high in the directory structure.

For example, my web service was in SiteProject_1/SiteProject_2/service.asmx

Originally SiteProject_1 was what I converted into the application within IIS. I was able to resolve the issue by removing that application within IIS and instead making SiteProject_2 into the application.

Tendency answered 17/11, 2017 at 12:56 Comment(0)
W
0

I was having this problem this morning and Google landed me here, but none of these answers worked for me. But I did figure out what was wrong - at least in my case - so I thought I'd share it in case it helps others.

I had a web service that had been working fine for months in a solution with other parts of the application that I work on. Yesterday, I needed to fix something in a release branch, so I opened Visual Studio on a copy of the solution in another directory. Visual Studio decided to be helpful and silently remap all my virtual directories in IIS to where the programs would be in the release folder (if I had bothered to build them, which I hadn't). Now when I tried to hit my web service, IIS was pointing to the release version which had the asmx but no bin folder.

Opening the Web properties tab in my development solution and clicking the Create Virtual Directory remapped it back to the development version and all was good with the world again.

Windsor answered 3/7, 2019 at 13:2 Comment(0)
W
0

There is a similar question on StackOverflow here: Web service Parser Error Message: Could not create type 'xxx'

I've run into this problem today after renaming the class name in the ASMX.CS file. I tried a number of different solutions to try to fix the problem, but none of them worked for me:

  • Cleaning and rebuilding the solution failed.
  • Renaming the 'Class' in both the ASMX and the ASMX.CS file failed.
  • Renaming the ASMX.CS file name and renaming it in the 'CodeBehind' path for the ASMX file failed.
  • Naming the ASMX and ASMX.CS files with the same name failed.

What DID work for me was creating a NEW ASMX file in Visual Studio and copying the old code into the new ASMX.CS file.

To do this in Visual Studio, just go to the Solution Explorer, right-click on the CS Proj -> Add -> Add New Item and choose the Web Service (ASMX) option. That will create the new ASMX file and then you can just copy your code into the new file and delete the old object.

Not sure how or why this fixed anything, because the new ASMX file seems identical, but it did fix the problem for me. Maybe there was a bad reference somewhere in the Visual Studio or CS Project settings?

Wert answered 27/1 at 4:51 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.