Simplified development of the WCF client (I)-add service references

Source: Internet
Author: User

This article from: http://blogs.msdn.com/ B /wcftoolsteamblogcn/archive/2009/01/12/wcf.aspx

 

 

Previous blog post"IntroductionVs2008InWCFTools ", You have mentioned adding service reference ...) And auto-attaching. Now we will introduce how to use these two functions to simplify the development and debugging of the client and some tips in use.

This article describes how to add service reference ...).

Familiar with Web Service DevelopmentProgramMembers should be familiar with adding service references. When creating a client program for a service, you do not need to write the underlying communication and interaction of the client from the beginning.CodeYou can enter a service address to add a service so that Visual Studio can generate a client proxy. In this way, accessing the service is just like accessing a local component without worrying about the communication details. If the created client program project and service program project are in the same solution (many developers will also develop the client program during service development ), you can also use Visual Studio to help us discover and add service references.

Now programmers who develop the WCF Service can also benefit from these features. If you create a project from the WCF Service Library (or sequential workflow service library and state machine Workflow under the WCF node) Project template, these functions are ready.

Let's take a look at how to use it:

1. Create a client program, which can be a Windows console program.

2. Add a WCF Service library in the same solution.

3. Build wcfservicelibrary1.

4. Right-click leleapplication1 and choose add service reference from the context menu ).

5. A dialog box is displayed:

6. If you already know the service address, enter the address in the address column to add the service and click go ". You can find the service corresponding to this address.

7. If you want to add a service in the same solution, click discover to find the service. Find the service, select the service that needs to be referenced in the client program, and click OK. At this time, wcfsvchost will automatically start the host service. A few seconds later, we can see that the client automatically generates the Service proxy code:

After adding a service reference on the client, you can access the service now. You only need to use the following two lines of code to call a method on the server:

Servicereference1.service1client client = new servicereference1.service1client ();

Client. getdata (0 );

 

Tips and notes:

 

 

 

1. There are four project templates under the WCF node of vs2008, but the syndication service library project does not have this function, because this service does not provide metadata.
2. Before "discovering" a service, you must first build the server project (that is, the first step is required) to ensure that the added service reference is up-to-date. We will further simplify Visual Studio in future versions.

 

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.