简体   繁体   English

使用svcutil.exe为多个WCF服务创建代理类的错误/警告

[英]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. 我正在编写.NET 3.5应用程序并控制WCF服务和客户端。

I'm using svcutil to generate proxy classes for my services, combining several services since they share data types. 我正在使用svcutil为我的服务生成代理类,因为它们共享数据类型,所以组合了多个服务。

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. 更严重的问题是错误 - 我有一个类被创建两次,导致很多“Global.ServiceReference.MyClass.MyField'和'Global.ServiceReference.MyClass.MyField''错误之间的歧义。 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. 基于应用于它们的属性,这与DataContractSerializer与XmlSerializer有关,但我真的不明白这些是什么意思。

A second problem is that svcutil is giving a boatload of warnings of the form: 第二个问题是svcutil提供了大量警告:

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 例如,如果服务#1有

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

and service #2 has 服务#2有

[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. 其中有100个,都抱怨各种globalElements,globalAttributes,或简单类型,如guid,duration,char等。

If I change one of the services to have only void parameters/return type, I don't get the warnings. 如果我改变其中一个服务只有void参数/返回类型,我不会收到警告。 This is really confusing, since this is the simplest possible test. 这真是令人困惑,因为这是最简单的测试。 Without using any custom types at all, svcutil is barfing. 根本不使用任何自定义类型,svcutil正在禁止使用。 Any idea what's going on here? 知道这里发生了什么吗?

Something in the XSD files is causing svcutil to invoke the XmlSerializer to generate some of your types. XSD文件中的某些内容导致svcutil调用XmlSerializer来生成一些类型。 Unfortunately type sharing between DataContract and XmlSerializer is not available, so you end up with duplicated types. 不幸的是,DataContract和XmlSerializer之间的类型共享不可用,因此您最终会得到重复的类型。 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: 因为看起来你可能只在服务器上使用DC,所以仅仅强制svcutil保持在DC模式并且不会落到XmlSerializer上就足够了,就像这样:

svcutil /serializer:DataContractSerializer ...

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. 实用程序是否完全生成类或者它什么都不创建。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM