Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

Troubleshooting
Research
Professional Opinions
Ask a Question
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

troubleshooting Question

'namespace' is undefined

Avatar of steve_a_sanders
steve_a_sandersFlag for United States of America asked on
JavaScriptASP.NET
5 Comments1 Solution1247 ViewsLast Modified:
I am learning to develop a webservice and have created a quick project in Visual Studio 2008 to test the concepts.  The namespace I chose to use is 'ASMX.TEST'.  My webservice works fine when run directly from IE7, but when I try to call it from an ASPX page I get an error 'ASMX' is undefined.  I've been pulling out what little hair I have left on this and would sincerely appreciate any help.  Code follows:
EmployeeServiceClient.aspx---
<%@ Page Language="VB" %>
<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="ajax" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>Web Service Test</title>
    <script type="text/javascript">

    function pageLoad() {
        ASMX.TEST.EmployeeService.GetEmployees(FillEmployeeList);
    }
    function FillEmployeeList(result) {
        try {
            var select = document.getElementById("Select1");
            alert("Fill Employee List: " + result.length);
            for (var i = 0; i < result.length; i++) {
                alert("Fill Employee List: " + result[i].LastName);
                var option = new Option(result[i].EmployeeID,
                            result[i].EmployeeID);
                select.options.add(option);
            }
        }
        catch (err) {
            txt = "There was an error on this page.\n\n";
            txt += "Error description: " + err.description + "\n\n";
            txt += "Click OK to continue.\n\n";
            alert(txt);
        }
    }
    function ErrorHandler(result) {
          var msg = result.get_exceptionType() + "\r\n";
          msg += result.get_message() + "\r\n";
          msg += result.get_stackTrace();
          alert(msg);
    }
    function TimeOutHandler(result) {
          alert("Timeout :" + result);
    }

    </script>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <ajax:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server">
            <Services>
                <asp:ServiceReference Path="EmployeeService.asmx" />
            </Services>
        </ajax:ToolkitScriptManager>
    </div>
    <table>
        <tr>
            <td colspan="2">
                <asp:Label ID="Label4" runat="server" Text="Employee Management" style="font-size: larger"></asp:Label>
            </td>
        </tr>
        <tr>
            <td style="width: 100px">
                <asp:Label ID="Label1" runat="server" Text="Employee ID:" />
            </td>
            <td style="width: 100px">
                <select id="Select1">
                </select>
            </td>
        </tr>
        <tr>
            <td style="width: 100px">
                <asp:Label ID="Label2" runat="server" Text="First Name :"></asp:Label>
            </td>
            <td style="width: 100px">
                <input id="Text1" type="text" />
            </td>
        </tr>
        <tr>
            <td style="width: 100px">
                <asp:Label ID="Label3" runat="server" Text="Last Name :"></asp:Label>
            </td>
            <td style="width: 100px">
                 <input id="Text2" type="text" />
            </td>
        </tr>
        <tr>
            <td align="center" colspan="2">
                <input id="Button3" type="button" value="Insert" />
                <input id="Button4" type="button" value="Update" />
                <input id="Button5" type="button" value="Delete" />
            </td>
        </tr>
        <tr>
            <td align="center" colspan="2">
                <span id="lblMsg" style="font-weight: bold; color: red;"></span>
            </td>
        </tr>
    </table>
    
    </form>
    </body>
</html>
=========================================
EmployeeService.vb ----
Imports System.Web
Imports System.Web.Services
Imports System.Web.Script.Services
Imports System.Data
Imports System.Data.SqlClient
Imports System.Configuration
Imports System.Collections.Generic

Namespace ASMX.TEST
    <WebService(Namespace:="ASMX.TEST", Name:="EmployeeService")> _
        <WebServiceBinding(ConformsTo:=WsiProfiles.BasicProfile1_1)> _
        <ScriptService()> _
        <GenerateScriptType(GetType(Employee))> _
        <Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()> _
        Public Class EmployeeService
        Inherits System.Web.Services.WebService

        Private strConn As String = ConfigurationManager.ConnectionStrings("connstr").ConnectionString

        <WebMethod()> _
        Public Sub EmployeeService()
            strConn = ConfigurationManager.ConnectionStrings("connstr").ConnectionString
        End Sub

        <WebMethod()> _
        <ScriptMethod(ResponseFormat:=ResponseFormat.Json)> _
        Public Function GetEmployees() As Employee()
            Dim conn As New SqlConnection(strConn)
            conn.Open()
            Dim cmd As New SqlCommand
            cmd.Connection = conn
            cmd.CommandText = "SELECT EmployeeID, FirstName, LastName FROM Test"
            Dim reader As SqlDataReader = cmd.ExecuteReader
            Dim list As New List(Of Employee)
            While (reader.Read())
                Dim emp As New Employee
                emp.EmployeeID = reader.GetInt32(0)
                emp.FirstName = reader.GetString(1)
                emp.LastName = reader.GetString(2)
                list.Add(emp)
            End While
            reader.Close()
            conn.Close()
            Dim rslt As Employee() = list.ToArray
            Return list.ToArray()
        End Function

        <WebMethod()> _
        Public Function GetEmployee(ByVal pEmployeeID As Integer) As Employee
            Dim conn As New SqlConnection(strConn)
            conn.Open()
            Dim cmd As New SqlCommand
            cmd.Connection = conn
            cmd.CommandText = "SELECT EmployeeID, FirstName, LastName FROM Test WHERE EmployeeID=@id"
            Dim id As New SqlParameter("@id", pEmployeeID)
            cmd.Parameters.Add(id)
            Dim reader As SqlDataReader = cmd.ExecuteReader
            Dim emp As New Employee
            While (reader.Read())
                emp.EmployeeID = reader.GetInt32(0)
                emp.FirstName = reader.GetString(1)
                emp.LastName = reader.GetString(2)
            End While
            reader.Close()
            conn.Close()
            Return emp
        End Function

        <WebMethod()> _
        Public Function Insert(ByVal pFirstName As String, ByVal pLastName As String) As Integer
            Dim conn As New SqlConnection(strConn)
            conn.Open()
            Dim cmd As New SqlCommand
            cmd.Connection = conn
            cmd.CommandText = "INSERT INTO Test (FirstName, LastName) VALUES (@fname,@lname)"
            Dim fname As New SqlParameter("@fname", pFirstName)
            Dim lname As New SqlParameter("@lname", pLastName)
            cmd.Parameters.Add(fname)
            cmd.Parameters.Add(lname)
            Dim EmpID As Integer = cmd.ExecuteNonQuery()
            conn.Close()
            Return EmpID
        End Function

        <WebMethod()> _
        Public Function Update(ByVal pEmployeeID As Integer, ByVal pFirstName As String, ByVal pLastName As String) As Integer
            Dim conn As New SqlConnection(strConn)
            conn.Open()
            Dim cmd As New SqlCommand
            cmd.Connection = conn
            cmd.CommandText = "UPDATE Test SET FirstName=@fname,LastName=@lname WHERE EmployeeID=@id"
            Dim fname As New SqlParameter("@fname", pFirstName)
            Dim lname As New SqlParameter("@lname", pLastName)
            Dim id As New SqlParameter("@id", pEmployeeID)
            cmd.Parameters.Add(fname)
            cmd.Parameters.Add(lname)
            cmd.Parameters.Add(id)
            Dim ReturnValue As Integer = cmd.ExecuteNonQuery()
            conn.Close()
            Return ReturnValue
        End Function

        <WebMethod()> _
        Public Function Delete(ByVal pEmployeeID As Integer) As Integer
            Dim conn As New SqlConnection(strConn)
            conn.Open()
            Dim cmd As New SqlCommand
            cmd.Connection = conn
            cmd.CommandText = "DELETE Test WHERE EmployeeID=@id"
            Dim id As New SqlParameter("@id", pEmployeeID)
            cmd.Parameters.Add(id)
            Dim ReturnValue As Integer = cmd.ExecuteNonQuery()
            conn.Close()
            Return ReturnValue
        End Function
    End Class
End Namespace
============================================
WSDL ----
<?xml version="1.0" encoding="utf-8"?>
<wsdl:definitions xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:tm="http://microsoft.com/wsdl/mime/textMatching/" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:mime="http://schemas.xmlsoap.org/wsdl/mime/" xmlns:tns="ASMX.TEST" xmlns:s="http://www.w3.org/2001/XMLSchema" xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/" xmlns:http="http://schemas.xmlsoap.org/wsdl/http/" targetNamespace="ASMX.TEST" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/">
  <wsdl:types>
    <s:schema elementFormDefault="qualified" targetNamespace="ASMX.TEST">
      <s:element name="EmployeeService">
        <s:complexType />
      </s:element>
      <s:element name="EmployeeServiceResponse">
        <s:complexType />
      </s:element>
      <s:element name="GetEmployees">
        <s:complexType />
      </s:element>
      <s:element name="GetEmployeesResponse">
        <s:complexType>
          <s:sequence>
            <s:element minOccurs="0" maxOccurs="1" name="GetEmployeesResult" type="tns:ArrayOfEmployee" />
          </s:sequence>
        </s:complexType>
      </s:element>
      <s:complexType name="ArrayOfEmployee">
        <s:sequence>
          <s:element minOccurs="0" maxOccurs="unbounded" name="Employee" nillable="true" type="tns:Employee" />
        </s:sequence>
      </s:complexType>
      <s:complexType name="Employee">
        <s:sequence>
          <s:element minOccurs="1" maxOccurs="1" name="EmployeeID" type="s:int" />
          <s:element minOccurs="0" maxOccurs="1" name="FirstName" type="s:string" />
          <s:element minOccurs="0" maxOccurs="1" name="LastName" type="s:string" />
        </s:sequence>
      </s:complexType>
      <s:element name="GetEmployee">
        <s:complexType>
          <s:sequence>
            <s:element minOccurs="1" maxOccurs="1" name="pEmployeeID" type="s:int" />
          </s:sequence>
        </s:complexType>
      </s:element>
      <s:element name="GetEmployeeResponse">
        <s:complexType>
          <s:sequence>
            <s:element minOccurs="0" maxOccurs="1" name="GetEmployeeResult" type="tns:Employee" />
          </s:sequence>
        </s:complexType>
      </s:element>
      <s:element name="Insert">
        <s:complexType>
          <s:sequence>
            <s:element minOccurs="0" maxOccurs="1" name="pFirstName" type="s:string" />
            <s:element minOccurs="0" maxOccurs="1" name="pLastName" type="s:string" />
          </s:sequence>
        </s:complexType>
      </s:element>
      <s:element name="InsertResponse">
        <s:complexType>
          <s:sequence>
            <s:element minOccurs="1" maxOccurs="1" name="InsertResult" type="s:int" />
          </s:sequence>
        </s:complexType>
      </s:element>
      <s:element name="Update">
        <s:complexType>
          <s:sequence>
            <s:element minOccurs="1" maxOccurs="1" name="pEmployeeID" type="s:int" />
            <s:element minOccurs="0" maxOccurs="1" name="pFirstName" type="s:string" />
            <s:element minOccurs="0" maxOccurs="1" name="pLastName" type="s:string" />
          </s:sequence>
        </s:complexType>
      </s:element>
      <s:element name="UpdateResponse">
        <s:complexType>
          <s:sequence>
            <s:element minOccurs="1" maxOccurs="1" name="UpdateResult" type="s:int" />
          </s:sequence>
        </s:complexType>
      </s:element>
      <s:element name="Delete">
        <s:complexType>
          <s:sequence>
            <s:element minOccurs="1" maxOccurs="1" name="pEmployeeID" type="s:int" />
          </s:sequence>
        </s:complexType>
      </s:element>
      <s:element name="DeleteResponse">
        <s:complexType>
          <s:sequence>
            <s:element minOccurs="1" maxOccurs="1" name="DeleteResult" type="s:int" />
          </s:sequence>
        </s:complexType>
      </s:element>
    </s:schema>
  </wsdl:types>
  <wsdl:message name="EmployeeServiceSoapIn">
    <wsdl:part name="parameters" element="tns:EmployeeService" />
  </wsdl:message>
  <wsdl:message name="EmployeeServiceSoapOut">
    <wsdl:part name="parameters" element="tns:EmployeeServiceResponse" />
  </wsdl:message>
  <wsdl:message name="GetEmployeesSoapIn">
    <wsdl:part name="parameters" element="tns:GetEmployees" />
  </wsdl:message>
  <wsdl:message name="GetEmployeesSoapOut">
    <wsdl:part name="parameters" element="tns:GetEmployeesResponse" />
  </wsdl:message>
  <wsdl:message name="GetEmployeeSoapIn">
    <wsdl:part name="parameters" element="tns:GetEmployee" />
  </wsdl:message>
  <wsdl:message name="GetEmployeeSoapOut">
    <wsdl:part name="parameters" element="tns:GetEmployeeResponse" />
  </wsdl:message>
  <wsdl:message name="InsertSoapIn">
    <wsdl:part name="parameters" element="tns:Insert" />
  </wsdl:message>
  <wsdl:message name="InsertSoapOut">
    <wsdl:part name="parameters" element="tns:InsertResponse" />
  </wsdl:message>
  <wsdl:message name="UpdateSoapIn">
    <wsdl:part name="parameters" element="tns:Update" />
  </wsdl:message>
  <wsdl:message name="UpdateSoapOut">
    <wsdl:part name="parameters" element="tns:UpdateResponse" />
  </wsdl:message>
  <wsdl:message name="DeleteSoapIn">
    <wsdl:part name="parameters" element="tns:Delete" />
  </wsdl:message>
  <wsdl:message name="DeleteSoapOut">
    <wsdl:part name="parameters" element="tns:DeleteResponse" />
  </wsdl:message>
  <wsdl:portType name="EmployeeServiceSoap">
    <wsdl:operation name="EmployeeService">
      <wsdl:input message="tns:EmployeeServiceSoapIn" />
      <wsdl:output message="tns:EmployeeServiceSoapOut" />
    </wsdl:operation>
    <wsdl:operation name="GetEmployees">
      <wsdl:input message="tns:GetEmployeesSoapIn" />
      <wsdl:output message="tns:GetEmployeesSoapOut" />
    </wsdl:operation>
    <wsdl:operation name="GetEmployee">
      <wsdl:input message="tns:GetEmployeeSoapIn" />
      <wsdl:output message="tns:GetEmployeeSoapOut" />
    </wsdl:operation>
    <wsdl:operation name="Insert">
      <wsdl:input message="tns:InsertSoapIn" />
      <wsdl:output message="tns:InsertSoapOut" />
    </wsdl:operation>
    <wsdl:operation name="Update">
      <wsdl:input message="tns:UpdateSoapIn" />
      <wsdl:output message="tns:UpdateSoapOut" />
    </wsdl:operation>
    <wsdl:operation name="Delete">
      <wsdl:input message="tns:DeleteSoapIn" />
      <wsdl:output message="tns:DeleteSoapOut" />
    </wsdl:operation>
  </wsdl:portType>
  <wsdl:binding name="EmployeeServiceSoap" type="tns:EmployeeServiceSoap">
    <soap:binding transport="http://schemas.xmlsoap.org/soap/http" />
    <wsdl:operation name="EmployeeService">
      <soap:operation soapAction="ASMX.TEST/EmployeeService" style="document" />
      <wsdl:input>
        <soap:body use="literal" />
      </wsdl:input>
      <wsdl:output>
        <soap:body use="literal" />
      </wsdl:output>
    </wsdl:operation>
    <wsdl:operation name="GetEmployees">
      <soap:operation soapAction="ASMX.TEST/GetEmployees" style="document" />
      <wsdl:input>
        <soap:body use="literal" />
      </wsdl:input>
      <wsdl:output>
        <soap:body use="literal" />
      </wsdl:output>
    </wsdl:operation>
    <wsdl:operation name="GetEmployee">
      <soap:operation soapAction="ASMX.TEST/GetEmployee" style="document" />
      <wsdl:input>
        <soap:body use="literal" />
      </wsdl:input>
      <wsdl:output>
        <soap:body use="literal" />
      </wsdl:output>
    </wsdl:operation>
    <wsdl:operation name="Insert">
      <soap:operation soapAction="ASMX.TEST/Insert" style="document" />
      <wsdl:input>
        <soap:body use="literal" />
      </wsdl:input>
      <wsdl:output>
        <soap:body use="literal" />
      </wsdl:output>
    </wsdl:operation>
    <wsdl:operation name="Update">
      <soap:operation soapAction="ASMX.TEST/Update" style="document" />
      <wsdl:input>
        <soap:body use="literal" />
      </wsdl:input>
      <wsdl:output>
        <soap:body use="literal" />
      </wsdl:output>
    </wsdl:operation>
    <wsdl:operation name="Delete">
      <soap:operation soapAction="ASMX.TEST/Delete" style="document" />
      <wsdl:input>
        <soap:body use="literal" />
      </wsdl:input>
      <wsdl:output>
        <soap:body use="literal" />
      </wsdl:output>
    </wsdl:operation>
  </wsdl:binding>
  <wsdl:binding name="EmployeeServiceSoap12" type="tns:EmployeeServiceSoap">
    <soap12:binding transport="http://schemas.xmlsoap.org/soap/http" />
    <wsdl:operation name="EmployeeService">
      <soap12:operation soapAction="ASMX.TEST/EmployeeService" style="document" />
      <wsdl:input>
        <soap12:body use="literal" />
      </wsdl:input>
      <wsdl:output>
        <soap12:body use="literal" />
      </wsdl:output>
    </wsdl:operation>
    <wsdl:operation name="GetEmployees">
      <soap12:operation soapAction="ASMX.TEST/GetEmployees" style="document" />
      <wsdl:input>
        <soap12:body use="literal" />
      </wsdl:input>
      <wsdl:output>
        <soap12:body use="literal" />
      </wsdl:output>
    </wsdl:operation>
    <wsdl:operation name="GetEmployee">
      <soap12:operation soapAction="ASMX.TEST/GetEmployee" style="document" />
      <wsdl:input>
        <soap12:body use="literal" />
      </wsdl:input>
      <wsdl:output>
        <soap12:body use="literal" />
      </wsdl:output>
    </wsdl:operation>
    <wsdl:operation name="Insert">
      <soap12:operation soapAction="ASMX.TEST/Insert" style="document" />
      <wsdl:input>
        <soap12:body use="literal" />
      </wsdl:input>
      <wsdl:output>
        <soap12:body use="literal" />
      </wsdl:output>
    </wsdl:operation>
    <wsdl:operation name="Update">
      <soap12:operation soapAction="ASMX.TEST/Update" style="document" />
      <wsdl:input>
        <soap12:body use="literal" />
      </wsdl:input>
      <wsdl:output>
        <soap12:body use="literal" />
      </wsdl:output>
    </wsdl:operation>
    <wsdl:operation name="Delete">
      <soap12:operation soapAction="ASMX.TEST/Delete" style="document" />
      <wsdl:input>
        <soap12:body use="literal" />
      </wsdl:input>
      <wsdl:output>
        <soap12:body use="literal" />
      </wsdl:output>
    </wsdl:operation>
  </wsdl:binding>
  <wsdl:service name="EmployeeService">
    <wsdl:port name="EmployeeServiceSoap" binding="tns:EmployeeServiceSoap">
      <soap:address location="http://localhost:50787/TestService/EmployeeService.asmx" />
    </wsdl:port>
    <wsdl:port name="EmployeeServiceSoap12" binding="tns:EmployeeServiceSoap12">
      <soap12:address location="http://localhost:50787/TestService/EmployeeService.asmx" />
    </wsdl:port>
  </wsdl:service>
</wsdl:definitions>
ASKER CERTIFIED SOLUTION
Avatar of steve_a_sanders
steve_a_sandersFlag of United States of America image

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Commented:
This problem has been solved!
Unlock 1 Answer and 5 Comments.
See Answers