http WCF service in winforms

  • Thread starter Thread starter smittywood000
  • Start date Start date
S

smittywood000

Guest
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");
_WebServiceHost.Open();

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
{
[OperationContract]
[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(){
$.ajax({
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.');
$("body").append(jqXHR.responseText)
},
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?


Thanks

Continue reading...
 
Back
Top