Notice: This website is an unofficial Microsoft Knowledge Base (hereinafter KB) archive and is intended to provide a reliable access to deleted content from Microsoft KB. All KB articles are owned by Microsoft Corporation. Read full disclaimer for more details.

PRB: "Server Error" Error Message While Trying to Call a Web Service Remotely


View products that this article applies to.

Symptoms

When you create an ASP.NET Web service on your computer, and then you create an ASP.NET Web application remotely on another computer and add the ASP.NET Web service that you created on your computer as a Web reference, you receive the following error message on the Web browser:

Server Error in '/<TestWebApplication>' Application.


This problem occurs when you exhaust the Web Service method of the ASP.NET Web service that is created on your computer.

↑ Back to the top


Cause

You can use localhost in the URL when you add a Web reference. However, the Web browser considers localhost as the computer where the ASP.NET application runs. Because the Web service does not exist on the computer where the Web application runs, you receive the error message in the "Symptoms" section.

↑ Back to the top


Resolution

You can resolve this problem when you add a Web reference. In the URL, use the IP address of the computer where the Web service is created instead of using localhost. This is an example of how to do this:

https://10.150.144.111/TestWebService/Service1.asmx
For code changes, you can follow the commented instructions in the Button1_Click() method of the Web application code sample in the "More Information" section.

↑ Back to the top


Status

This behavior is by design.

↑ Back to the top


More information

Steps to Reproduce the Problem

Create a Web Service

  1. Start Microsoft Visual Studio .NET.
  2. On the File menu, point to New and then click Project.
  3. Select Visual C# Projects or Visual Basic Projects from Project Types. Select ASP.NET Web Service from Templates.
  4. Type http://localhost/TestWebService in the Location text box and then click OK.
  5. Double-click Service.asmx and then replace the existing code with the following code in Service1.asmx:

    Visual C# .NET Code:
    using System;
    using System.Collections;
    using System.ComponentModel;
    using System.Data;
    using System.Diagnostics;
    using System.Web;
    using System.Web.Services;
    
    namespace TestWebService
    {
    	/// <summary>
    	/// Summary description for Service1.
    	/// </summary>
    	public class Service1 : System.Web.Services.WebService
    	{
    		public Service1()
    		{
    			//CODEGEN: This call is required by the ASP.NET Web Services Designer.
    			InitializeComponent();
    		}
    
    		#region Component Designer generated code
    		
    		//Required by the Web Services Designer.
    		private IContainer components = null;
    				
    		/// <summary>
    		/// Required method for Designer support. Do not modify.
    		/// The contents of this method with the code editor.
    		/// </summary>
    		private void InitializeComponent()
    		{
    		}
    
    		/// <summary>
    		/// Clean up any resources being used.
    		/// </summary>
    		protected override void Dispose( bool disposing )
    		{
    			if(disposing && components != null)
    			{
    				components.Dispose();
    			}
    			base.Dispose(disposing);		
    		}
    		
    		#endregion
    
    		// WEB SERVICE EXAMPLE
    		// The HelloWorld() example service returns the string Hello World.
    		// To build, uncomment the following lines and then save and build the project.
    		// To test this Web service, press F5.
    
    		[WebMethod]
    		public string HelloWorld()
    		{
    			return "Hello World";
    		}
    	}
    }
    

    Visual Basic .NET Code:
    Imports System.Web.Services
    
    <System.Web.Services.WebService(Namespace := "http://tempuri.org/TestWebService/Service1")> _
    Public Class Service1
        Inherits System.Web.Services.WebService
    
    #Region " Web Services Designer Generated Code "
    
        Public Sub New()
            MyBase.New()
    
            'This call is required by the Web Services Designer.
            InitializeComponent()
    
            'Add your own initialization code after the InitializeComponent() call.
    
        End Sub
    
        'Required by the Web Services Designer.
        Private components As System.ComponentModel.IContainer
    
        'Note that the following procedure is required by the Web Services Designer.
        'It can be modified by using the Web Services Designer.  
        'Do not modify it by using the code editor.
        <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
            components = New System.ComponentModel.Container()
        End Sub
    
        Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
            'CODEGEN: This procedure is required by the Web Services Designer.
            'Do not modify it by using the code editor.
            If disposing Then
                If Not (components Is Nothing) Then
                    components.Dispose()
                End If
            End If
            MyBase.Dispose(disposing)
        End Sub
    
    #End Region
    
        ' WEB SERVICE EXAMPLE
        ' The HelloWorld() example service returns the string Hello World.
        ' To build, uncomment the following lines and then save and build the project.
        ' To test this Web service, make sure that the .asmx file is the start page.
        ' and press F5.
        '
        <WebMethod()> _
        Public Function HelloWorld() As String
            Return "Hello World"
        End Function
    
    End Class
    
  6. On the Build menu, click Build Solution.

Create a Web Application

  1. Start another instance of Visual Studio .NET.
  2. On the File menu, point to New and then click Project.
  3. Select Visual C# Projects or Visual Basic Projects from Project Types. Select ASP.NET Web Application from Templates.
  4. Type http://<remoteserver>/TestWebApplication in the Location text box and then click OK.

    Note The name of the remote server where the ASP.NET Web application is created is named <remoteserver>.
  5. Right-click WebForm1.aspx, click View HTML Source, and then replace the existing code with the following code:

    Visual C# .NET Project:
    <%@ Page language="c#" Codebehind="WebForm1.aspx.cs" AutoEventWireup="false" Inherits="TestWebApplication.WebForm1" %>
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
    <HTML>
    	<HEAD>
    		<title>WebForm1</title>
    		<meta name="GENERATOR" Content="Microsoft Visual Studio .NET 7.1">
    		<meta name="CODE_LANGUAGE" Content="C#">
    		<meta name="vs_defaultClientScript" content="JavaScript">
    		<meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5">
    	</HEAD>
    	<body MS_POSITIONING="GridLayout">
    		<form id="Form1" method="post" runat="server">
    			<asp:Button id="Button1" style="Z-INDEX: 101; LEFT: 240px; POSITION: absolute; TOP: 224px" runat="server"
    				Text="Hello" Width="256px" Height="64px"></asp:Button>
    			<asp:Label id="Label1" style="Z-INDEX: 102; LEFT: 232px; POSITION: absolute; TOP: 96px" runat="server"
    				Width="264px" Height="72px"></asp:Label>
    		</form>
    	</body>
    </HTML>
    Visual Basic .NET Project:
    <%@ Page Language="vb" AutoEventWireup="false" Codebehind="WebForm1.aspx.vb" Inherits="TestWebApplication.WebForm1"%>
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
    <HTML>
    	<HEAD>
    		<title>WebForm1</title>
    		<meta name="GENERATOR" content="Microsoft Visual Studio .NET 7.1">
    		<meta name="CODE_LANGUAGE" content="Visual Basic .NET 7.1">
    		<meta name="vs_defaultClientScript" content="JavaScript">
    		<meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5">
    	</HEAD>
    	<body MS_POSITIONING="GridLayout">
    		<form id="Form1" method="post" runat="server">
    			<asp:Button id="Button1" style="Z-INDEX: 101; LEFT: 224px; POSITION: absolute; TOP: 160px" runat="server"
    				Text="Hello" Width="280px" Height="72px"></asp:Button>
    			<asp:Label id="Label1" style="Z-INDEX: 102; LEFT: 224px; POSITION: absolute; TOP: 72px" runat="server"
    				Width="280px" Height="56px"></asp:Label>
    		</form>
    	</body>
    </HTML>
  6. In Solution Explorer, right-click Reference and then click Add Web Reference.
  7. Type http://localhost/TestWebService/Service1.asmx in the URL text box and then click Go.
  8. Click Add Reference.
  9. Replace the existing code with the following code in WebForm1.aspx.cs or in WebForm1.aspx.vb:

    Visual C# .NET Code:
    using System;
    using System.Collections;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Web;
    using System.Web.SessionState;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Web.UI.HtmlControls;
    
    namespace TestWebApplication
    {
    	/// <summary>
    	/// Summary description for WebForm1.
    	/// </summary>
    	public class WebForm1 : System.Web.UI.Page
    	{
    		protected System.Web.UI.WebControls.Button Button1;
    		protected System.Web.UI.WebControls.Label Label1;
    	
    		private void Page_Load(object sender, System.EventArgs e)
    		{
    			// Put user code to initialize the page here.
    		}
    
    		#region Web Form Designer generated code
    		override protected void OnInit(EventArgs e)
    		{
    			//
    			// CODEGEN: This call is required by the ASP.NET Web Form Designer.
    			//
    			InitializeComponent();
    			base.OnInit(e);
    		}
    		
    		/// <summary>
    		/// Required method for Designer support. Do not modify.
    		/// The contents of this method with the code editor.
    		/// </summary>
    		private void InitializeComponent()
    		{    
    			this.Button1.Click += new System.EventHandler(this.Button1_Click);
    			this.Load += new System.EventHandler(this.Page_Load);
    
    		}
    		#endregion
    
    		private void Button1_Click(object sender, System.EventArgs e)
    		{
    			localhost.Service1 obj1 = new localhost.Service1();
    			// Uncomment the following line then and comment the previous line of code to resolve the problem.
    			// WebReference.Service1 obj1 = new WebReference.Service1();
    			Label1.Text = obj1.HelloWorld();
    		}
    	}
    }
    
    Visual Basic .NET Code:
    Public Class WebForm1
        Inherits System.Web.UI.Page
    
    #Region " Web Form Designer Generated Code "
    
        'This call is required by the Web Form Designer.
        <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
    
        End Sub
        Protected WithEvents Button1 As System.Web.UI.WebControls.Button
        Protected WithEvents Label1 As System.Web.UI.WebControls.Label
    
        'Note that the following placeholder declaration is required by the Web Form Designer.
        'Do not delete or move it.
        Private designerPlaceholderDeclaration As System.Object
    
        Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
            'CODEGEN: This method call is required by the Web Form Designer.
            'Do not modify it by using the code editor.
            InitializeComponent()
        End Sub
    
    #End Region
    
        Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            'Put user code to initialize the page here
        End Sub
    
        Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
            Dim obj1 As New localhost.Service1
            ' Uncomment the following line and then comment the previous line of code to resolve the problem.
            'Dim obj1 As New WebReference.Service1
            Label1.Text = obj1.HelloWorld()
        End Sub
    End Class
    
  10. On the Build menu, click Build Solution.

Test the Web Service

  1. On the Debug menu, click Start.
  2. In the Web browser, click Hello.

    You receive the error message in the "Symptoms" section.

↑ Back to the top


References

For more information about ASP.NET, visit the following Microsoft Web site:
http://msdn2.microsoft.com/en-us/library/4w3ex9c2(vs.71).aspx

For additional information about how to create an ASP.NET Web application on a remote Web server, click the following article number to view the article in the Microsoft Knowledge Base:
822316� HOW TO: Create a New ASP.NET Web Application on a Remote Web Server

↑ Back to the top


Keywords: kburlmon, kbwebservices, kbwebserver, kbwebbrowser, kbremoting, kbaspobj, kbprb, kberrmsg, KB822323

↑ Back to the top

Article Info
Article ID : 822323
Revision : 5
Created on : 5/23/2007
Published on : 5/23/2007
Exists online : False
Views : 334