How To Use Configuration Files to Specify the URL That Is Used to Locate a Web Service (316928)
The information in this article applies to:
- Microsoft .NET Framework 1.1
- Microsoft .NET Framework 1.0
- Microsoft Visual Studio .NET (2003), Enterprise Architect Edition
- Microsoft Visual Studio .NET (2003), Enterprise Developer Edition
- Microsoft Visual Studio .NET (2003), Professional Edition
- Microsoft Visual Studio .NET (2003), Academic Edition
- Microsoft Visual Studio .NET (2002), Enterprise Architect Edition
- Microsoft Visual Studio .NET (2002), Enterprise Developer Edition
- Microsoft Visual Studio .NET (2002), Professional Edition
- Microsoft Visual Studio .NET (2002), Academic Edition
- Microsoft Web Services (included with the .NET Framework)
This article was previously published under Q316928 SUMMARYThis step-by-step article describes how to use
configuration files to specify the URL that is used to locate a Web
service. back to the
topCreate the Web Service - Start Visual Studio .NET.
- Create a new Microsoft Visual Basic .NET Web service
project.
By default, the Service1.asmx file is
created. - In the Code Window, remove the comment for
the HelloWorld WebMethod.
- On the Build menu, click Build
Solution.
back to the
topUse the Web Service- Start Visual Studio .NET.
- Create a new Visual Basic .NET Windows
application project.
- Add a Web reference to the Web service that was created in the "Create the Web Service" section.
- In the Solution Explorer window under the
Web Reference section, select the Web reference that you
added in step 3.
- On the View menu, click Properties
Window.
- In the Properties window, change the
URL Behavior property from Static to Dynamic.
- On the Build menu, click Build
Solution.
back to the
topCheck the Configuration File- Open the App.config file of the project or the Web.config
file of the project to view the results.
- Locate the "appSettings" section that appears as
follows:
<appSettings>
<add key="Test.localhost.Service1" value="http://localhost/WebService1/Service1.asmx"/>
</appSettings> Note The actual key and the actual value may differ. This depends on the project
name that you provide. The
key is the reference that is used in your application to refer to this
service, and the value is the URL to the Web service. For example, in Visual Basic .NET, to declare a variable as an
instance of this Web service, you can use the following code: Dim objMyService As Test.localhost.Service1 This key has three sections that are separated by periods:
- The namespace for the application project
- The folder name for the Web reference
- The class name of the Web service
To understand the entry in the App.config file, follow these steps: - In Microsoft Visual Studio. NET IDE in the Solution
Explorer window, right-click Project, and then select Properties.
The namespace is
listed in the Properties dialog box. - In Visual Studio. NET IDE in the Solution
Explorer window, right-click Web Reference, and then select Properties.
The folder name appears in the Properties dialog box. - In Visual Studio .NET IDE in the Solution
Explorer window, right-click Web Reference, and then select Properties.
In the source code of the Web service that is the code behind the window for the .asmx
page, the service is implemented as a procedure inside a
class. This is the class name. The application obtains this class
name through the service name attribute in the .wsdl file in the Web reference. back to the
topTroubleshootYou must remember the following points when you use the URL
Behavior property:
- Like all modifications to the Web.config file, if you change
the URL, this causes the application to restart.
Note This only applies to Web applications. - If you change the behavior of the Web reference from
Dynamic to Static, the key and value pair in the App.config file or in the Web.config
file may not be deleted. You must edit the file to verify that
the entry is deleted.
- If the Web reference already has an entry in the
App.config file or in the Web.config file, and you make a modification that affects the
entry (such as changing the folder name for the Web reference), the config
file may not be updated. You can edit the config file, and then type the new data. Or, you can delete
the entry from the file, and then toggle the Web reference behavior to make the
entry regenerate.
- If you do not see an App.config file in the application
directory, toggle the URL Behavior property. After you toggle the URL Behavior property, the App.config
file is created.
back to the
topREFERENCESFor additional information about how to locate XML Web services, visit the following Microsoft
Developer Network (MSDN) Web site: For additional information about how to redirect
an application to target a different XML Web service during installation, visit the following Microsoft
Developer Network (MSDN) Web site:
back to the top
Modification Type: | Minor | Last Reviewed: | 7/13/2004 |
---|
Keywords: | kbHOWTOmaster kbConfig kbDeployment kbinfo kbSysAdmin kbWebServices KB316928 kbAudDeveloper kbAudITPRO |
---|
|