BloggingAbout.NET
Thoughts of developers
Creating shared types with SvcUtil against multiple sources

One of the teams I am working with ran into an issue when generating shared types via SvcUtil.  The issue was SvcUtil was generating multiple types (e.g., classes, enums) in the proxy .cs file.  After a google search, I found this was being experienced by others:

http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=745657&SiteID=1

http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=1392697&SiteID=1

 

An example of the duplicate types:

[System.CodeDom.Compiler.

GeneratedCodeAttribute("svcutil", "3.0.3906.22")]

[System.

SerializableAttribute()]

[System.Xml.Serialization.

XmlTypeAttribute(Namespace="http://schemas.datacontract.org/2004/07/LR.Model.Enums")]

 

public enum ReturnStatusEnum

{

 

 

/// <remarks/>

None,

 

 

/// <remarks/>

BadLogonOrPassword,

 

 

/// <remarks/>

Successful,

 

 

}

 

 

[System.CodeDom.Compiler.

GeneratedCodeAttribute("System.Runtime.Serialization", "3.0.0.0")]

[System.Runtime.Serialization.

DataContractAttribute(Namespace="http://schemas.datacontract.org/2004/07/LR.Model.Enums")]

 

public enum ReturnStatusEnum : int

{

 

[System.Runtime.Serialization.

EnumMemberAttribute()]

None = -1,

 

[System.Runtime.Serialization.

EnumMemberAttribute()]

BadLogonOrPassword = 0,

 

[System.Runtime.Serialization.

EnumMemberAttribute()]

Successful = 1,

 

}

The solution is simply including a switch to SvcUtil to force the serializer to be a specific type.  The default is Auto so in the example above, the SvcUtil decided to use the XmlSerializer for one class and the DataContractSerializer for another.

An example of the syntax: svcutil /ns:*,my.namespace /serializer:XmlSerializer service1.svc  service2.svc service3.asmx

Hope this saves someone some time!

 

 


Posted Fri, Aug 1 2008 6:07 AM by chilberto
Filed under: ,

Comments

Philippe wrote re: Creating shared types with SvcUtil against multiple sources
on Fri, Aug 1 2008 11:23 AM

I have the same problem, but for a different reason. I wrote WSDL files manually (interoperability between .NET and J2EE), then generated proxy for WCF.

In the WSDL file, there is a type that is used in the header of on of the operations, and that is also used in a fault operation (in the body then). Apparently, svcutil re-generates that type differently, leading to the same issue.

When I use the /ser:XmlSerializer switch, I end up with generated sources that can not be compiled due to an error in the [System.ServiceModel.FaultContractAttribute(typeof(...))] annotation of the operation. This is weird.

Philippe wrote re: Creating shared types with SvcUtil against multiple sources
on Fri, Aug 1 2008 12:25 PM

I acctualy found someone who has the same problem:

forums.microsoft.com/.../ShowPost.aspx

But this is so old, I don't think I will find any answer.

Add a Comment

(required)  
(optional)
(required)  
Remember Me?

Please add 8 and 1 and type the answer here:
Copyright © 2003-2010 BloggingAbout.NET