Question

I have a .NET server side project that contains multiple services. Each of the services deals with each own set of methods, but the methods share the same types:

  • Customer.svc contains methods such as GetCustomer, that returns data about the customer (including customer's address)
  • Order.svc contains methods such as Getorder that returns data about the order (including shipping address)

When I visit Customer.svc?WSDL and Order.svc?WSDL each of them references its own XSD file and the Address type is defined in both of them.

So if the external client references both endpoints, he will get two different XSD files that contains the same type.

Question: How can I force WCF to share types/XSDs between WSDLs (on the server side!). Please not that I am not asking how to share types on the client (this can be achieved with svcutil /reference switch).

Was it helpful?

Solution

The only way to control this implies handcrafting your "metadata" (WSDL + XSD), and then exposing it through a custom configuration. You have to make sure you externalize the common XSD(s), and then you reference them correctly (based on where you plan to publish them relative to the location of the WSDLs) from within the Customer and Order wsdl files.

Have a look serviceMetadata documentation, particularly the externalMetadataLocation attribute. Below is an example which shows you the gist of it (you may try with and without absolute URLs for externalMedatadataLocation attribute, and see how it works for you):

<serviceBehaviors>
    <behavior name="CustomMetadata">
        <serviceMetadata httpGetEnabled="true" externalMetadataLocation="https://.../mywsdl.wsdl"/>
        <serviceDebug includeExceptionDetailInFaults="false"/>
    </behavior>
</serviceBehaviors>

Depending on your particular deployment (self hosted, IIS, Windows Service, etc.), you may run into all sorts of problems that you should be able to address through other behaviours. Search for "custom wsdl WCF" or "externalMetadataLocation example external XSD" for a survey of other problems people ran into, and sift through them as they may apply to your specific scenario.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top