Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Errors/Warnings using svcutil.exe to create proxy classes for several WCF services

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?

like image 252
Clyde Avatar asked Nov 17 '09 19:11

Clyde


People also ask

How to generate proxy for WCF service?

The WCF client proxy can be generated manually by using the Service Model Metadata Utility Tool (SvcUtil.exe) for more information see, ServiceModel Metadata Utility Tool (Svcutil.exe). The WCF client proxy can also be generated within Visual Studio using the Add Service Reference feature.

What is required by client to generate client proxy in Web services?

A metadata exchange endpoint is required to support the dynamic generation of proxy and configuration for client applications. You must explicitly enable metadata exchange by adding the endpoint and enabling the metadata exchange behavior.


1 Answers

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 ...
like image 199
alexdej Avatar answered Sep 30 '22 14:09

alexdej