To use webservice I added a web service reference and then added the following code to my MainPage.xaml.cs file.
using System;
using System.Collections.Generic;
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;
namespace WebServiceTest
{
public partial class MainPage : PhoneApplicationPage
{
// Constructor
public MainPage()
{
InitializeComponent();
}
private void PhoneApplicationPage_Loaded(object sender, RoutedEventArgs e)
{
try
{
ServiceReference.PDAServiceSoapClient ws =
new ServiceReference.PDAServiceSoapClient();
ws.GetResoureAroudCompleted +=
new EventHandler<ServiceReference.GetResoureAroudCompletedEventArgs>(ws_GetResoureAroudCompleted);
ws.GetResoureAroudAsync("基站,机楼", 113, 23, 10000);
}
catch
{
System.Windows.MessageBox.Show("error!");
}
}
void ws_GetResoureAroudCompleted(object sender, ServiceReference.GetResoureAroudCompletedEventArgs e)
{
if (e.Error != null)
{
var result = e.Result;
}
}
}
}
Then I ran PhoneApplication and got this exception:
System.InvalidOperationException was unhandled
Message=There was an error reflecting type ‘WebServiceTest.ServiceReference.GetResoureAroudResponseGetResoureAroudResult’.
InnerException: System.InvalidOperationException
Message=There was an error reflecting property ‘Any1’.
in Reference.cs
Code:
public WebServiceTest.ServiceReference.GetResoureAroudResponseGetResoureAroudResult EndGetResoureAroud(System.IAsyncResult result) {
object[] _args = new object[0];
**WebServiceTest.ServiceReference.GetResoureAroudResponseGetResoureAroudResult _result = ((WebServiceTest.ServiceReference.GetResoureAroudResponseGetResoureAroudResult)(base.EndInvoke("GetResoureAroud", _args, result)));**
return _result;
}
It’s not caught by try-catch, anybody know why?
The exception is not caught by your exception handler because it occurs in the framework and is out of scope. Depending on whether the webservice conforms to best practice, it may surface an Error object and if so you should inspect this prior to attempting to retrieve any data.
This can produce symptoms similar to yours, but I’m not certain this is the problem you face.