Hello,
I created a simple web service for testing purpose in Visual Studio 2005:
[WSTest.asmx]
<%@ WebService Language="C#" CodeBehind="~/App_Code/Service.cs"
Class="WSTest" %>
[App_Code/Service.cs]
using System;
using System.Web;
using System.Web.Services;
using System.Web.Services.Protocols;
[WebService(Namespace = "http://bonusnaweb.com.br/WebService/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
public class WSTest : System.Web.Services.WebService
{
[WebMethod]
public int Sum(int num1, int num2) {
return num1+num2;
}
}
I tested it locally creating a virtual directory on my local IIS, and added
a web reference for the address http://localhost/WSTest/WSTest.asmx on a
test web site project, which worked correctly.
After that, I uploaded the files on a web server, which already has a site
running on it. I created a folder "WebService" and uploaded the WSTest.asmx
file, created an App_Code folder and uploaded the Service.cs file to it.
When I add a web referente for
http://www.bonusnaweb.com.br/WebService/WSTest.asmx (real web server), I get
the error:
Parser Error
Description: An error occurred during the parsing of a resource required to
service this request. Please review the following specific parse error
details and modify your source file appropriately.
Parser Error Message: Could not create type 'WSTest'.
Source Error:
Line 1: <%@ WebService Language="C#" CodeBehind="~/App_Code/Service.cs"
Class="WSTest" %>
Source File: /WebService/WSTest.asmx Line: 1
After that, because the ~\App_Code would point the the App_Code folder on
the web site root directory, I changed the WSTest.asmx file to:
<%@ WebService Language="C#" CodeBehind="App_Code/Service.cs" Class="WSTest"
%>
That is, I changed the App_Code path. When I reference the web service
again, I get
Parser Error
Description: An error occurred during the parsing of a resource required to
service this request. Please review the following specific parse error
details and modify your source file appropriately.
Parser Error Message: Could not create type 'WSTest'.
Source Error:
Line 1: <%@ WebService Language="C#" CodeBehind="App_Code/Service.cs"
Class="WSTest" %>
Source File: /WebService/WSTest.asmx Line: 1
What am I doing wrong? What is the appropriate way to publish a web service?
I tried the Publish Web Site option from VS2005, where a PrecompiledWeb
folder was created, but It didn't work too.
Jeová