So I'm working on getting a communication channel open between my Unity game and a menu service written in WPF and C#. I've been having issues getting services to launch and finally came across the WebServiceHost. I was able to implement it in unity, it seems to open and return to me a `CommunicationState.Opened` state so it seems to have opened and be running but when I try to send a message to it through my web browser it tells me Bad Request (Invalid host). I'm very new to trying to do this so if my explanation is wrong I apologize. Below is the code I'm using to create and start the service as well as the messaging class. Also I'm entering http://localhost:9098/AMI/Megatouch/ShowInGameMenu?name=Quit into my web browser
[ServiceContract]
public interface IInGameMenuMessaging
{
[OperationContract]
[WebGet(UriTemplate = "ShowInGameMenu?name={name}")]
void ShowInGameMenu(string name);
[OperationContract]
[WebGet(UriTemplate = "HideInGameMenu")]
void HideInGameMenu();
}
[ServiceBehavior(InstanceContextMode = InstanceContextMode.Single)]
public class InGameMessaging : IInGameMenuMessaging
{
public void ShowInGameMenu(string name)
{
//Console.WriteLine("Inside ShowInGameMenu:{0}", name);
Debug.Log("Inside ShowInGameMenu:");
}
public void HideInGameMenu()
{
Console.WriteLine("Inside HideInGame");
}
}
public class service_host
{
public WebServiceHost StartHost()
{
Debug.Log("The service is Starting.");
var game_object = new InGameMessaging();
var host = new WebServiceHost(game_object, new Uri("http://localhost:9098/AMI/Megatouch"));
var ep = host.AddServiceEndpoint(typeof(IInGameMenuMessaging), new WebHttpBinding(), "InGameMenu");
host.Open();
return host;
}
}
WebServiceHost _webhost;
public static service_host host = new service_host();
// Use this for initialization
void Start()
{
_webhost = host.StartHost();
Debug.Log("Host is started");
Debug.Log("_webhost.State is " + _webhost.State.ToString());
}