Solutions for Web References __web

Source: Internet
Author: User
Tags soap wsdl

Adding Web references is a necessary skill in the development of the network age. However, adding a Web reference is not a simple technique. While it's easy to add a Web reference to the IDE by right-clicking on it, it looks simple, but it's not. I'm here to summarize the method of adding Web references, there are two ways to add Web references, one of which is the former, and the second is the way of acting. the first is implemented in an integrated environment by adding a dialog box.

How to add and remove Web references through an integrated environment

Web references enable a project to use one or more XML Web services. Use the Add Web Reference dialog box to search for WEB services on your local, local area network, or Internet.

After you add a Web reference to the current project, you can invoke any methods exposed through the Web service.

To add a Web reference to a project

1. In Solution Explorer, right-click the name of the target project for which you want to add a Web service, and then click Add Web Reference.

The Add Web Reference dialog box appears.

2. In the URL box, enter the URL of the WEB service you want to use. If you don't know the URL, use the links in the Navigation Pane to find the Web service you want.

Attention

If you are developing a Web application on a computer that is behind a firewall and your application will use a Web service that is outside the firewall, you must include the address and port of the network proxy server in the URL. Consult your network administrator to find out how to provide the URL path for this section.

3. In the Web services located on this URL box, select the Web service that you want to use.

4. Verify that the project is able to use the WEB service and that all external code provided is trustworthy.

Security attention

When you open an item that contains a Web reference to edit, the local proxy file for the Web service that you are using runs in a Devenv.exe process initiated by a trusted user (yourself). When you open a project or component in the Integrated development environment (IDE), code is executed on your local computer.

5. Enter a name in the Web reference name field that you will use to programmatically access the selected Web service in your code.

Attention

By default, the Web reference is assigned a namespace that corresponds to its server name. You can change this value and enter a custom namespace name. There are certain restrictions on acceptable namespace names. For more information about characters that are not allowed in the Web reference name, see the Add Web Reference dialog box. The Visual Web Developer creates a namespace based on a Web reference name by generating a nested folder hierarchy. In the top-level folder, you create a. wsdl file that references the Web service, and also create supporting files, such as Discovery (. Disco and. discomap) files that contain information about the location of the Web service.

6. Click "Add Reference".

To remove a Web reference

If your project no longer requires a Web reference to XML Web services, you can remove it from your project. the second method is implemented through the proxy class.

This approach is through the Wsdl.exe tool, creating a remote service proxy class, that is, a local class, by adding the class to the project, the direct use of the class to achieve similar and the first way to add a reference to the effect. A good thing about this is that by parsing Web services yourself, you can separate the addresses of Web services, put them in a configuration file, and then resolve the addresses yourself. The following figure, the use of the project I used, put the address in an XML file, and then read the address from the XML file, at the address of the read to invoke the service AH. And if you take one of the previous ways, the address is fixed and will be compiled into a DLL, and you'll have to recompile the DLL if you want to change the service address. If implemented in the second way, we do not have to recompile, just need to change the address in the configuration file can be OH.

Creating an XML Web service proxy

By definition, you can use industry standard protocols (including SOAP) to communicate with Web services over a network. That is, the client and Web service communicate using SOAP messages, and the SOAP message encapsulates input and output parameters as XML. Fortunately for WEB service clients, proxy class processing maps parameters to XML elements and then sends SOAP messages over the network.

A proxy class can be generated whenever a service description exists and the service description conforms to the WEB Service Description Language (WSDL). A service description defines how to communicate with a WEB service. Using the service description, you can use the Wsdl.exe tool to create a proxy class. The Web service client can then invoke a method of the proxy class that communicates with the Web service over the network by processing a SOAP message that is returned to and from the Web service. Because the proxy class communicates with the Web service over the Internet, it is a good idea to verify that the Url property of the proxy class refers to a trusted target.

By default, the proxy class uses SOAP to communicate with the Web service on top of HTTP. However, Wsdl.exe can generate proxy classes that communicate with Web services using the Http-get protocol or the Http-post protocol. To specify that the proxy class should use Http-get or http-post, provide the/protocol switch to the Wsdl.exe tool, as described in the following table.

Using Wsdl.exe to generate XML Web service proxy classes

You can use the Web Service Description Language Tool (Wsdl.exe) at a command prompt to create a proxy class, (at least) to specify the URL to an XML WEB service or service description, or to a path to a saved service description.

Copy Wsdl/language:language/protocol:protocol/namespace:mynamespace/out:filename/username:username/password: Password/domain:domain <url or path>

Attention

The parameters listed here are commonly used by Wsdl.exe. For a complete syntax for Wsdl.exe, see Web Services Description Language Tool (Wsdl.exe).

Parameter values

<url or path>

The URL or path to the service description (the file that describes the Web service in the Web Service Description language).

If you specify a file, a file that contains a description of the service is provided. For example:

mywebservice.wsdl

If you specify a URL, the URL must reference the. asmx page or return the service description. For WEB services created with asp.net, you can use the The WSDL is appended to the URL of the Web service to return the service description. For example

Http://www.contoso.com/MyWebService.asmx?WSDL

/language:language

Generates the language used by the proxy class. Available options include CS, VB, and JS, respectively, C #, Visual Basic. NET, and JScript. Net. The default language is C #. (optional)

/protocol:protocol

The protocol used to communicate with the Web service method. Available options include SOAP, Http-get, and Http-post. The default protocol is SOAP. (optional)

/namespace:mynamespace

The namespace of the generated proxy. The default value is the global namespace. (optional)

/out:filename

The name of the file that contains the proxy class to create. The default name is based on the name of the class that implements the Web service. (optional)

/username:username

The user name to use when connecting to a WEB server that requires authentication. (optional)

/password:password

The password to use when connecting to a WEB server that requires authentication. (optional)

/domain:domain

The domain that is used when connecting to a WEB server that requires authentication. (optional)

Generated proxy class details

When Wsdl.exe is used to generate a proxy class, a source file is generated in the specified language. This file contains a proxy class for the synchronization and asynchronous methods of each Web service method that exposes the Web service. For example, if a Web service contains a Web service method named Add, the proxy class has the following methods for invoking the Add Web service method: Add, BeginAdd, and EndAdd. The Add method of the proxy class is used to communicate with the Add Web service method synchronously, but the BeginAdd and EndAdd methods are used for asynchronous communication with the Web service method. For more information about asynchronous communication with Web service methods, see asynchronous communication with an XML Web service.

Each method of the generated proxy class contains the appropriate code to communicate with the Web service method. If an error occurs during communication with the WEB service and the proxy class, an exception is thrown. For more information about handling exceptions, see Handling and throwing Exceptions in XML Web services.

The order of parameters may vary between the definition order in the Web service method and the associated proxy class method. In most cases, the parameter order is the same. However, if the WEB service requires Document format

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.