Click here to Skip to main content
15,886,137 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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-
C#
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.
    [ServiceContract]
    public interface IService1
    {

        [OperationContract(IsOneWay=true)]
        void SendCreditLimitRequest(string id);


    }

}

and
C#
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;
            else
                value = 0;


        }
    }
}

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

  <system.web>
    <compilation debug="true" targetFramework="4.0" />
  </system.web>
  <system.serviceModel>
    <services>
      <service name="Service1">
        <clear />
        <host>
          <baseAddresses>
            <add  baseAddress ="http://localhhost/host"/>
          </baseAddresses>
        </host>
        <endpoint address="net.msmq://localhost/private/requestqueue"
          binding="netMsmqBinding" bindingConfiguration="" name="ServiceEndpoint"
          contract="WcfService2.IService1" />
      </service>
    </services>
    <behaviors>
      <serviceBehaviors>
        <behavior>
          <!-- 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"/>
        </behavior>
      </serviceBehaviors>
    </behaviors>
    <serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
  </system.serviceModel>
 <system.webServer>
    <modules runAllManagedModulesForAllRequests="true"/>
  </system.webServer>
  
</configuration>

----------------------------------------------------------------------------------
Code of my Window host is as :
C#
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()
        {
            InitializeComponent();
        }

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

        }

        private void button2_Click(object sender, EventArgs e)
        {
            host.Close();
        }
    }
}

--------------------------------------------------------------------------------
and exception i am facing is---
C#
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.
  Source=System.ServiceModel
  StackTrace:
       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()
  InnerException: 

----------------------
Please help !!
Posted
Updated 20-Apr-18 21:41pm
v2

The best answer I can give you is a link to the MSDN documentation on the topic:
http://msdn.microsoft.com/en-us/library/ms733107.aspx[^]
It explains in detail all of the queries you have in this post.
 
Share this answer
 
Comments
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.
fjdiewornncalwe 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
Check double check your service name and make sure you are using your namespace along with interface nothing other than that
<services>
     <service behaviorConfiguration="maxBehavior"
              name="SimplesServices.SimplesServices">

       <endpoint address="SimplesServices"
          binding="basicHttpBinding"
                 contract="SimplesServices.ISimplesServices"/>
       <host>
         <baseAddresses>
           <add baseAddress="http://localhost:8080"/>
         </baseAddresses>
       </host>
     </service>

Concentrate on the above section
 
Share this answer
 
v2

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900