WCF service web.config tweaks to change the generated wdl

1.1k views Asked by At

My wcf service follows following structure of load balancing:

public (https) -> F5 LB (http) -> node1/node2.

i am exposing services on http scheme and F5 LB takes care of ssl offloading. since my service is exposed as http, the generated wsdl through F5 LB contains http based url as follows:

my LB service URL:

https://myservice.mydomain.com/service1.svc

and the generated service page is :

MyService Service

You have created a service.

To test this service, you will need to create a client and use it to call the service. You can do this using the svcutil.exe tool from the command line with the following syntax:    

svcutil.exe http://myservice.mydomain.com/service1.svc?wsdl

You can also access the service description as a single file:

http://myservice.mydomain.com/service1.svc?singleWsdl

as you notice the generated page has http url exposed from app nodes. since F5 LB exposes service as https, its not allowing the above http url and the request from client is bouncing.

now, can we tweak my service web.config to expose the service on http scheme but have wsdl points to https url so that the url from generated above wsdl from F5 LB too https and client will work on https and request from LB will come to service on http that my service handle?

2

There are 2 answers

0
Seymour On BEST ANSWER

Without fully understanding your configuration/environment, I’ll suggest a few options that may help you resolve the issue:

  • Provide both http and https base addresses in your service configuration and enable metadata via https only ''
  • Implement a separate mex endpoint (rather than using the serviceMetadata), which allows more control of the metadata endpoint (i.e. different address and/or listenUri)
  • Use the System.ServiceModel.Description.IWsdlExportExtension to control the rendered service metadata

References:
What was the difference between WSDL & Mex Endpoint in WCF
http://blogs.msdn.com/b/saurabs/archive/2012/04/27/http-get-v-s-mex-end-point.aspx
http://msdn.microsoft.com/en-us/library/aa717040.aspx

0
Michael Edenfield On

I have never done this, but like most things in WCF, there are extension points you can hook into to override its default behavior.

It sounds like what you need to do is implement a custom "metadata" endpoint. There's a series of article on MSDN on Exporting Custom Metadata. Specifically, there is an IWsdlExportExtension you can implement that gives you access to the WSDL data before it's sent to the client.

It seems like this works the same as most other behavior extensions, which means you would do something like this (again, I've never done it, but this should get you started; also see this blog entry for more details behind the behavior extension mechanism):

  • Implement an extension that implements IWsdlExportExtension and IEndpointBehavior.
  • Implement a behavior extension element that can go into the config file
  • Register that endpoint behavior extension by adding it to the system.serviceModel / extensions / behaviorExtensions element in your config file
  • Add your new extension to your endpoint's behavior.

e.g.:

public class LbWsdl : IWsdlExportExtension, IEndpointBehavior
{
    public void ExportContract(WsdlExporter exporter, WsdlContractConversionContext context)
    {
        // Fix WSDL here
    }
}

public class LbWsdlExtension : BehaviorExtensionElement
{
    public override Type BehaviorType
    {
        get { return typeof(LbWsdl); }
    }
}

<system.serviceModel>
  <extensions>
    <behaviorExtensions>
      <add name="lbWsdl" type="LbWsdlExtensions.LbWsdlExtension,LbWsdlExtension />
    </behaviorExtensions>
  </extensions>
  <behaviors>
    <endpointBehaviors>
      <behavior name="LoadBalancedBehavior">
        <webHttp/>
        <lbWsdl />
      </behavior>
    </endpointBehaviors>
  </behaviors>
</system.serviceModel>