Click here to Skip to main content
15,887,376 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I am getting empty response while invoking the WCF service hosted as a server through windows service in asp.net with C#.The WCF service reference and dll of it has been added to the windows service and it has been updated to invoke the server But no response coming from the Service though. No exceptions there but no response coming.

The core code in the WCF interface and main code part and the invoking part via the windows service is being updated below.

What I have tried:

Core code part
WCF Part:
interface part
[ServiceContract(CallbackContract = typeof(IWebSocketTestCallback))]
  public interface IWebSocketTest
  {
      [OperationContract(IsOneWay = true)]
      Task EncAndSendFinancial(string strRequestAPI);
  }
  public interface IWebSocketTestCallback
  {
      [OperationContract(IsOneWay = true)]
      Task OnEncAndSendFinancial(string strRequestAPI);
  }

WCF.cs part
Task IWebSocketTest.EncAndSendFinancial(string strRequestAPI)
      {
          var callback = OperationContext.Current.GetCallbackChannel<IWebSocketTestCallback>();
          return callback.OnEncAndSendFinancial("Hi Alex:"+ strRequestAPI); //pass response API

      }


Windows Service invoke the callbackhandler:
var context = new InstanceContext(new WCFServiceCallbackHandler());
                   var client = new ServiceReference1.WebSocketTestClient(context);

private class WCFServiceCallbackHandler : ServiceReference1.IWebSocketTestCallback
       {
           void ServiceReference1.IWebSocketTestCallback.OnEncAndSendFinancial(string strRequestAPI)
           {
               Console.WriteLine(strRequestAPI);

               string filePath = ConfigurationSettings.AppSettings["filepath"].ToString().Trim();


               using (StreamWriter writer = new StreamWriter(filePath, true))
               {
                   writer.WriteLine("Message :" + strRequestAPI + "<br/>" + Environment.NewLine);
                   writer.WriteLine(Environment.NewLine + "-----------------------------------------------------------------------------" + Environment.NewLine);
               }
           }
       }
Posted
Updated 5-Jul-18 11:04am
v2

1 solution

Your issue seems same as in this msdn thread . "Windows Service does not have handles; So, CallBack Can not be called". Try using Synchronous WCF Method that may solve your problem.
 
Share this answer
 
v2

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900