0

I am Creating a smart Device Application for my client in Visual studio 2008. I Have Create a web service to get stock data from actual database and save in windows ce Device Compact database on a button click event of smart device application. Here is my code:

    private void btnGetData_Click(object sender, EventArgs e)
    {
        ServiceAgent.InventorySev ws = new InvetoryDevice.ServiceAgent.InventorySev();

        AsyncCallback cb = new AsyncCallback(ServiceCallback);
        ws.BeginGetInventoryData(cb, ws);
    }

    private void ServiceCallback(IAsyncResult ar)
    {
        ServiceAgent.InventorySev ws = (ServiceAgent.InventorySev)ar.AsyncState;
        DataTable dt = ws.EndGetInventoryData(ar);
    }

I am geting Error:

   DataTable dt = ws.EndGetInventoryData(ar);

Error:

    System.Net.WebException was unhandled
    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.doAsyncInvoke(Object asyncResultAsObject)
            at System.Threading.ThreadPool.WorkItem.doWork(Object o)
            at System.Threading.Timer.ring()
    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()
Sadequzzaman Monoj
  • 121
  • 2
  • 3
  • 10
  • Could you show the code of your `webservice`? –  Apr 20 '14 at 12:22
  • possible duplicate of [No connection could be made because the target machine actively refused it 127.0.0.1:3446](http://stackoverflow.com/questions/9695224/no-connection-could-be-made-because-the-target-machine-actively-refused-it-127-0) – wruckie Apr 20 '14 at 12:26
  • My Web service Code is: [WebMethod] public DataTable GetInventoryData() { BuyTableAdapter ta = new BuyTableAdapter(); InvDataSet.BuyDataTable buy = ta.GetCurrnetStock(); return buy; } – Sadequzzaman Monoj Apr 20 '14 at 12:57

1 Answers1

1

Your question seems to be a duplication. Regardless, your problem is not in your code, but with the connection to the database.

Quoted from No connection could be made because the target machine actively refused it 127.0.0.1:3446

"Actively refused it" means that the host sent a reset instead of an ack when you tried to connect. It is therefore not a problem in your code. Either there is a firewall blocking the connection or the process that is hosting the service is not listening on that port, this may be because it is not running at all or because it is listening on a different port.

once you start the process hosting your service try netstat -anb (requires admin privileges) to verify that it is running and listening on the expected port.

Community
  • 1
  • 1
wruckie
  • 1,717
  • 1
  • 23
  • 34