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

Microsoft Excel 2010: Help making a Formula to up Values by a repeating pattern

excel design-patterns formula repeating

I have a Spreadsheet, and inside this sheet contains a column with numbers, I want to make a formula that will go down that Column and do basically this.. Values: 1 will be 9.50. 2 will be 9.75. 3 ...

Node.js port listening and reading from stdin at the same time

sockets node.js stdin

I have a socket server in Node.js and I'd like to be able to read from stdin at the same time the server is listening. It works only partially. I'm using this code:

findViewById returns null in a custom view with subviews inside

android null android-custom-view findviewbyid

I'm developing a View that shows a stack of messages making fadeIn,fadeOut and wait time between them. It has a stack of messages and when I need to display some of them I added to it. This view ha...

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.