[英]Service doesn't implement Property's get/set method
I'm having trouble with the Service Reference Manager in my Silverlight application substituting the get and set methods of a property with a generic one. 我在Silverlight应用程序中使用Service Reference Manager遇到麻烦,用通用属性代替了属性的get和set方法。
My example: I have a Rule class in my Service that has three public properties that all use the same private member. 我的示例:我的Service中有一个Rule类,该类具有三个都使用同一私有成员的公共属性。
[DataContract]
public class RulesReadable
{
[DataMember]
private bool? m_passed;
...
[DataMember]
public bool? State
{
get { return m_passed; }
set { m_passed = value; }
}
[DataMember]
public bool HasPassed
{
get { return (m_passed == true) ? true : false; }
set { m_passed = value; }
}
[DataMember]
public bool HasFailed
{
get { return (m_passed == false) ? true : false; }
set { m_passed = !value; }
}
}
When I call the service, get this data type back, and try to get/set the properties I find that each property has been given its own variable instead of sharing one between the three. 当我调用服务时,请恢复该数据类型,并尝试获取/设置属性,我发现每个属性都被赋予了自己的变量,而不是在三个属性之间共享。 If I go to the definition of the class on the Silverlight side I see that this is in fact what has happened:
如果我在Silverlight方面查看类的定义,我会看到实际上是发生了什么:
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.Runtime.Serialization", "4.0.0.0")]
[System.Runtime.Serialization.DataContractAttribute(Name="Manager.RulesReadable", Namespace="http://schemas.datacontract.org/2004/07/MyWebApp.Services")]
public partial class ManagerRulesReadable : object, System.ComponentModel.INotifyPropertyChanged {
private bool HasFailedField;
...
[System.Runtime.Serialization.DataMemberAttribute()]
public bool HasFailed {
get {
return this.HasFailedField;
}
set {
if ((this.HasFailedField.Equals(value) != true)) {
this.HasFailedField = value;
this.RaisePropertyChanged("HasFailed");
}
}
}
...
}
How do I get the class on the Silverlight side to behave like the class on the Service side? 如何使Silverlight侧的类的行为类似于Service侧的类?
First add the assemblies that these classes are in as references to your Silverlight project. 首先,添加这些类所在的程序集,作为对Silverlight项目的引用。 When creating your service reference select the "Reuse types in referenced assemblies" checkbox and either reuse all referenced assemblies or pick and choose specific assemblies to reuse.
创建服务引用时,请选中“在引用的程序集中重用类型”复选框,然后重用所有引用的程序集或选择要重用的特定程序集。 The assemblies that are referenced by the service directly (and any dependencies) will then be a part of the Silverlight application as well.
服务直接引用的程序集(以及任何依赖项)也将成为Silverlight应用程序的一部分。
Don't use Service References. 不要使用服务引用。 They are evil.
他们是邪恶的。 If you google "Silverlight WCF without Service Reference" you will find several good tutorials.
如果您在Google中搜索“没有服务参考的Silverlight WCF”,则会发现一些不错的教程。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.