此致
我正在尝试从我正在创建的Windows手机应用程序库中调用web服务,但是我有一个奇怪的问题,我希望你能帮助我。
首先,我在我的应用程序主页上有以下代码:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Phone.Controls;
using Library;
using System.Threading;
namespace Host
{
public partial class MainPage : PhoneApplicationPage
{
public MainPage()
{
InitializeComponent();
Class1.AsyncCall test = new AsyncCall();
test.Call("0002145", 51);
private void PhoneApplicationPage_Loaded(object sender, RoutedEventArgs e)
{
}
}
}
我的AsyncCall
课程在我的库中,它包含以下代码:
using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Collections.Generic;
using System.Threading;
using Library;
using Library.WebserviceRemote;
namespace Library
{
public class AsyncCallWS
{
WebserviceCall com = new WebserviceCall();
com.methodOne("methodOne", "1221", 122);
}
}
我的WebserviceCall
是库中的另一个类,调用的方法如下所示:
using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
//using System.ServiceModel;
using Library.WebserviceRemote;
using System.Collections.Generic;
using System.Diagnostics;
using System.Threading;
namespace Library
{
//[DebuggerNonUserCode]
public class WebserviceCall
{
public void methodOne(String Method, String param1, int param2)
{
WebserviceRemote client = new WebserviceRemote ();
System.Diagnostics.Debug.WriteLine("I am in methodOne " + param1 + param2);
client.methodOneOnServiceCompleted += new EventHandler<methodOneOnServiceCompletedEventArgs>(client_methodOneOnServiceCompleted);
client.methodOneOnServiceAsync("1221", 122);
System.Diagnostics.Debug.WriteLine("After call to webservice ");
}
private void client_methodOneOnServiceCompleted(object sender, methodOneOnServiceCompletedEventArgs e)
{
System.Diagnostics.Debug.WriteLine("This is the response " + e.Result);
}
}
}
问题是永远不会读取方法client_methodOneOnServiceCompleted
,应用程序永远不会进入它,所以我无法从webservice获得响应。我认为它有一些归因于EventHandler
,因为这都是在库中完成的而不是应用程序页面。
但是,我不知道为什么它没有进入该方法。此外,没有错误,输出中的所有内容都存在,除了:
System.Diagnostics.Debug.WriteLine("This is the response " + e.Result);
另一个注意事项:当从应用程序本身调用时,此代码就像一个魅力,但我真的需要从库中调用webservice,所以请帮助:)
PS:这都是在模拟器7.0中测试的
谢谢。