wcfsvcutil.exe

svcutil generating MessageContractAttribute or OperationContractAttribute for different services


I'm using svcutil to make proxy classes and I've noticed that for different services I get different results.

I'm using this svcutil command:

svcutil http://server/SomeService.asmx 
    /l:c# 
    /syncOnly 
    /out:C:\ISomeService
    /config:C:\ISomeService.config 
    /namespace:*,SomeServiceProxy

Proxy classes for first service generate code like this:

[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.Runtime.Serialization", "4.0.0.0")]
[System.Runtime.Serialization.DataContractAttribute(Name="GetFirstService", Namespace="http://othernamespace.com")]
public partial class GetFirstServiceRequest : SomeServiceProxy.ResponseInfoBase
{
    ...
}

And proxy classes for second service generate this:

[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "4.0.0.0")]
[System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Advanced)]
[System.ServiceModel.MessageContractAttribute(WrapperName = "GetSecondService", WrapperNamespace = "http://somenamespace.com", IsWrapped = true)]
public partial class GetSecondServiceRequest
{
    ...
}

Why is one class marked with MessageContractAttribute and the other with DataContractAttribute? How does svcutil decide to use one or the other, the command is same for both services?


Solution

  • The DataContract format supports only a subset of XML Schema Definition. So it depends on the service metadata: svcutil (actually System.ServiceModel.Description.WsdlImporter which is used by svcutil) tries to generate DataContracts by default. If it encounters a schema that cannot be represented as a DataContract, it generates a MessageContract as fallback.