Click here to Skip to main content
12,996,722 members (78,224 online)
Rate this:
Please Sign up or sign in to vote.
See more:
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);
ScheduledActionService.LaunchForTest(task.Name, TimeSpan.FromSeconds(60));
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.";
else if (e.Status == GeoPositionStatus.NoData)
toast.Title = "GPS";
toast.Content = "No location data is currently available. Try again later.";
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;
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
Posted 14-May-12 3:31am

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web01 | 2.8.170609.2 | Last Updated 14 May 2012
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100