次の方法で共有


WsdlExporter.GetGeneratedMetadata is called once and only once

If you have to provide a custom WSDL as part of your WCF service, you have to extend the WsdlExporter class and implement the GetGeneratedMetadata method. This method returns a MetadataSet object which encapsulates the WSDL that represents the service. One of the reasons you may take this route is if you want to add some custom metadata to the WSDL. The one thing to remember about this method is that WCF will call it exactly once to get the WSDL when someone first calls the ?WSDL or MEX endpoint of your  service. If you return a valid WSDL from this method, it is cached and used on subsequent calls to the metadata endpoint. On the other hand, if for some reason, you get an exception on that first call, then WCF 'remembers' the exception and will return it on subsequent calls to the metadata endpoint. If you encountered a transient, recoverable error when generating the metadata, you don't get another chance to generate it. the only solution at this time is to restart the app domain.

This behavior is by design as the WSDL is considered a 'static' thing and must always be the same for a service, so there is no retry logic built into WCF to call it more than once in the event of an error.

This is the one point I wanted to get across in the post - as far as possible, avoid doing anything fancy in the GetGeneratedMetadata method and ensure it is always able to return a WSDL, possible read from a local file.