Microsoft KB Archive/822323

= PRB: &quot;Server Error&quot; Error Message While Trying to Call a Web Service Remotely =

Article ID: 822323

Article Last Modified on 5/23/2007

-

APPLIES TO


 * Microsoft Web Services Enhancements for Microsoft .NET 1.1
 * Microsoft ASP.NET 1.1

-





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 '/' Application.

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



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 &quot;Symptoms&quot; section.



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 &quot;More Information&quot; section.



STATUS
This behavior is by design.



MORE INFORMATION
Steps to Reproduce the Problem

Create a Web Service
 Start Microsoft Visual Studio .NET. On the File menu, point to New and then click Project. Select Visual C# Projects or Visual Basic Projects from Project Types. Select ASP.NET Web Service from Templates. Type http://localhost/TestWebService in the Location text box and then click OK.  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 description for Service1. ///    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; ///        /// Required method for Designer support. Do not modify. /// The contents of this method with the code editor. ///        private void InitializeComponent {       }

///        /// Clean up any resources being used. ///        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 &quot;Hello World&quot;; }   } }

Visual Basic .NET Code: Imports System.Web.Services

<System.Web.Services.WebService(Namespace := &quot;http://tempuri.org/TestWebService/Service1&quot;)> _ Public Class Service1 Inherits System.Web.Services.WebService


 * 1) Region &quot; Web Services Designer Generated Code &quot;

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


 * 1) 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 &quot;Hello World&quot; End Function

End Class </li> On the Build menu, click Build Solution.</li></ol>

Create a Web Application
<ol> Start another instance of Visual Studio .NET.</li> On the File menu, point to New and then click Project.</li> Select Visual C# Projects or Visual Basic Projects from Project Types. Select ASP.NET Web Application from Templates.</li> Type http:// /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 .</li>  Right-click WebForm1.aspx, click View HTML Source, and then replace the existing code with the following code:

Visual C# .NET Project: <%@ Page language=&quot;c#&quot; Codebehind=&quot;WebForm1.aspx.cs&quot; AutoEventWireup=&quot;false&quot; Inherits=&quot;TestWebApplication.WebForm1&quot; %> <!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 4.0 Transitional//EN&quot; > <HTML> <HEAD> WebForm1 <meta name=&quot;GENERATOR&quot; Content=&quot;Microsoft Visual Studio .NET 7.1&quot;> <meta name=&quot;CODE_LANGUAGE&quot; Content=&quot;C#&quot;> <meta name=&quot;vs_defaultClientScript&quot; content=&quot;JavaScript&quot;> <meta name=&quot;vs_targetSchema&quot; content=&quot;http://schemas.microsoft.com/intellisense/ie5&quot;> </HEAD> <body MS_POSITIONING=&quot;GridLayout&quot;> <form id=&quot;Form1&quot; method=&quot;post&quot; runat=&quot;server&quot;> <asp:Button id=&quot;Button1&quot; style=&quot;Z-INDEX: 101; LEFT: 240px; POSITION: absolute; TOP: 224px&quot; runat=&quot;server&quot; Text=&quot;Hello&quot; Width=&quot;256px&quot; Height=&quot;64px&quot;></asp:Button> <asp:Label id=&quot;Label1&quot; style=&quot;Z-INDEX: 102; LEFT: 232px; POSITION: absolute; TOP: 96px&quot; runat=&quot;server&quot; Width=&quot;264px&quot; Height=&quot;72px&quot;></asp:Label> </HTML> Visual Basic .NET Project: <%@ Page Language=&quot;vb&quot; AutoEventWireup=&quot;false&quot; Codebehind=&quot;WebForm1.aspx.vb&quot; Inherits=&quot;TestWebApplication.WebForm1&quot;%> <!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 4.0 Transitional//EN&quot;> <HTML> <HEAD> WebForm1 <meta name=&quot;GENERATOR&quot; content=&quot;Microsoft Visual Studio .NET 7.1&quot;> <meta name=&quot;CODE_LANGUAGE&quot; content=&quot;Visual Basic .NET 7.1&quot;> <meta name=&quot;vs_defaultClientScript&quot; content=&quot;JavaScript&quot;> <meta name=&quot;vs_targetSchema&quot; content=&quot;http://schemas.microsoft.com/intellisense/ie5&quot;> </HEAD> <body MS_POSITIONING=&quot;GridLayout&quot;> <form id=&quot;Form1&quot; method=&quot;post&quot; runat=&quot;server&quot;> <asp:Button id=&quot;Button1&quot; style=&quot;Z-INDEX: 101; LEFT: 224px; POSITION: absolute; TOP: 160px&quot; runat=&quot;server&quot; Text=&quot;Hello&quot; Width=&quot;280px&quot; Height=&quot;72px&quot;></asp:Button> <asp:Label id=&quot;Label1&quot; style=&quot;Z-INDEX: 102; LEFT: 224px; POSITION: absolute; TOP: 72px&quot; runat=&quot;server&quot; Width=&quot;280px&quot; Height=&quot;56px&quot;></asp:Label> </HTML> </li> In Solution Explorer, right-click Reference and then click Add Web Reference.</li> Type http://localhost/TestWebService/Service1.asmx in the URL text box and then click Go.</li> Click Add Reference.</li>  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 description for WebForm1. ///    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); }       ///         /// Required method for Designer support. Do not modify. /// The contents of this method with the code editor. ///        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


 * 1) Region &quot; Web Form Designer Generated Code &quot;

'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


 * 1) 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 </li> On the Build menu, click Build Solution.</li></ol>

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 &quot;Symptoms&quot; section.

<div class="references_section">