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.