WCF OperationContract的财产忘记值 [英] WCF OperationContract property forgets value

查看:166
本文介绍了WCF OperationContract的财产忘记值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

最近一直<一个href="http://stackoverflow.com/questions/5468323/wcf-authentication-nt-challenge-response">successful让我的IIS承载WCF服务与基本身份验证工作

由于成功地实施了。我注意到,属性值不会被记录。

Since successfully implementing that. I have noticed that property values are not remembered.

下面是一些code:

[ServiceContract]
public interface IEcho
{
    string Message { [OperationContract]get; [OperationContract]set; }
    [OperationContract]
    string SendEcho();
}

public class EchoProxy : IEcho
{
    public string Message { get; set; }
    public string SendEcho()
    {
        return string.Concat("You said: ", Message);
    }
}
public class EchoService : System.ServiceModel.ClientBase<IEcho>, IEcho
{
    //-- ..... CONSTRUCTORS OMITTED ....

    public string Message
    {
        get { return base.Channel.Message; }
        set { base.Channel.Message = value; }
    }
    public string SendEcho()
    {
        return base.Channel.SendEcho();
    }
}

下面是在控制台和结果:

Here is the console and the result:

EchoService client = new EchoService("SecureEndpoint");
client.ClientCredentials.UserName.UserName = "test";
client.ClientCredentials.UserName.Password = "P@ssword1";
client.Message = "Hello World";
Console.WriteLine(client.SendEcho());

预期成果:你说:你好世界
实际结果:你说:

Expected Result: You said: Hello World
Actual Result: You said:

我已经上传了沙盒项目,我的SkyDrive。我已经包含在API项目SETUP.TXT。

I have Uploaded the sandbox project to my skydrive. I have included a SETUP.txt in the API project.

<一个href="http://lhsnxg.sn2.livefilestore.com/y1p5psRuDMO3MIgasmZXpD9Yq5yIns3l2R5klCUAM5E7xZsToXVIpbHPTxSl14XIfS-kARebyWjpTG7XrjaCgIazQ/WCF_Properties.zip?download&psid=1"相对=nofollow> 点击这里下载。
我怎样才能得到性能的工作?

Click here to download.
How can I get properties to work?

谢谢

推荐答案

我从来没有见过一个属性用于传输数据的WCF的合同。即Message属性。 AFAIK它只是不可能的。

I have never seen WCF contract used with a property to transfer data. i.e. the Message property. AFAIK its just not possible.

我的建议是要保留合同的组成部分分开,即操作和数据的关注。

My recommendation would be to keep the concerns that are part of the contract separate, i.e. Operation and Data.

[ServiceContract]
public interface IEcho
{
    [OperationContract]
    string SendEcho(string Message);
}

[ServiceContract]
public interface IEcho
{
    [OperationContract]
    string SendEcho(Message message);
}

[DataContract]
public class Message
{
    [DataMember]
    public string Message {get; set;}
}

在以后的某个时候,你可能希望改变消息对象。

At some later point you may wish to change the Message Object.

[DataContract]
public class MessageV2 : Message
{
    [DataMember]
    public DateTime Sent {get; set;}
}

尽管这改变了合同,这样的变化,如果能认真管理是向后兼容。

While this changes the contract, changes like this can be backwardly compatible if managed carefully.

这篇关于WCF OperationContract的财产忘记值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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