Microsoft Sync Framework for ADO. Net, TargetInvocationException

Hello,

   I am developing a windows mobile application in which I am using Sync framework with WCF.
I am trying to synchronize between the server and mobile client application. When I click Sync on the mobile client application I am getting the following exception:


System.Reflection.TargetInvocationException was unhandled
  Message="TargetInvocationException"
  StackTrace:
       at System.Reflection.RuntimeMethodInfo.InternalInvoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture, Boolean verifyAccess, StackCrawlMark& stackMark)
       at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
       at System.Reflection.MethodBase.Invoke(Object obj, Object[] parameters)
       at Microsoft.Synchronization.Data.ServerSyncProviderProxy.GetChanges(SyncGroupMetadata groupMetadata, SyncSession syncSession)
       at Microsoft.Synchronization.SyncAgent.DownloadChanges(SyncGroupMetadata groupMetadata)
       at Microsoft.Synchronization.SyncAgent.Synchronize()
       at MobileOrderManagement.BusinessLogic.Synchronize.SynchronizeDB()
       at MobileOrderManagement.OpenOrdersPage.SyncMenuItem_Click(Object sender, EventArgs e)
       at System.Windows.Forms.MenuItem.OnClick(EventArgs e)
       at System.Windows.Forms.Menu.ProcessMnuProc(Control ctlThis, WM wm, Int32 wParam, Int32 lParam)
       at System.Windows.Forms.Form.WnProc(WM wm, Int32 wParam, Int32 lParam)
       at System.Windows.Forms.Control._InternalWnProc(WM wm, Int32 wParam, Int32 lParam)
       at Microsoft.AGL.Forms.EVL.EnterMainLoop(IntPtr hwnMain)
       at System.Windows.Forms.Application.Run(Form fm)
       at MobileOrderManagement.Program.Main()
  InnerException: System.Net.WebException
       Message="Unable to connect to the remote server"
       StackTrace:
            at System.Net.HttpWebRequest.finishGetResponse()
            at System.Net.HttpWebRequest.GetResponse()
            at System.Web.Services.Protocols.WebClientProtocol.GetWebResponse(WebRequest request)
            at System.Web.Services.Protocols.HttpWebClientProtocol.GetWebResponse(WebRequest request)
            at System.Web.Services.Protocols.SoapHttpClientProtocol.doInvoke(String methodName, Object[] parameters, WebClientAsyncResult asyncResult)
            at System.Web.Services.Protocols.SoapHttpClientProtocol.Invoke(String methodName, Object[] parameters)
            at MobileOrderManagement.OrderDetailsProxy.OrderDetailsCacheSyncService.GetChanges(SyncGroupMetadata groupMetadata, SyncSession syncSession)
            at System.Reflection.RuntimeMethodInfo.InternalInvoke(RuntimeMethodInfo rtmi, Object obj, BindingFlags invokeAttr, Binder binder, Object parameters, CultureInfo culture, Boolean isBinderDefault, Assembly caller, Boolean verifyAccess, StackCrawlMark& stackMark)
            at System.Reflection.RuntimeMethodInfo.InternalInvoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture, Boolean verifyAccess, StackCrawlMark& stackMark)
            at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
            at System.Reflection.MethodBase.Invoke(Object obj, Object[] parameters)
            at Microsoft.Synchronization.Data.ServerSyncProviderProxy.GetChanges(SyncGroupMetadata groupMetadata, SyncSession syncSession)
            at Microsoft.Synchronization.SyncAgent.DownloadChanges(SyncGroupMetadata groupMetadata)
            at Microsoft.Synchronization.SyncAgent.Synchronize()
            at MobileOrderManagement.BusinessLogic.Synchronize.SynchronizeDB()
            at MobileOrderManagement.OpenOrdersPage.SyncMenuItem_Click(Object sender, EventArgs e)
            at System.Windows.Forms.MenuItem.OnClick(EventArgs e)
            at System.Windows.Forms.Menu.ProcessMnuProc(Control ctlThis, WM wm, Int32 wParam, Int32 lParam)
            at System.Windows.Forms.Form.WnProc(WM wm, Int32 wParam, Int32 lParam)
            at System.Windows.Forms.Control._InternalWnProc(WM wm, Int32 wParam, Int32 lParam)
            at Microsoft.AGL.Forms.EVL.EnterMainLoop(IntPtr hwnMain)
            at System.Windows.Forms.Application.Run(Form fm)
            at MobileOrderManagement.Program.Main()
       InnerException: System.Net.Sockets.SocketException
            Message="No connection could be made because the target machine actively refused it"
            ErrorCode=10061
            NativeErrorCode=10061
            StackTrace:
                 at System.Net.Sockets.Socket.ConnectNoCheck(EndPoint remoteEP)
                 at System.Net.Sockets.Socket.Connect(EndPoint remoteEP)
                 at System.Net.Connection.doConnect(IPEndPoint ep)
                 at System.Net.Connection.connect(Object ignored)
                 at System.Threading.ThreadPool.WorkItem.doWork(Object o)
                 at System.Threading.Timer.ring()

Can someone please help me to solve this issue.

Thank you,
Divya.
rgatigantiAsked:
Who is Participating?
 
hjgodeConnect With a Mentor Commented:
I assume either the service is not running on the server or the port is not correct.

If you just enter an address, the default port 80 for http is used.

According to http://msdn.microsoft.com/en-us/library/dd938879.aspx

"To configure the service

   1. Replace the <service> element definition in app.config with that suggested by the comment block.
   2. There are two important changes that you must make to the XML you just added:

In the <endpoint address=""…> element, change the binding attribute from binding="wsHttpBinding" to binding="basicHttpBinding". The .NET Compact Framework does not support "wsHttpBinding".

    * In the <baseAddresses> element, change the URL that is specified in the <add baseaddress…> statement from localhost:8080 to the correct host name and port where the service will be running, for example some_server:8088. "

the service does not use thta standard http port. So you have to enter the port behind the address before conecting. For example ttp://<ComputerName>:<Port>/cacheSyncService/

The link above shows
"Then start Internet Explorer Mobile on the device, and enter the URL of the service, for example: http://myserver:8080/NorthwindDataCacheSyncService/."  
as example

Possiblly you can follwo the instructions at the above link and find your mistake.

0
 
rgatigantiAuthor Commented:
I am using SQL server 2008 SP2 database and SQL Server CE 3.5 SP1 for devices. Please help me to solve this issue.
0
 
hjgodeCommented:
I never use the sync framework but the error you get is a network error:
========================
WSAECONNREFUSED
10061

Connection refused.

    No connection could be made because the target computer actively refused it. This usually results from trying to connect to a service that is inactive on the foreign host—that is, one with no server application running.
========================
(see http://msdn.microsoft.com/en-us/library/ms740668%28v=vs.85%29.aspx)

You have to check if the WCF service is running on the server, the TCP/IP connection between the client and the server in general, firewall settings and the WCF service port. See also http://msdn.microsoft.com/en-us/library/cc488004%28v=vs.90%29.aspx


If you need further assistance please describe your network connection.
0
Cloud Class® Course: Ruby Fundamentals

This course will introduce you to Ruby, as well as teach you about classes, methods, variables, data structures, loops, enumerable methods, and finishing touches.

 
rgatigantiAuthor Commented:
Hi,

  I have checked and WCF service is running on my server. I turned off firewall. Please help me further to resolve this issue. I am using basicHttp connection.

Thank you,
Divya.

0
 
hjgodeCommented:
How is the mobile connected to the server? It is a wireless connection?

You may test the connection using vxUtils (includes ping and a port scanner for windows mobile): http://www.cam.com/vxutil_pers.html

Please check if the server's IP address can be pinged and then if service port is open to the mobile device.
0
 
rgatigantiAuthor Commented:
No its not a wireless connection. I have used device emulator manager and cradled the device to use the machine's network.

Can you please explain how I should check if service port is open to the mobile device. I am new to this so please dont mind if the question is obvious.

Thank you,
Divya.
0
 
hjgodeCommented:
OK you are running the app in device emulator on your PC.

To have a network connection between the emulator device and the PC's network, ActiveSync or WMDC has to be running on the PC. Cradling the device in emulator does not necessary connect the emulated device to ActiveSync/WMDC.
In ActiveSync/WMDC is a connection setting saying "This connects to:" Work/Internet/Both. To have the ActiveSync/WMDC passthru the PC's Internet network connection to the emulated device the settings must be Internet or both. A work connection only lets the device connect to shared windows resources but not internet addresses.

Test if you can open a web page in internet explorer on the emulated device (EMUDEV). For example to microsoft.com.

Test in internet explorer if EMUDEV can open the standard website of the IIS providing the sync service.

You may also try in internet explorer mobile on the EMUDEV to open the basicHTTP address and port of the sync service.

regards

josef
0
 
hjgodeCommented:
One more possible test:

Recently I did a mobile app with SQLCE client. As all runtimes are available on the developing machine too, I could even run the compact framework targetting app on my developing machine by simply double clicking the exe (in bin\Debug or bin\Release of the project dir) and it runs on my desktop PC.

If all requirements for the exe are available on the desktop framework too, you may try to run your Sync App on the PC. Just a double click to try.

side note:
As the compact framework is a shrinked version of the full dot net framework a Compact Framework application can always be run on desktop PC if it does not reference any SmartDevice-only assemblies nor does any coredll.dll specific calls.

SQL Server Compact is available for both, full and compact framework and so my app was able to run on my PC.
0
 
rgatigantiAuthor Commented:
Hi,

   I really appreciate for all the information you have given me. Thank you for that.
I have checked the internet connection from the emulator. I am able to open microsoft.com from emulator.
But I have created WCF web service and added the web reference to my client project. I am not able to open that web service http://<ComputerName>/cacheSyncService/ from my browser on my server machine nor on the emulator. I think that is the reason for my exception. Can you let me know what I am missing over here.

Thank you,
Divya.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.