我已在WCF
中创建了功能,并在WCFTestClient.exe
中对其进行了测试。但是在实际客户端(移动)上进行测试时。它不显示功能,仅显示以下内容。
示例函数名称为Plus();
,它将显示PlusAsync();
,其中void为返回值。还有一个事件处理程序(我记得它是PlusEventHandler
的东西)。
请告诉我。
答案 0 :(得分:2)
您正在进行PlusAsync
操作,因为WCF服务在您的客户端中添加为异步您还可以查看下面的图像,其中显示了如何异步添加wcf服务
但这可能是Mobile应用程序异步的默认行为,并在该调用中放置回调函数以获取重新调整值并显示它
调用WCF异步服务的示例
private void MakeAsynchronousCall(int NumberOfStudents)
{
BasicHttpBinding basicHttpBinding = new BasicHttpBinding();
StudentService.StudentServiceClient c =
new WFCCallExample.StudentService.StudentServiceClient();
EndpointAddress endpointAddress = c.Endpoint.Address;
StudentService.IStudentService iStudentService =
new ChannelFactory<StudentService.IStudentService>
(basicHttpBinding, endpointAddress).CreateChannel();
AsyncCallback aSyncCallBack =
delegate(IAsyncResult result)
{
try
{
List<StudentService.Student> Students =
iStudentService.EndGetStudents(result);
this.Dispatcher.BeginInvoke((Action)delegate
{ DGStudent.ItemsSource = Students; });
}
catch (Exception ex)
{
this.Dispatcher.BeginInvoke((Action)delegate
{ MessageBox.Show(ex.Message); });
}
};
try
{
iStudentService.BeginGetStudents(NumberOfStudents,
aSyncCallBack, iStudentService);
} catch (Exception ex) { MessageBox.Show(ex.Message); }
}
答案 1 :(得分:0)
正如How to: Call WCF Service Operations Asynchronously所述,首先创建一个处理结果的回调方法:
// Asynchronous callbacks for displaying results.
static void AddCallback(object sender, AddCompletedEventArgs e)
{
Console.WriteLine("Add Result: {0}", e.Result);
}
然后您订阅已完成的事件并发出呼叫:
client.AddCompleted += new EventHandler<AddCompletedEventArgs>(AddCallback);
client.AddAsync(value1, value2);
一旦WCF调用返回,您的AddCallback
将被调用。