I want to access the response value with in the WCF callback handler while communicating with the WCF Service hosted as server from Client Side in asp.net with c# using Visual Studio 2017.
I am trying to communicate client server side over a web socket.
I have hosted the WCF Web Service which is being hosted. I want to communicate with the server from the client side as a web application and get the response to a text-box.
The output is obtained with in the call back handler but it is not accessible to the main method outside it
Code set in the code block below will illustrate it even further
What I have tried:
Server Side:
[ServiceContract(CallbackContract = typeof(IServiceCallback))]
public interface IService1
{
[OperationContract(IsOneWay = true)]
Task Hello(string messsage);
}
public interface IServiceCallback
{
[OperationContract(IsOneWay = true)]
Task OnHello(string message);
}
<pre> Task IService1.Hello(string messsage)
{
var callback = OperationContext.Current.GetCallbackChannel<IServiceCallback>();
return callback.OnHello("You Said:" + messsage);
}
}
Client Side:
protected void btnGetResponse_Click(object sender, EventArgs e)
{
var context = new InstanceContext(new WCFServiceCallbackHandler());
var client = new ServiceReference1.Service1Client(context);
bool exit = false;
Console.WriteLine("Enter X to exit:");
Console.WriteLine("Write and enter to send something to server:");
while (!exit)
{
Console.WriteLine("Client:");
String stringToSend = txtMsgToServer.Text;
if (stringToSend.ToUpper() != "X")
{
client.Hello(stringToSend);
}
else { exit = true; }
}
}
}
public class WCFServiceCallbackHandler : ServiceReference1.IService1Callback
{
public string result { get; set; }
void ServiceReference1.IService1Callback.OnHello(string message)
{
Console.WriteLine(message);
result = message;
}