connect IIS hosted c# web service to photon server

Options
BesoC
BesoC ✭✭
edited March 2014 in Photon Server
Hello Photon development team :)

Is there a way to connect IIS hosted c# web service to photon server? The problem is that the web service is not durable, so PhotonPeer descendent class cannot listen for events, nor call even call Service(). The only way i can think of is (and it's working) to write a WCF windows service. Perhaps you can suggest something?

Regards

Comments

  • Just to make sure that I understand this correctly, you want to build a IIS web service that acts as a Photon client?

    In theory, it's possible with the Photon .NET client lib. You can disable the "inactivity timeout" for the applicaton pool in IIS and configure a monitoring service (like pingdom) to send a request to your app regularly to wake it up.. if you want to work around the "unreliable" uptime of IIS applications.

    WCF or Windows Services (depending on your requirements) might be other viable approaches...

    Maybe you can do it "the other way round" and let Photon call the WebService? That approach is very common and works fine (and in fact, I thought you were asking about that, so I needed to read your question twice before I realized what you want to do).

    It's hard to give advice about your architecture without knowing what you want to achieve, so I can not give much help here.. sorry! :)
  • BesoC
    BesoC ✭✭
    Options
    Thanks for quick reply, Nicole

    Perhaps i didn't shaped my question well enough. Say, some external service needs to communicates with my server and update client status - online, offline, away, etc. The easiest way to do it - create a web service that external system can call. So, here comes my question - how can it be done?
  • chvetsov
    Options
    As Nicole has written before you may send http requests from Photon server to your external service. This requests will contain information about players as JSON string.

    Next thing you may do is start from Photon server some other webservice, like ServiceStack. if there is a sample in Photon SDK it should be called PhotonHttpServiceApp.

    Third, you may open plain socket connection between you Photon server and Http Server session, and do everything through this socket
  • BesoC
    BesoC ✭✭
    Options
    Hi Ilya

    1. External service should update client status, so Photon server receives data and not sends any requests

    2. I have investigated ServiceStack a little. Looks like it's some kind of replacement for WCF. Do you mean that it can be integrated into Photon server, so Photon server will 'host' webservice itself? However, it's not free. I was also unable to found any mentions of PhotonHttpServiceApp in samples, I didn't even imagined that it was possible. Can you please give me some more information about it?

    3. How can it be done? are there any tutorials or examples? Is it possible to declare Photon .NET client in http server, connect it to Photon Server and listen for operation responses / events?
  • chvetsov
    Options
    >> 1. External service should update client status, so Photon server receives data and not sends any requests
    As i understand you would like external server pereodically sends updates to PhotonServer, if so then PhotonServer may ask pereodically about player's state. or this does not fit your needs?

    2. You are right. You may use WCF or Service Stack. For service stack follow this tutorial.
    Code from Main put into Photon Application Setup method of course except

    Console.WriteLine("AppHost Created at {0}, listening on {1}", DateTime.Now, listeningOn);
    Console.ReadKey();

    3. Well, i know that this is possible in Apache. you may create listening socket in Photon, and create general socket from session. I assumed, that something similar may be done with IIS.
    This is just usual work with sockets. There is nothing special, so you may find tutorial in MSDN
  • chvetsov
    Options
    2. for WCF you may find tutorial in web. All you need just create object of right class and call start for it in Application.Setup
  • BesoC
    BesoC ✭✭
    Options
    >> 1. External service should update client status, so Photon server receives data and not sends any requests
    As i understand you would like external server pereodically sends updates to PhotonServer, if so then PhotonServer may ask pereodically about player's state. or this does not fit your needs?
    No, it does not. Users can be several hundred at a time, so it will be like 'bombing' the external server.
    2. You are right. You may use WCF or Service Stack. For service stack follow this tutorial.
    Code from Main put into Photon Application Setup method of course except

    Console.WriteLine("AppHost Created at {0}, listening on {1}", DateTime.Now, listeningOn);
    Console.ReadKey()
    for WCF you may find tutorial in web. All you need just create object of right class and call start for it in Application.Setup
    Frankly, i didn't thought about it. I did create a WCF Windows service and it works - PhotonPeer connects to Photon server. However I didn't though about putting WCF service inside Photon server itself. Thanks for the good idea :)
    3. Well, i know that this is possible in Apache. you may create listening socket in Photon, and create general socket from session. I assumed, that something similar may be done with IIS.
    This is just usual work with sockets. There is nothing special, so you may find tutorial in MSDN
    Same as 2. However, i think that WCF is better then sockets :)

    Thank you very much, Ilya

    P.S. There is no link for the ServerStack tutorial. Can you please post it?
  • BesoC
    BesoC ✭✭
    Options
    Hello again

    I have created WCF library and put it into Photon Server:
    [code2=csharp]private static ServiceHost _integrationService;
    if (_integrationService == null)
    {
    _integrationService = new ServiceHost(typeof (IntegrationService));
    BasicHttpBinding basicHttpBinding = new BasicHttpBinding();
    //Modify your bindings settings if you wish, for example timeout values
    System.ServiceModel.Description.ServiceEndpoint serviceEndpoint = _integrationService.AddServiceEndpoint(typeof (IIntegrationService),
    basicHttpBinding,
    "http://localhost:9876/Integration/IntegrationService/");
    IntegrationService.BalanceChanged += BalanceChanged;
    _integrationService.Open();
    DoLogDebug(string.Format("ServicePoint Added at: {0}", serviceEndpoint.ListenUri), Enums.DebugTypes.Info);
    }[/code2]

    However, after start, browser displays empty page. if i stop Photon server, then browser cannot connect to localhost:9876, therefore, the servicehost is opened. I also changed access rights giving rights to everyone to create endpoint at http://localhost:9876/Integration/IntegrationService/. still blank page. From Visual Studio debug WCF runs OK. What can it be? maybe Photon server requires something?
  • chvetsov
    Options
    here is link for tutorial https://github.com/ServiceStack/Service ... lf-hosting

    i can not say much about WFC, I tried about year ago and it worked well, Similar on ServiceStack.
    I assume that this is just simple error, you will find it if will be attentive enough