我有一个类,它在WPF和SL中共享相同的代码。
我的问题是现在,我在SL中有一个WCF调用,它为我提供了一个空的对象,但是当我在WPF中运行相同的代码时,它可以工作:
这是我的电话:
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);
}
当我在 Silverlight 中调用"info"变量中的对象时,它在服务器上为 null。当我在 WPF 中调用它时,它可以工作!变量中的值(SessionId)工作,意味着我得到了SL和WPF中的值。
类 OperationModeStateInfoDTO 在 WPF 和 SL 中具有相同的共享代码
。这里:
[DataContract]
public class OperationModeStateInfoDTO
{
[DataMember]
public virtual string Name { get; set; }
[DataMember]
public virtual string State { get; set; }
}
发现了我自己的错误...
我有两个 WCF 接口,一个在服务器上使用,一个在带有 WPF 和 SL 的客户端中使用
服务器端:
[OperationContract(IsOneWay = false)]
SecurityAnswerDTO SwitchOperationModeCp(string sessionId, OperationModeStateInfoDTO myOperationModeStates);
客户端:
[OperationContract(IsOneWay = false, AsyncPattern = true)]
IAsyncResult BeginSwitchOperationModeCp(string sessionId, OperationModeStateInfoDTO myOperationModeState, AsyncCallback callback, object state);
SecurityAnswerDTO EndSwitchOperationModeCp(IAsyncResult res);
问题是界面中参数的名称不同:myOperationModeStates和myOperationModeState!但我不明白的是,即使使用不同的参数,它也可以在 WPF 中工作......
我在这里找到的答案是:http://blog.functionalfun.net/2009/09/if-your-wcf-service-is-unexpectedly.html