Here's an example of configuring a web.config file to show the meta data for an ASP.NET 3.5 AJAX WCF service.
In this case, you first add the service using Add New Item -> AJAX-Enabled WCF Service -> (Name WeatherService.svc) -> Add.
Next, configure the web.config's <system.serviceModel> section to look like this:
<system.serviceModel>
<services>
<service name="WeatherService"
behaviorConfiguration="WeatherServiceAspNetAjaxBehavior">
<endpoint address=""
binding="webHttpBinding" contract="WeatherService" />
<endpoint contract="IMetadataExchange"
binding="mexHttpBinding" address="mex" />
</service>
</services>
<behaviors>
<endpointBehaviors>
<behavior name="WeatherServiceAspNetAjaxBehavior">
<enableWebScript />
</behavior>
</endpointBehaviors>
<serviceBehaviors>
<behavior name="WeatherServiceAspNetAjaxBehavior" >
<serviceMetadata httpGetEnabled="true" />
</behavior>
</serviceBehaviors>
</behaviors>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" />
</system.serviceModel>
使得:
endpointBehaviors &serviceBehaviors 共用一个名字。
或者如下:
<behaviors>
<endpointBehaviors>
<behavior name="AjaxBehavior">
<enableWebScript />
</behavior>
</endpointBehaviors>
<serviceBehaviors>
<behavior name="AjaxServiceBehavior">
<serviceMetadata httpGetEnabled="true" />
</behavior>
</serviceBehaviors>
</behaviors>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" />
<services>
<service behaviorConfiguration="AjaxServiceBehavior" name="ShoppingCartService">
<endpoint address="" behaviorConfiguration="AjaxBehavior"
binding="webHttpBinding" bindingConfiguration="AjaxBinding"
contract="ShoppingCartService" />
<endpoint address="" behaviorConfiguration="AjaxBehavior" binding="webHttpBinding" bindingConfiguration="AjaxSecureBinding" contract="ShoppingCartService" />
</service>
</services>