我正在編寫一個.NET 3.5應用程序並控制着WCF服務和客戶端。使用svcutil.exe爲幾個WCF服務創建代理類的錯誤/警告
我正在使用svcutil爲我的服務生成代理類,結合了多個服務,因爲它們共享數據類型。
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 '「錯誤。請注意,現在這個類只在其中一個服務中引用,但將來它會從更多的參考中引用。
兩個生成的類的樣子:
[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的,但我不真的不明白那是什麼意思。
的第二個問題是,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.
這些錯誤有兩個非常簡單的服務,甚至發生。例如,如果服務#1
[OperationContract]
public string test(int test)
{
return "test";
}
和服務#2
[OperationContract]
public int Ping(string test)
{
return 23;
}
...我得到的警告。有100個,所有抱怨各種globalElements,globalAttributes或簡單類型如GUID,持續時間,字符等。
如果我改變其中一個服務只有void參數/返回類型,我不得到警告。這真是令人困惑,因爲這是最簡單的測試。根本沒有使用任何自定義類型,svcutil正在bar。。任何想法這裏發生了什麼?
:因爲它看起來像你可能使用DC專門的服務器上,這可能是濫竽充數迫使SvcUtil工具留在DC模式,而不是下降到XmlSerializer的,就像這樣。我不知道這些警告正在傷害我,所以如果他們真的沒有問題,我很樂意忽略他們。 這是我的問題的第一部分重複的類定義,這絕對是現在我殺了我。 – Clyde 2009-11-19 16:53:25
我只是想補充一點,當我對svcutil.exe做同樣的處理時,我得到了ERRORS--它們實際上是警告,在輸出文件生成的意義上(它起作用!),但屏幕上的消息說「錯誤:....!」 Superconfusing! – azheglov 2010-01-27 15:56:07