silverlight中调用wcf方法的问题
人家写的方法:YCServiceClient client = new YCServiceClient();
SLUtil.SetServiceAddress(client.Endpoint);
client.GetWariningListCompleted += new EventHandler<GetWariningListCompletedEventArgs>(GetWariningListCompleted);
void GetWariningListCompleted(object sender, GetWariningListCompletedEventArgs e)
{
//Dispatcher.BeginInvoke(() =>
//{
try
{
MapPage.ShowDebug("告警查询服务器耗时:" + (DateTime.Now - _warnLoadBegin).TotalSeconds + "秒");
if (e.Error != null)
{
ShowDebug(e.Error.Message + "\n" + e.Error.StackTrace);
return;
}
_warnList.Clear();
alarmList.WarnList.ItemsSource = e.Result;
//WarnList.ItemsSource = e.Result;
if (e.Result.Count == 0)
{
alarmList.WarnList.Visibility = System.Windows.Visibility.Collapsed;
alarmList.NoWarnInfo.Visibility = System.Windows.Visibility.Visible;
}
else
{
alarmList.WarnList.Visibility = System.Windows.Visibility.Visible;
alarmList.NoWarnInfo.Visibility = System.Windows.Visibility.Collapsed;
}
if (WarnLayer == null)
return;
WarnLayer.ClearStation(STA_WARN);
foreach (WarnInfo info in e.Result)
{
_warnList.Add(info.StId, info);
WarnLayer.AddStation(STA_WARN, info.StId, info.Jd, info.Wd, info);
}
audio.Stop();
if (WarnLayer.Graphics.Count > 0)
{
audio.Play();
}
}
catch (Exception ex)
{
ShowDebug(ex.Message + "\n" + ex.StackTrace);
}
finally
{
CloseLoading();
MapPage.ShowDebug(String.Format("告警加载开始时间:{0:HH:mm:ss}\n耗时:{1}秒", _warnLoadBegin, (DateTime.Now - _warnLoadBegin).TotalSeconds));
}
//});
}
我也在wcf中定义了一个方法,但怎么才能写出类似这样的方法,是先写下面这个方法吗?下面方法参数类型GetWariningListCompletedEventArgs 是在哪儿定义的?
[解决办法]
GetWariningListCompletedEventArgs 应该是在服务端那边定义的,你上面的代码是silverlight(客户端)的代码。
[解决办法]
在解决方案的Web项目中添加“启用的Silverlight的WCF服务”,名称为Serivce1.svc
在Serivce1.svc中写上一个wcf服务后,在客户端项目引用该服务后就自动产生了:
[OperationContract]
public List<T> GetWariningListCompleted()
{
var q= from s in youTable ;
return q.tolist();
}
[OperationContract]
public List<T> GetWariningList()
{
var q= from s in youTable ;
return q.tolist();
}