0
votes

I am learning about WCF deployment in IIS and I have found something strange. Basically my service only uses the default behavior regardless of how I set the behaviorConfiguration attribute of element in web.config.

So here's the relevant piece of my web.config:

<system.serviceModel>
<services>
  <service name="TableImport" behaviorConfiguration="MyServiceTypeBehaviors">
    <endpoint address="" binding="wsHttpBinding" />
  </service>
</services>

<behaviors>
  <serviceBehaviors>
    <behavior>
      <serviceMetadata httpGetEnabled="false" />
    </behavior>
    <behavior name="MyServiceTypeBehaviors" >
      <serviceMetadata httpGetEnabled="true" policyVersion="Policy15" />
    </behavior>
  </serviceBehaviors>
</behaviors>
</system.serviceModel>

As you can see the default serviceMetadata element has httpGetEnabled="false" whereas the MyServiceTypeBehaviors serviceMetadata element has httpGetEnabled="true". You can also see that my service's behaviorConfiguration attribute is set to "MyServiceTypeBehaviors".

The result should be that my service publishes metadata however through a browser and through Visual Studio "Add Service Reference" feature I get the same result: no metadata.

On the other hand if I enable metadata in the default behavior and disable it in "MyServiceTypeBehaviors" and continue to have my service use MyServiceTypeBehaviors then I get metadata both through the browser and through VS.

To me, these tests indicate that my service uses default behavior regardless of how I set up my config file... but at the same time I can change the default behavior through web.config so my web.config is in fact able to affect how the service works. Any ideas?

2
What happens if you remove default behavior? Does your specific behavior works roght?evgenyl
If I remove the default behavior and only have the MyServiceTypeBehaviors and the MyServiceTypeBehaviors enables metadata the result is no metadata. So my assessment is that removing the default behavior does not make my specific behavior work right.user800576
I'd try to remove default behsvior and policy version.evgenyl

2 Answers

0
votes

You don't specify a contract in your endpoint, so without the contract the endpoint is notgoing to know what service it's using.

If you're using .NET 4.0 or later (and based on the issues you described it sounds like you are), you're actually connecting to a default endpoint that is based on the address of the service. The default endpoint is provided by the framework.

As such, it will use the default service behavior. This matches your problem description:

-  When the default behavior's httpGetEnabled is set to false, you get no metadata.
-  When the default behavior's httpGetEnabled is set to true, you get the metadata.

The easiest solution in this situation is to simply add the contract to the endpoint you are trying to define:

<endpoint address="" binding="wsHttpBinding" contract="FullyQualified.IContractName" />
-1
votes

You need to add the "metadata" or "MEX" endpoint. Alter your services section of your config to look like:

     <services>
     <service name="TableImport" behaviorConfiguration="MyServiceTypeBehaviors">
        <endpoint address="" binding="wsHttpBinding" />
        <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
     </service>
   </services>