[Translation] WCF Part 4: Make your service visible through metadata

Source: Internet
Author: User

The previous article describes how to create a service and host the service by setting some information in APP. config. This chapter describes how to use metadata to expose the service. The method is very simple. You only need to add an endpoint to expose it. This is another old saying, ABC. This endpoint is called Mex endpoint, which isMEtadataExThe abbreviation of the first letter of the word "change. You do not need to write anyCodeYou only need to configure the configuration file. Open "service configuration Editor" on App. config, open the "advanced" folder, select "service behaviors", and add a new service behavior. Set nEwbehaviorChangeHelloservicebehavior,Click the Add button and select the 'servicemetaddata' option.

 

Next we will configure a new behavior (behavior) for the endpoint ). Select the created service from the node. This part may be the most easily forgotten, but you must bind the configured behavior to this service. In fact, it is very easy to select from the behaviorconfiguration attribute list of the service.
Next, add the Mex endpoint. Right-click the endpoints folder under the service and choose add endpoint. Set the address to http: // localhost: 8080/helloservice/MEX/, select the binding method as "mexhttpbinding", and enter "imetadataexchange" in the contract ". Save and exit the configuration file editor. The following configuration information is displayed:

<?XML Version="1.0" Encoding="UTF-8"?>
 
<Configuration>
 
 
 
<System. servicemodel>
<Behaviors>
 
<Servicebehaviors>
 
<Behavior Name="Helloservicebehavior">
<Servicemetadata/>
 
</Behavior>
 
</Servicebehaviors>
 
</Behaviors>
<Services>
 
<Service Behaviorconfiguration="Helloservicebehavior" Name="Classa. WCF. samples. Hello">
<Endpoint Address="Http: // localhost: 8080/helloservice/" Binding="Basichttpbinding"
 
Bindingconfiguration="" Contract="Classa. WCF. samples. ihello"/>
<Endpoint Address="Http: // localhost: 8080/helloservice/MEX/" Binding="Mexico httpbinding" Bindingconfiguration=""
 
Contract="Imetadataexchange"/>
</Service>
 
</Services>
 
</System. servicemodel>
 
</Configuration>

Run this service by pressing F5. Although it seems that there is no big difference with the previous one, now we can create a proxy. Open Visual Studio command prompt (open the menu Visual Studio 2005/Visual Studio Tools to find it) and execute the following command:
Svcutil.exe/O: client. CS/config: App. config http: // localhost: 8080/helloservice/MEX/
Open the generated file, especially app. config, and you will find that this configuration file contains an ABC reference to the previously created service.

Note: To view the originalArticle, Please refer to all the indexes here.

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.