WCF OperationContract function forgets value

have recently been successful in that my WCF service center for IIS worked with basic authentication .

Since then, we have been successfully implementing it. I noticed that property values โ€‹โ€‹are not remembered.

Here is the 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:

I uploaded the sandbox project to my skydrive. I included the SETUP.txt file in the API project.

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

Thank you

+2
source share
2 answers

I have never seen a WCF contract used to transfer data. those. property Message. AFAIK its just not possible.

, , , .. .

[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;}
}

- .

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

, .

+3

, , , . MSDN , Instancing Concurrency.

, InstanceContextMode.PerCall , .

InstanceContextMode.Single , . , , , .

, . (, ), InstanceContextMode.PerSession () , .

@JTew, , , , - (, ). :

[ServiceContract]
public interface IEcho
{
    [OperationContract]
    void SetMessage(string message);

    [OperationContract]
    string GetMessage();

    ... etc ...
}
+1

All Articles