Windows phone 7 如何在WindowsPhone7中调用webservice方法?
为了连接到webservices,我编写了以下代码Windows phone 7 如何在WindowsPhone7中调用webservice方法?,windows-phone-7,Windows Phone 7,为了连接到webservices,我编写了以下代码 WebClient wc = new WebClient(); wc.DownloadStringAsync(new Uri("http://www.Webservices.asmx")); wc.DownloadStringCompleted += new DownloadStringCompletedEventHandler(wc_DownloadStringCompleted); void wc_DownloadStringComple
WebClient wc = new WebClient();
wc.DownloadStringAsync(new Uri("http://www.Webservices.asmx"));
wc.DownloadStringCompleted += new DownloadStringCompletedEventHandler(wc_DownloadStringCompleted);
void wc_DownloadStringCompleted(object sender,DownloadStringCompletedEventArgs e)
{
Debug.WriteLine("Web service says: " + e.Result);
using (var reader = new StringReader(e.Result))
{
String str = reader.ReadToEnd();
}
}
通过使用上面的代码得到字符串结果。但是我想在HTMLVisulaizer中得到结果,然后我知道有哪些方法拥有该Web服务。然后我可以轻松访问特定的方法。
请告诉我如何在Windows phone 7中调用web服务方法?在webservice中,我有5个webmethods。如何获取该方法以及如何调用特定的WebMethod
请提前告诉我谢谢。@venkateswara您是说获取已知WebReference方法的列表,以便知道在代码中调用哪个方法?当您将WebReference添加到WP7项目中时,您没有看到这种已知的方法调用吗?由于您将在VS中开发WP7应用程序,我看不出您希望这样做的原因。即使您自己并不拥有webservice,您也需要从VS连接到它,以便将引用添加到您的项目中 下面是VS2010中添加WebReference的屏幕。操作列在右侧 添加后,您可以使用ObjectBrowser了解应如何调用这些方法 如果我从你的问题中漏掉了什么,请告诉我。@Jason James 第一步: 您必须添加引用服务,就像Jason James有非常详细的说明一样 步骤2: 您可以在应用程序中打开App.xaml.cs
public Apps()
{
// Global handler for uncaught exceptions.
UnhandledException += Application_UnhandledException;
// Show graphics profiling information while debugging.
if (System.Diagnostics.Debugger.IsAttached)
{
// Display the current frame rate counters.
Application.Current.Host.Settings.EnableFrameRateCounter = true;
// Show the areas of the app that are being redrawn in each frame.
//Application.Current.Host.Settings.EnableRedrawRegions = true;
// Enable non-production analysis visualization mode,
// which shows areas of a page that are being GPU accelerated with a colored overlay.
//Application.Current.Host.Settings.EnableCacheVisualization = true;
}
// You can declare objects here that you will use
//Examlpe: NameservicesReferent.(Function that returns services) = new NameservicesReferent.(Function that returns services)();
Ws_Function=new Nameservices.ServiceSoapClient()
步骤3:
在Mainpage.xaml.cs中
GlobalVariables.Ws_advertise.getLinkAdvertiseIndexCompleted += new EventHandler<advertise.getLinkAdvertiseIndexCompletedEventArgs>(Ws_advertise_getLinkAdvertiseIndexCompleted);
GlobalVariables.***NameWedservise***.getLinkAdvertiseIndexAsync("**parameters to be passed**");
GlobalVariables.Ws_advision.getlinkadviseindexcompleted+=新事件处理程序(Ws_advision_getlinkadviseindexcompleted);
全局变量。***namewedservice***.getLinkAdvertiseIndexAsync(“**要传递的参数**”);
步骤4:
void Ws_advertise_getLinkAdvertiseIndexCompleted(object sender, advertise.getLinkAdvertiseIndexCompletedEventArgs e)
{
//function returns the results to you, the example here is an array
string[] array = null;
try
{
array = e.result;
if(array != null)
}
cath(exception ex)
{
}
finally
{
array = null;
GlobalVariables.Ws_advertise.getLinkAdvertiseIndexCompleted -= new EventHandler<advertise.getLinkAdvertiseIndexCompletedEventArgs>(Ws_advertise_getLinkAdvertiseIndexCompleted);
}
}
void Ws\u advertive\u getLinkAdvertiseIndexCompleted(对象发送方,advertive.getLinkAdvertiseIndexCompletedEventArgs e)
{
//函数将结果返回给您,这里的示例是一个数组
字符串[]数组=null;
尝试
{
数组=e.result;
if(数组!=null)
}
cath(例外情况除外)
{
}
最后
{
数组=空;
GlobalVariables.Ws_advertise.getLinkAdvertiseIndexCompleted-=新事件处理程序(Ws_advertise_getLinkAdvertiseIndexCompleted);
}
}
Hi Jas可能与我执行的步骤相同。对于调用方法,我在对象资源管理器中找不到该方法,但在添加引用时看到了该方法。方法名称为“Genericmethod()”,但在对象资源管理器中我看到了“GenericWebMethodAsync()”,我找不到我的方法“Genericmethod()在对象资源管理器中,它正在返回数据集。请告诉我我做错了什么。我相信在WP7中,您只能异步调用方法,因此,添加引用时生成的代理仅创建异步调用。这就是为什么在对象浏览器中只能看到xxxxxancy()方法的原因。希望有帮助。
void Ws_advertise_getLinkAdvertiseIndexCompleted(object sender, advertise.getLinkAdvertiseIndexCompletedEventArgs e)
{
//function returns the results to you, the example here is an array
string[] array = null;
try
{
array = e.result;
if(array != null)
}
cath(exception ex)
{
}
finally
{
array = null;
GlobalVariables.Ws_advertise.getLinkAdvertiseIndexCompleted -= new EventHandler<advertise.getLinkAdvertiseIndexCompletedEventArgs>(Ws_advertise_getLinkAdvertiseIndexCompleted);
}
}