http WCF service in winforms RRS feed

  • Question

  • I have a winforms app that will be running on a networked pc, and it's creating a WebServiceHost with an endpoint using NetHttpBinding so I can connect to it from a js app in a browser.

    _WebServiceUri = new Uri("http://localhost:8000/");
    _WebServiceHost = new WebServiceHost(typeof(IRemoteGenericService), _WebServiceUri);
    _WebServiceHost.AddServiceEndpoint(typeof(IRemoteGenericService), new NetHttpBinding(BasicHttpSecurityMode.None, true), "RemoteGenericService"); 

    So essentially I want this forms app to be a quasi web server for WCF services to browser based apps.  I want to use REST and JSON for client/server comm. I configured the contract like this:

    [ServiceContract(Namespace ="RfaWebWcfInterface")]
    internal interface IRemoteGenericService    
      [WebInvoke(Method = "GET", ResponseFormat = WebMessageFormat.Json)]
      string GetPCName();

    Normally this is all configured in a svc file when used in a ASP.net scenario, but in this case, since it's in a winforms app it doesn't have a svc file, and there is no web site the client connects to.

    So my question is this.  How do I configure the client (and maybe the server, if I've missed something) to consume the WCF service?  I found the following code snippet on another site, but I don't know what to put in the url argument since this is not a web server.

    function callTest(){
    	url: "",
            dataType: "json",
            type: "GET",
            success: function (data, textStatus, jqXHR) {
               // perform a success processing
            error: function (jqXHR, textStatus, errorThrown) {
               alert('An error has occurred while trying to communicate with the service.');
            complete: function (jqXHR, textStatus) {
            //any process that needs to be done once the service call is complete        

    So how do I call a wcf service from a js when the service is running on a winforms app?


    • Moved by CoolDadTx Thursday, December 5, 2019 6:52 PM ASP.NET related
    Thursday, December 5, 2019 4:24 PM

All replies

  • This isn't going to work with a winforms app but I'll let the web dev folks over in the correct forums help you out. Please post your question there.

    Michael Taylor http://www.michaeltaylorp3.net

    Thursday, December 5, 2019 6:52 PM