Hi All,
I am trying to call a wcf service from background process(scheduled task) agent of windows phone 7.1 application. while this process is getting executed the service method that I am using getting called twice.
actually my background process execution starts with "OnInvoke(ScheduledTask task)" method and an exception is being thrown once I debug through "tservice.MymethodAsync(id, latitude, longitude);" method in the below code of "scheduledtaskagent" class:
protected override void OnInvoke(ScheduledTask task)
{
if (task is PeriodicTask)
{
Watcher = new GeoCoordinateWatcher(GeoPositionAccuracy.High);
Watcher.MovementThreshold = 10;
Watcher.StatusChanged +=
new EventHandler<GeoPositionStatusChangedEventArgs>(OnStatusChanged);
Watcher.PositionChanged +=
new EventHandler<GeoPositionChangedEventArgs<GeoCoordinate>> (OnPositionChanged);
Watcher.Start();
GPSDoneFlag.Reset();
GPSDoneFlag.WaitOne(10000);
}
#if DEBUG_AGENT
ScheduledActionService.LaunchForTest(task.Name, TimeSpan.FromSeconds(60));
#endif
NotifyComplete();
}
ShellToast toast = new ShellToast();
void OnStatusChanged(object sender, GeoPositionStatusChangedEventArgs e)
{
if (e.Status == GeoPositionStatus.Disabled)
{
toast.Title = "GPS";
toast.Content = "The location service is currently turned off.";
toast.Show();
}
else if (e.Status == GeoPositionStatus.NoData)
{
toast.Title = "GPS";
toast.Content = "No location data is currently available. Try again later.";
toast.Show();
}
else if (e.Status == GeoPositionStatus.Ready)
{
}
}
Location geolocation = new Location();
void OnPositionChanged(object sender, GeoPositionChangedEventArgs<GeoCoordinate> e)
{
geolocation = new GeoCoordinate(e.Position.Location.Latitude, e.Position.Location.Longitude);
lats = geolocation.Latitude.ToString();
longs = geolocation.Longitude.ToString();
updatelocation(lats, longs);
}
string id;
public static string filename = "data.txt";
public void updatelocation(string latitude, string longitude)
{
AppSettings tmpSettings = MyAppl.AppSettings.Load();
uid = tmpSettings.myString;
if (latitude == "" && longitude == "")
{
latitude = "No Data";
longitude = "No Data";
}
tservice.MymethodAsync(id, latitude, longitude);
tservice.MymethodCompleted += new EventHandler<MyAppl.myservice.UpdateLogCompletedEventArgs>(tservice_MymethodCompleted);
}
I am getting an exception at following method:
public System.IAsyncResult BeginMymethod(string id, string first, string second, System.AsyncCallback callback, object asyncState) {
object[] _args = new object[3];
_args[0] = id;
_args[1] = first;
_args[2] = second;
System.IAsyncResult _result = base.BeginInvoke("Mymethod", _args, callback, asyncState);
return _result;
<pre>
saying "The communication object, System.ServiceModel.Channels.HttpChannelFactory+HttpRequestChannel, is in the Opening state. Communication objects cannot be used for communication unless they are in the Opened state."
Could someone please help me resolve the issue