Maxime Rossini
Maxime Rossini

Reputation: 3879

In a WCF proxy-generated client, what determines the serializer used?

When I expose a WCF service using DataContact/DataMember attributes, each service reference I make in other projects to this service generates classes with DataContract/DataMember attributes (as well as IExtensibleDataObject interface implementation, etc.).

In another project, I have to use a SOAP service whose WSDL has not been generated by WCF, but by some other tool I don't know and can't change the behavior.

My problem is that the code generated by my svcutil proxy is a little bit less flexible:

What happened in the svcutil tool / the wsdl I use, that it has to generate code in this way?

Upvotes: 1

Views: 1960

Answers (1)

VJAI
VJAI

Reputation: 32768

What happened in the svcutil tool / the wsdl I use, that it has to generate code in this way?

The Svcutil.exe tool can be used to create client proxies for both WCF and ASMX services. When Svcutil.exe is used create a proxy from an ASMX service, the data types that are generated in the code usually use XML serialization.

http://msdn.microsoft.com/en-us/library/cc304837.aspx

UPDATE:

My best guess is it is the schema specified in the WSDL determines which serialization has to be used by the the svcutil.exe.

The namespace of data contract serialization schema is http://schemas.microsoft.com/2003/10/Serialization and you can get much details about that here.

So if the svcutil sees this schema specified in the wsdl then it go for data-contract serializer else the xml serializer.

I also checked with WSDLs of WCF and ASMX. The WSDL of WCF service contains the following XSD sections and they are missing in the ASMX's one.

<xsd:schema targetNamespace="http://tempuri.org/Imports">

   <xsd:import schemaLocation="http://localhost:53328/Service1.svc?xsd=xsd0"
     namespace="http://tempuri.org/"/>

   <xsd:import schemaLocation="http://localhost:53328/Service1.svc?xsd=xsd1" 
     namespace="http://schemas.microsoft.com/2003/10/Serialization/"/>

   <xsd:import schemaLocation="http://localhost:53328/Service1.svc?xsd=xsd2" 
      namespace="http://schemas.datacontract.org/2004/07/WcfService1"/>
</xsd:schema>

Upvotes: 1

Related Questions