简体   繁体   English

服务未实现Property的get / set方法

[英]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.

相关问题 在属性的Set {}方法中获取属性名称 - Get property name in the property's Set{} method VS Designer总是抛出异常“x属性没有get / set方法” - VS Designer always throws the Exception “The x Property doesn't have a get/set method” C#Property get set没有设置值 - C# Property get set doesn't set a value API GET 方法不在 Xamarin Forms 的属性中存储数据 - API GET method doesn't store data in the property in Xamarin Forms 如何在依赖属性中获取/设置什么都不做? - Howcome the get/set in dependency property doesn't do anything? 使用 Attributes 向属性的 set/get 方法添加装饰代码 - Use Attributes to add decoration code to property's set/get method 使用 get 之间是否有任何边缘情况差异? 放; singleton 服务的属性或 GetValue、SetValue 方法? - Is there any edge case difference between using a get; set; property or a GetValue, SetValue method for a singleton service? 在WPF中,OnRender方法不会显示厚度设置为依赖项属性的Rectangle - OnRender method doesn't display a Rectangle with the thickness set to a dependency property in WPF 为什么WCF服务方法的参数未设置为正确的值 - Why doesn't the WCF service method have its parameter set to the correct value 对象不支持属性或方法“ lazyload” - Object doesn't support property or method 'lazyload'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM