使用svcutil.exe的创建代理类数WCF服务的错误/警告 [英] Errors/Warnings using svcutil.exe to create proxy classes for several WCF services

查看:182
本文介绍了使用svcutil.exe的创建代理类数WCF服务的错误/警告的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在写一个.NET 3.5应用程序,并有超过两个的WCF服务和客户端的控制。

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

我使用SvcUtil工具生成代理类为我服务,结合几个服务,因为它们共享的数据类型。

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

更严重的问题是错误 - 我有一个类被创建两次,而导致大量的错误'Global.ServiceReference.MyClass.MyField'和'Global.ServiceReference.MyClass.MyField'之间的模糊性的。需要注意的是,现在,这个类是只在一个服务引用,但在未来它会从更多的引用。

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
}

[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
}

根据适用于他们的属性

,这已经是与DataContractSerializer的与XmlSerializer的,但我真的不明白这些的意思。

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.

第二个问题是,SvcUtil工具是给形式警告勿庸置疑:

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.

这些错误,甚至有两个非常简单的服务发生。例如,如果服务#1具有

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

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

和服务#2

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

......我得到的警告。还有像100人,所有的抱怨各种globalElements,globalAttributes,或simpleTypes像GUID,持续时间,焦炭等。

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

如果我改变服务之一,只有空参数/返回值类型,我没有得到警告。这的确是令人困惑的,因为这是最简单的可能的测试。如果不使用任何自定义类型可言,SvcUtil工具是barfing。任何想法是怎么回事?

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?

推荐答案

东西的XSD文件导致SvcUtil工具调用XmlSerializer的生成一些你的类型。 DataContract和XmlSerializer的之间不幸的是共享式不可用,那么你最终重复类型。因为它看起来像你可能使用DC服务器完全,则可能是滥竽充数,迫使SvcUtil工具留在DC模式,而不是翻倒到XmlSerializer的,就像这样:

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 ...

这篇关于使用svcutil.exe的创建代理类数WCF服务的错误/警告的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆