web service consumer compiler error "type or namespace...could not be found"

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • websurvivor
    New Member
    • May 2010
    • 1

    #1

    web service consumer compiler error "type or namespace...could not be found"

    I have experience with Windows programming but I am new to Web programming and I am trying to create a web service. I am doing this with Notepad and the .NET SDK. I have recently built a Windows Server 2003 machine and activated IIS. I am using the default directory structure ("inetpub\wwwro ot") for the default web site. In trying to learn web service programming I have tried using multiple examples on the Web to create Web services this way. But I get a compiler error every time similar to the one below...

    Code:
    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
    Here are the steps I am going through to create a web service. This particular one is an example from a codeguru.com article.
    1. I have created the "FirstService.a smx" file and put it into the folder "wwwroot\ws 1" on the server.
    2. I have created the "WebApp.asp x" file and put it into the folder "wwwroot\ws 1" on the server.
    3. I used wsdl.exe to create "FirstService.c s", using "http://myserver/ws1/FirstService.as mx?wsdl".
    4. I used csc.exe to create "FirstService.d ll" using "FirstService.c s".
    5. 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.as mx
    Code:
      <%@ 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";
          }
      }
    WebApp.aspx
    Code:
      <%@ 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>
  • Frinavale
    Recognized Expert Expert
    • Oct 2006
    • 9749

    #2
    I don't really know what to suggest as a way to fix this....
    Have you seen this MSDN walkthrough for Creating an XML Web Service Using C++ and the CLR?

    Comment

    Working...