我被打壓了,我試圖更新現有服務引用WCF服務(共享類型),我不能。我嘗試了我在Google上找到的所有內容(social.msdn,stackoverflow,...),但我還沒有找到解決我的問題的方法。WCF更新服務參考錯誤
我已經有一個的ServiceContract和我一樣添加下面的代碼創建一個新操作:
[ServiceContract]
public partial interface IServiceDTO : IGenericServiceDTO<EntityDTO>
{
// Some OperationContracts working like
[OperationContract]
EntityDTO[] Method(int field);
// NewMethod
[OperationContract]
OtherEntityDTO[] NewMethod(int field);
}
[DataContract]
public class EntityDTO {
// Some properties working
}
[DataContract]
public class OtherEntityDTO {
// Some properties working
[DataMember]
YetAnotherEntity NewProperty {get;set;}
}
當我嘗試更新它拋出我的follwing錯誤的服務參考:
Attempting to download metadata from 'http://localhost:65499/Services/Acciones/ProcesoServiceDTO.svc' using WS-Metadata Exchange or DISCO. Error: Cannot import wsdl:portType Detail: An exception was thrown while running a WSDL import extension: System.ServiceModel.Description.DataContractSerializerMessageContractImporter Error: Referenced type 'mpm.seg.ServiceModel.DTO.DataContracts.Acciones.ProcesoDTO, mpm.seg.ServiceModel.DTO.DataContracts, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' with data contract name 'ProcesoDTO' in namespace 'http://schemas.datacontract.org/2004/07/mpm.seg.ServiceModel.DTO.DataContracts.Acciones' cannot be used since it does not match imported DataContract. Need to exclude this type from referenced types.XPath to Error Source: //wsdl:definitions[@targetNamespace='http://tempuri.org/']/wsdl:portType[@name='IProcesoServiceDTO']
首先,我不明白句子「...由於與導入的DataContract不匹配而無法使用」。 svcutil如何試圖將引用類型與導入的DataContract匹配?我引用了在客戶端項目中引用類型的項目,原因是服務器和客戶端處於相同的解決方案中,但我試圖將它們分開並引用完全相同的dll。
此外,當我嘗試,例如,以下情況它的工作原理(寫「NewProperty」的「OtherEntityDTO到EntityDTO」的),我不明白的區別:
[ServiceContract]
public partial interface IServiceDTO : IGenericServiceDTO<EntityDTO>
{
// Some OperationContracts working like
[OperationContract]
EntityDTO[] Method(int field);
// NewMethod
[OperationContract]
OtherEntityDTO[] NewMethod(int field);
}
[DataContract]
public class EntityDTO {
// Some properties working
[DataMember]
YetAnotherEntity NewProperty {get;set;}
}
[DataContract]
public class OtherEntityDTO {
// Some properties working
}
請,提前幫助我並多謝。
是的,你的問題是不同的,如果你想使用一個屬性作爲DataMember,它必須被獲取和設置爲了通過WCF序列化/反序列化。看看這個:[StackOverflow thread](http://stackoverflow.com/questions/1873741/wcf-exposing-readonly-datamember-properties-without-set) – Marc