Host WCF in Windows Forms: Error when opening the host

I am trying to start and stop a WCF service library through a windows desktop application but got stuck. I cannot start it because it gives me error in the shost.Open();

Code:

private void startwcfedcHost()
{
    ServiceHost shost = new ServiceHost(typeof(WcfServiceLibrary.Service));
    shost.Open();
}

Error:

Service 'WcfServiceLibrary.Service' has zero application (non-infrastructure) 
endpoints.

This might be because no configuration file was found for your application, or because no service element matching the service name could be found in the configuration file, or because no endpoints were defined in the service element.

But when I try to run my wcf service it works, How can I fix this issue?

Answers


I suggest you take a look at the following:

Here


Since you don't specify the endpoints via code, you need to specify them via configuration. What you probably have is a missing configuration file. Change the Main method (if a console application; something like the Page_Loaded event if you're writing a windows app) to print the following value:

AppDomain.CurrentDomain.SetupInformation.ConfigurationFile

That will show the name that the application expects its configuration file to be. Once you have that, make sure that that file exists, and it has the appropriate <system.serviceModel> section to define the service endpoints.


WCF is about A(address) B(binding) C(contract), you need to specify binding.


Need Your Help

How can I view/edit my registry settings on a Windows CE 6 device?

usb windows-ce activesync regedit rndis

In his second comment here, PaulH suggests changing registry settings, providing this link.

Scala XML fetch a value based on tag name

xml scala

Is it possible to get the value of a tag based on the tags name? For example., in the following xml,

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.