Search code examples
c#wpfwcfsilverlight

WCF Call from Silverlight delivers a "null" Object, in WPF it works


I have a class which shares the same Code in WPF and SL.

My problem is now, I have a WCF call in SL, which delivers me an empty Object, but when I run the same Code in WPF it works:

This is my call:

  private async void Selector_OnSelectionChanged(object sender, SelectionChangedEventArgs e)
    {
        var channel = CommonClient.Instance.MainCommonService.Channel;

        var info = new OperationModeStateInfoDTO() { Name = this.OperationMode.Name, State = this.OperationMode.CurrentState };
        var ret = await Task.Factory.FromAsync((a, b) => channel.BeginSwitchOperationModeCp(CommonClient.Instance.SessionId, info, a, b), (r) => channel.EndSwitchOperationModeCp(r), TaskCreationOptions.None);
        SecurityClient.CheckSecurityAnswerAndReportError(ret);
    }

the object in the "info" Variable is null at the server when I call it in Silverlight. When I call it in WPF it works! The Value from the Variable before (SessionId) works, means I got the Value in SL and WPF.

And also the class OperationModeStateInfoDTO has the same shared Code in WPF & SL

here:

 [DataContract]
 public class OperationModeStateInfoDTO
 {
    [DataMember]
    public virtual string Name { get; set; }

    [DataMember]
    public virtual string State { get; set; }
 }

Solution

  • Found my own error...

    I have two WCF Interfaces, one I use on the Server an one in Client with WPF and SL

    Server Side:

        [OperationContract(IsOneWay = false)]
        SecurityAnswerDTO SwitchOperationModeCp(string sessionId, OperationModeStateInfoDTO myOperationModeStates);
    

    Client Side:

        [OperationContract(IsOneWay = false, AsyncPattern = true)]
        IAsyncResult BeginSwitchOperationModeCp(string sessionId, OperationModeStateInfoDTO myOperationModeState, AsyncCallback callback, object state);
        SecurityAnswerDTO EndSwitchOperationModeCp(IAsyncResult res);         
    

    the Problem was the different Name of the Parameter in the Interface: myOperationModeStates and myOperationModeState! But what I don't understand was, that it works in WPF even with the different Parameters...

    The answer I found here: http://blog.functionalfun.net/2009/09/if-your-wcf-service-is-unexpectedly.html