Reputation: 67
I am attempting to wrap a WCF service that was previously running in an .asmx service in the taskbar into a Console App.
Here is the code for wrapping up the WCF Service:
class Program
{
static void Main(string[] args)
{
Uri uri = new Uri("http://localhost:5000");
using (ServiceHost host = new ServiceHost(typeof(CheckoutService), uri))
{
Console.WriteLine("Prepping CheckoutService server");
ServiceMetadataBehavior smb = new ServiceMetadataBehavior();
smb.HttpGetEnabled = true;
smb.MetadataExporter.PolicyVersion = PolicyVersion.Policy15;
host.Description.Behaviors.Add(smb);
host.Open();
Console.Clear();
Console.WriteLine("CheckoutService server up and running");
Console.WriteLine("Press Return to stop service at any point");
Console.ReadLine();
host.Close();
}
}
However, the client application that should receive this service (which used to work before the service was wrapped into a console app) is now crashing out with the error:
There was no endpoint listening at http://localhost:5000/CheckoutService.svc that could accept the message. This is often caused by an incorrect address or SOAP action. See InnerException, if present, for more details.
The endpoint configuration for this client in app.config is:
<endpoint
address="http://localhost:5000/CheckoutService.svc"
binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_ICheckoutService"
contract="CheckoutServiceServer.ICheckoutService" name="BasicHttpBinding_ICheckoutService" />
I think perhaps I am missing some form of .config
file in the console project hosting the WCF service but i could be wrong!
Upvotes: 2
Views: 7490
Reputation: 7961
You have not configured an endpoint for your ServiceHost
instance. The configuration file you referenced isn't being used, but based on this file you need to configure your ServiceHost
instance to use the BasicHttpBinding binding and your CheckoutServiceServer.ICheckoutService
contract to configure your service endpoint via the ServiceHost.AddServiceEndpoint()
method.
See this article for help with hosting a WCF service.
Upvotes: 0
Reputation: 15881
It looks like you're closing the host without waiting for user input. Are you missing Console.ReadLine()
?
Upvotes: 3