Expand|Select|Wrap|Line Numbers
- Server Error in '/ws1' Application.
- --------------------------------------------------------------------------------
- Compilation Error
- Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.
- Compiler Error Message: CS0246: The type or namespace name 'FirstService' could not be found (are you missing a using directive or an assembly reference?)
- Source Error:
- Line 1: <%@ Page Language="C#" %>
- Line 2: <%@ Import Namespace="FirstService" %>
- Line 3: <script runat="server">
- Line 4: void runSrvice_Click(Object sender, EventArgs e)
- Source File: c:\inetpub\wwwroot\ws1\WebApp.aspx Line: 2
- ...
- Version Information: Microsoft .NET Framework Version:1.1.4322.2443; ASP.NET Version:1.1.4322.2407
- I have created the "FirstService.asmx" file and put it into the folder "wwwroot\ws1" on the server.
- I have created the "WebApp.aspx" file and put it into the folder "wwwroot\ws1" on the server.
- I used wsdl.exe to create "FirstService.cs", using "http://myserver/ws1/FirstService.asmx?wsdl".
- I used csc.exe to create "FirstService.dll" using "FirstService.cs".
- I copied the DLL to the server. I had no "bin" folder in the "wwwroot" folder, so I created it myself. I put the DLL in there but it didn't work. I have also tried putting the DLL into the "wwwroot/ws1" folder, as well as creating a "wwwroot/ws1/bin" folder and putting the DLL there. I have also tried right-clicking on "ws1" in IIS, clicking "Properties", then clicking the "Create" button so the folder icon turns into an icon that looks like a gear.
No matter where I put the DLL file, or where I create a "bin" folder, I keep getting the compiler error. Why is this happening?
I have tried different examples from the Web, but here is the code for one of them...
FirstService.asmx
Expand|Select|Wrap|Line Numbers
- <%@ WebService language="C" class="FirstService" %>
- using System;
- using System.Web.Services;
- using System.Xml.Serialization;
- [WebService(Namespace="http://myserver/ws1/")]
- public class FirstService : WebService
- {
- [WebMethod]
- public int Add(int a, int b)
- {
- return a + b;
- }
- [WebMethod]
- public String SayHello()
- {
- return "Hello World";
- }
- }
Expand|Select|Wrap|Line Numbers
- <%@ Page Language="C#" %>
- <script runat="server">
- void runSrvice_Click(Object sender, EventArgs e)
- {
- FirstService mySvc = new FirstService();
- Label1.Text = mySvc.SayHello();
- Label2.Text = mySvc.Add(Int32.Parse(txtNum1.Text),
- Int32.Parse(txtNum2.Text)).ToString();
- }
- </script>
- <html>
- <head>
- </head>
- <body>
- <form runat="server">
- <p>
- <em>First Number to Add </em>:
- <asp:TextBox id="txtNum1" runat="server"
- Width="43px">4</asp:TextBox>
- </p>
- <p>
- <em>Second Number To Add </em>:
- <asp:TextBox id="txtNum2" runat="server"
- Width="44px">5</asp:TextBox>
- </p>
- <p>
- <strong><u>Web Service Result -</u></strong>
- </p>
- <p>
- <em>Hello world Service</em> :
- <asp:Label id="Label1" runat="server"
- Font-Underline="True">Label</asp:Label>
- </p>
- <p>
- <em>Add Service</em> :
- & <asp:Label id="Label2" runat="server"
- Font-Underline="True">Label</asp:Label>
- </p>
- <p align="left">
- <asp:Button id="runSrvice" onclick="runSrvice_Click"
- runat="server" Text="Execute"></asp:Button>
- </p>
- </form>
- </body>
- </html>