Reputation: 133
I have a web service that works in IIS 6 but does not work in IIS 7. To test whether web services work at all, I made a simple web service in my ASMX file, as shown:
<%@ WebService Language='c#' Class="DEMOAddNumbers" %>
using System;
using System.Web.Services;
public class DEMOAddNumbers : WebService
{
[WebMethod]
public int AddThis(int x, int y)
{
int mySum;
mySum = x + y;
return mySum;
}
}
This web service works, but when I use CodeBehind and put the code in a DEMOAddNumbers.CS file, it says,
Could not create type 'DEMOAddNumbers'
I have tried various ways to reference DEMOAddNumbers.cs, such as:
<%@ WebService Language='c#' Class="DEMOAddNumbers" CodeBehind='DEMOAddNumbers.cs' %>
<%@ WebService Language='c#' Class="DEMOAddNumbers" CodeBehind='~/DEMOAddNumbers.cs' %>
Put it in an App_Code directory and then:
<%@ WebService Language='c#' Class="DEMOAddNumbers" CodeBehind='~/App_Code/DEMOAddNumbers.cs' %>
Still same error message. I'm not using Visual Studio, just straight code. Any suggestions?
Thanks
Jim
Upvotes: 0
Views: 1359
Reputation: 17010
Get rid of the directive to point to a code behind file. You can then embed the code in the ASMX.
I would recommend adding a namespace and all of the proper attributes to the class, but it should work once you stop having ASP.NET engine look for the code behind file.
Upvotes: 1
Reputation: 17010
Are you doing this hand coded or in Visual Studio? Assume hand coding.
Create new ASMX file called DEMOAddNumbers.asmx and place this line in it
Create new ASMX.CS file called DEMOAddNumbers.asmx.cs and place this in it
using System; using System.Web.Services; public class DEMOAddNumbers : WebService { [WebMethod] public int AddThis(int x, int y) { int mySum; mySum = x + y; return mySum; } }
You can't have straight code on ASMX. If you want "straight code" move to WCF.
Upvotes: 0