Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: WinMobile
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
Posted 14-May-12 3:31am
skumarn654

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

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 598
1 OriginalGriff 280
2 George Jonsson 258
3 CPallini 190
4 Animesh Datta 130
0 OriginalGriff 5,985
1 Sergey Alexandrovich Kryukov 5,341
2 CPallini 4,760
3 George Jonsson 3,400
4 Gihan Liyanage 2,522


Advertise | Privacy | Mobile
Web01 | 2.8.140916.1 | Last Updated 14 May 2012
Copyright © CodeProject, 1999-2014
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