Search code examples
c#wcfknown-types

WCF KnownTypes reference generation


I have a WCF service that has one BaseForm that is inherited numerous time (100+), some (10+) have multi-layered inheritance too. All of the derived forms are listed as KnownTypes.

The problem I am having is the time it takes for the service to start up and to generate a client reference. Using the WCF Test Client as a test it takes about 10 minutes for it to complete. If I don't reference the KnowTypes (or just list a couple) it takes about 1.5 mins to fully complete.

Is there anyway to see what is going on, why it is taking so long? Or is there a better way than the standard?

Cheers


Solution

  • How big is the WSDL generated for your service? Depending on how large those known types are, you are potentially including a huge amount of data in the 'service reference' or proxy.

    Every object that you include as a KnownType will be added to the WSDL or service metadata. This will include, at a minimum,

    • the fully qualified name of the object (including namespace and xml namespace)
    • list of all properties on the object
    • description of all types of all properties, i.e. non simple types can have large descriptions.

    When you connect to the service to request metadata, as the WCF test client does when you provide a service URL, it will need to

    1. Ask the service to generate this metadata document, and the service will investigate all the objects and their properties
    2. Send this content over the wire - not a big deal but not free
    3. Deserialize into a proxy; in the WCF test client this means generating the fields on the form that relate to each property type for each object.

    What can you do about this? You probably don't need to do anything. This is a one time operation - once your service client knows the types that will can be sent and received it stores them (as generated code) and reuses them.