tags:

views:

1189

answers:

2

I'm writing a .NET 3.5 app and have control over both the WCF service and client.

I'm using svcutil to generate proxy classes for my services, combining several services since they share data types.

svcutil /out:ServiceReference.cs /noconfig /namespace:*,Global.ServiceReference /tcv:Version35 http://localhost:12345/first.svc http://localhost:12345/second.svc

The more serious problem is the error -- I've got a class being created twice, resulting lots of "Ambiguity between 'Global.ServiceReference.MyClass.MyField' and 'Global.ServiceReference.MyClass.MyField' " errors. Note that right now, this class is only referenced in ONE of the services, though in the future it will be referenced from more.

The two generated class look like:

[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.Runtime.Serialization", "3.0.0.0")]
[System.Runtime.Serialization.DataContractAttribute(Name="MyClass", Namespace="http://schemas.datacontract.org/2004/07/MyService.Util")]
public partial class MyClass : object, System.Runtime.Serialization.IExtensibleDataObject
{ 
  //fields
}

and

[System.CodeDom.Compiler.GeneratedCodeAttribute("svcutil", "3.0.4506.2152")]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(Namespace="http://schemas.datacontract.org/2004/07/MyService.Util")]
public partial class MyClass
{
  // same fields
}

Based on the attributes applied to them, this has something to do with the DataContractSerializer vs. the XmlSerializer, but I don't really understand what those mean.

A second problem is that svcutil is giving a boatload of warnings of the form:

Error: There was a validation error on a schema generated during export:
    Source:
    Line: 1 Column: 10415
   Validation Error: The simpleType 'http://schemas.microsoft.com/2003/10/Serialization/:guid' has already been declared.

These errors happen even with two very simple services. For example, if service #1 has

[OperationContract]
public string test(int test)
{
    return "test";
}

and service #2 has

[OperationContract]
public int Ping(string test)
{
    return 23;
}

...I get the warnings. There's like a 100 of them, all complaining about various globalElements, globalAttributes, or simpleTypes like guid, duration, char, etc.

If I change one of the services to have only void parameters/return type, I don't get the warnings. This is really confusing, since this is the simplest possible test. Without using any custom types at all, svcutil is barfing. Any idea what's going on here?

+1  A: 

The warnings are normal when you share types and list multiple services I have been using this method for over a year. Is the utility generating the class at all or is it creating nothing.

rerun
Yep it's creating the classes. I'm not aware that the warnings are hurting me so I'm happy to ignore them if they're really not a problem.It's the duplicate class definition from the first part of my question that's definitely killing me right now.
Clyde
I just want to add that when I do the same with svcutil.exe, I get ERRORS - they are actually warnings, in the sense that the output file is generated (and it works!), but the message on the screen says "Error:....!" Superconfusing!
azheglov
+1  A: 

Something in the XSD files is causing svcutil to invoke the XmlSerializer to generate some of your types. Unfortunately type sharing between DataContract and XmlSerializer is not available, so you end up with duplicated types. Since it looks like you're probably using DC exclusively on the server, it might be enough just to force svcutil to stay in DC mode and not fall over to XmlSerializer, like so:

svcutil /serializer:DataContractSerializer ...
alexdej