Click here to Skip to main content
12,759,432 members (31,834 online)
Rate this:
Please Sign up or sign in to vote.
See more: C#3.0 C# WCF
Hi All,

I have recently started to study WCF and I am really confused in Endpoints.
What are Host endpoints exactly.

I have created a simple host and client service and hosted then in Windows Form.But i am unable to invoke services. :(
Code of hostService-
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.ServiceModel.Web;
using System.Text;

namespace WcfService2
    // NOTE: You can use the "Rename" command on the "Refactor" menu to change the interface name "IService1" in both code and config file together.
    public interface IService1

        void SendCreditLimitRequest(string id);



using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.ServiceModel.Web;
using System.Text;

namespace WcfService2
    // NOTE: You can use the "Rename" command on the "Refactor" menu to change the class name "Service1" in code, svc and config file together.
    public class Service1 : IService1

        public void  SendCreditLimitRequest(string id)
            double value;

            if (id == "1")
                value = 10;
            else if (id == "2")
                value = 20;
                value = 0;


Its Web Config is--
<?xml version="1.0"?>

    <compilation debug="true" targetFramework="4.0" />
      <service name="Service1">
        <clear />
            <add  baseAddress ="http://localhhost/host"/>
        <endpoint address="net.msmq://localhost/private/requestqueue"
          binding="netMsmqBinding" bindingConfiguration="" name="ServiceEndpoint"
          contract="WcfService2.IService1" />
          <!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment -->
          <serviceMetadata httpGetEnabled="true"/>
          <!-- To receive exception details in faults for debugging purposes, set the value below to true.  Set to false before deployment to avoid disclosing exception information -->
          <serviceDebug includeExceptionDetailInFaults="false"/>
    <serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
    <modules runAllManagedModulesForAllRequests="true"/>

Code of my Window host is as :

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.ServiceModel;
using System.ServiceProcess;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace host
    public partial class Form1 : Form
        ServiceHost host;
        public Form1()

        private void button1_Click(object sender, EventArgs e)
            host = new ServiceHost(typeof(WcfService2.Service1Client));
            MessageBox.Show("Service Started!");


        private void button2_Click(object sender, EventArgs e)

and exception i am facing is---
System.InvalidOperationException was unhandled
  Message=Service 'host.WcfService2.Service1Client' 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.
       at System.ServiceModel.Description.DispatcherBuilder.EnsureThereAreApplicationEndpoints(ServiceDescription description)
       at System.ServiceModel.Description.DispatcherBuilder.InitializeServiceHost(ServiceDescription description, ServiceHostBase serviceHost)
       at System.ServiceModel.ServiceHostBase.InitializeRuntime()
       at System.ServiceModel.ServiceHostBase.OnBeginOpen()
       at System.ServiceModel.ServiceHostBase.OnOpen(TimeSpan timeout)
       at System.ServiceModel.Channels.CommunicationObject.Open(TimeSpan timeout)
       at System.ServiceModel.Channels.CommunicationObject.Open()
       at host.Form1.button1_Click(Object sender, EventArgs e) in C:\WcfPrograms\host\host\Form1.cs:line 25
       at System.Windows.Forms.Control.OnClick(EventArgs e)
       at System.Windows.Forms.Button.OnClick(EventArgs e)
       at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
       at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
       at System.Windows.Forms.Control.WndProc(Message& m)
       at System.Windows.Forms.ButtonBase.WndProc(Message& m)
       at System.Windows.Forms.Button.WndProc(Message& m)
       at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
       at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
       at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
       at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
       at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(IntPtr dwComponentID, Int32 reason, Int32 pvLoopData)
       at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
       at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
       at System.Windows.Forms.Application.Run(Form mainForm)
       at host.Program.Main() in C:\WcfPrograms\host\host\Program.cs:line 18
       at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
       at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
       at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
       at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean ignoreSyncCtx)
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
       at System.Threading.ThreadHelper.ThreadStart()

Please help !!
Posted 25-Sep-12 10:46am
Updated 25-Sep-12 11:14am

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

The best answer I can give you is a link to the MSDN documentation on the topic:[^]
It explains in detail all of the queries you have in this post.
vicvis 28-Sep-12 9:23am
I have changed my App.config and problem was resolved.
However one question is still in my mind.....What happens and restriction i will face in case Metadata Endpoints are not provided by me.
Marcus Kramer 28-Sep-12 10:17am
I'm not entirely sure, but I would assume if the endpoints were meant to be dynamic on deployed versions of my code I would provide an interface to make sure that endpoints get configured properly from within the application.
vicvis 2-Oct-12 12:24pm
I am still unable to understand why we define client endpoints in our service config.
I understand what are endpoints on service side but defining endpoints under <client> tag is my question???Can somebody please throw light on this.Thanks in advance

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

    Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web02 | 2.8.170217.1 | Last Updated 25 Sep 2012
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100