none
The type 'Service', provided as the Service attribute value in the ServiceHost directive, or provided in the configuration element system.serviceModel/serviceHostingEnvironment/serviceActivations could not be found

    Question

  • Hi,

    I am new to WCF. I am getting below error when i try to browse svc file from VS2010.

    Below is my code:

    namespace WcfService1
    {
        [ServiceContract]
        public interface IEmployee
        {
            [OperationContract]
            string GetName();
        }
        [DataContract]
        public class Employee
        {
            [DataMember]
            public string FirstName;
        }
    }

    namespace WcfService1
    {
        public class EmployeeService: IEmployee
        {
            public string GetName()
            {
                return "Veera";
            }
        }
    }

    Web.config file

    <system.serviceModel>
        <services>
          <service name="WcfService1.IEmployee.EmployeeService">
            <endpoint name="EmployeeEndPoint"
                      address=""
                      binding="basicHttpBinding"
                      contract="WcfService1.IEmployee"
                      behaviorConfiguration="EmployeeServiceBehavior"/>
          </service>
        </services>
        <behaviors>
          <serviceBehaviors>
            <behavior name="EmployeeServiceBehavior">
              <serviceMetadata httpGetEnabled ="true"/>
            </behavior>
            <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="false" />
      </system.serviceModel>

    Regards,

    Kummi


    Kummi

    Tuesday, June 19, 2012 10:44 PM

Answers

  • You havent configured meta data correctly in your service .... In your configuration file you have create service behavior but add it to endpoint behavior .... you should add this as a service behavior

    Do something like the following ....

    <services>
      <service
          name="WcfService1.EmployeeService"
          behaviorConfiguration="EmployeeServiceBehavior">
     <endpoint name="EmployeeEndPoint"
                      address=""
                      binding="basicHttpBinding"
                      contract="WcfService1.IEmployee"/>
        <endpoint address="mex"
                  binding="mexHttpBinding"
                  contract="IMetadataExchange" />
      </service>
    </services>
    <behaviors>
      <serviceBehaviors>
        <behavior name="EmployeeServiceBehavior">
          <serviceMetadata httpGetEnabled="True" policyVersion="Policy15" />
        </behavior>
      </serviceBehaviors>
    </behaviors>


    Tanvir Huda Application Architect/Consultant http://thetechnocrate.wordpress.com/

    • Marked as answer by Kummi Wednesday, June 20, 2012 2:11 AM
    Wednesday, June 20, 2012 12:50 AM

All replies

  • Hi

    Can you change your servicename to 'WcfService1.EmployeeService' in configuration file

    <service name="WcfService1.EmployeeService"></service>

    Also open the .svc file code behind file. There should be one line. And the service attribute should have the same name 'WcfService1.EmployeeService'


    Tanvir Huda Application Architect/Consultant http://thetechnocrate.wordpress.com/


    • Edited by Tanvir Huda Tuesday, June 19, 2012 11:29 PM
    Tuesday, June 19, 2012 11:28 PM
  • Hi Tanvir,

    Even after doing the suggested changes i am still facing the same issue. Below are the changes implemented

    EmpService.svc

    <%@ ServiceHost Language="C#" Debug="true" Service="WcfService1.EmployeeService"  %>

    Web.config file

    <service name="WcfService1.EmployeeService">

    Note: 

    When i run using WCF Test Client, i am getting the below expception:

    "Failed to add a service. Service metadata may not be accessible. Make sure your service is running and exposing metadata."

    Error Details:

    Error: Cannot obtain Metadata from http://localhost:3626/EmpService.svc If this is a Windows (R) Communication Foundation service to which you have access, please check that you have enabled metadata publishing at the specified address.  For help enabling metadata publishing, please refer to the MSDN documentation at http://go.microsoft.com/fwlink/?LinkId=65455.WS-Metadata Exchange Error    URI: http://localhost:3626/EmpService.svc    Metadata contains a reference that cannot be resolved: 'http://localhost:3626/EmpService.svc'.    The server did not provide a meaningful reply; this might be caused by a contract mismatch, a premature session shutdown or an internal server error.HTTP GET Error    URI: http://localhost:3626/EmpService.svc    There was an error downloading 'http://localhost:3626/EmpService.svc'.    The request failed with the error message:--<html>    <head>        <title>Configuration Error</title>        <style>         body {font-family:"Verdana";font-weight:normal;font-size: .7em;color:black;}          p {font-family:"Verdana";font-weight:normal;color:black;margin-top: -5px}         b {font-family:"Verdana";font-weight:bold;color:black;margin-top: -5px}         H1 { font-family:"Verdana";font-weight:normal;font-size:18pt;color:red }         H2 { font-family:"Verdana";font-weight:normal;font-size:14pt;color:maroon }         pre {font-family:"Lucida Console";font-size: .9em}         .marker {font-weight: bold; color: black;text-decoration: none;}         .version {color: gray;}         .error {margin-bottom: 10px;}         .expandable { text-decoration:underline; font-weight:bold; color:navy; cursor:hand; }        </style>    </head>    <body bgcolor="white">            <span><H1>Server Error in '/' Application.<hr width=100% size=1 color=silver></H1>            <h2> <i>Configuration Error</i> </h2></span>            <font face="Arial, Helvetica, Geneva, SunSans-Regular, sans-serif ">            <b> Description: </b>An error occurred during the processing of a configuration file required to service this request. Please review the specific error details below and modify your configuration file appropriately.            <br><br>            <b> Parser Error Message: </b>There is no endpoint behavior named 'EmployeeServiceBehavior'.<br><br>            <b>Source Error:</b> <br><br>            <table width=100% bgcolor="#ffffcc">               <tr>                  <td>                      <code><pre>Line 8:      <services>Line 9:        <service name="WcfService1.EmployeeService"><font color=red>Line 10:         <endpoint name="EmployeeEndPoint"</font>Line 11:                   address=""Line 12:                   binding="basicHttpBinding"</pre></code>                  </td>               </tr>            </table>            <br>            <b> Source File: </b> E:\VeeraStuff\Sandbox\Practise\C#\WcfService1\web.config<b> ÿÿ Line: </b> 10            <br><br>            <hr width=100% size=1 color=silver>            <b>Version Information:</b>ÿMicrosoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.272            </font>    </body></html><!-- [ConfigurationErrorsException]: There is no endpoint behavior named 'EmployeeServiceBehavior'. (E:\VeeraStuff\Sandbox\Practise\C#\WcfService1\web.config line 10)   at System.Configuration.BaseConfigurationRecord.EvaluateOne(String[] keys, SectionInput input, Boolean isTrusted, FactoryRecord factoryRecord, SectionRecord sectionRecord, Object parentResult)   at System.Configuration.BaseConfigurationRecord.Evaluate(FactoryRecord factoryRecord, SectionRecord sectionRecord, Object parentResult, Boolean getLkg, Boolean getRuntimeObject, Object& result, Object& resultRuntimeObject)   at System.Configuration.BaseConfigurationRecord.GetSectionRecursive(String configKey, Boolean getLkg, Boolean checkPermission, Boolean getRuntimeObject, Boolean requestIsHere, Object& result, Object& resultRuntimeObject)   at System.Configuration.BaseConfigurationRecord.GetSection(String configKey)   at System.Web.Configuration.HttpConfigurationSystem.GetSection(String sectionName, VirtualPath path)   at System.Web.Configuration.WebConfigurationManager.GetSection(String sectionName, String path)   at System.ServiceModel.Activation.HostedAspNetEnvironment.UnsafeGetSectionFromWebConfigurationManager(String sectionPath, String virtualPath)   at System.ServiceModel.Activation.HostedAspNetEnvironment.UnsafeGetConfigurationSection(String sectionPath)   at System.ServiceModel.Configuration.ConfigurationHelpers.UnsafeGetAssociatedSection(ContextInformation evalContext, String sectionPath)   at System.ServiceModel.Description.ConfigLoader.LookupService(String serviceConfigurationName)   at System.ServiceModel.ServiceHostBase.ApplyConfiguration()   at System.ServiceModel.ServiceHostBase.InitializeDescription(UriSchemeKeyedCollection baseAddresses)   at System.ServiceModel.ServiceHost.InitializeDescription(Type serviceType, UriSchemeKeyedCollection baseAddresses)   at System.ServiceModel.ServiceHost..ctor(Type serviceType, Uri[] baseAddresses)   at System.ServiceModel.Activation.ServiceHostFactory.CreateServiceHost(Type serviceType, Uri[] baseAddresses)   at System.ServiceModel.Activation.ServiceHostFactory.CreateServiceHost(String constructorString, Uri[] baseAddresses)   at System.ServiceModel.ServiceHostingEnvironment.HostingManager.CreateService(String normalizedVirtualPath)   at System.ServiceModel.ServiceHostingEnvironment.HostingManager.ActivateService(String normalizedVirtualPath)   at System.ServiceModel.ServiceHostingEnvironment.HostingManager.EnsureServiceAvailable(String normalizedVirtualPath)[ServiceActivationException]: The service '/EmpService.svc' cannot be activated due to an exception during compilation.  The exception message is: There is no endpoint behavior named 'EmployeeServiceBehavior'. (E:\VeeraStuff\Sandbox\Practise\C#\WcfService1\web.config line 10).   at System.Runtime.AsyncResult.End[TAsyncResult](IAsyncResult result)   at System.ServiceModel.Activation.HostedHttpRequestAsyncResult.End(IAsyncResult result)   at System.ServiceModel.Activation.HostedHttpRequestAsyncResult.ExecuteSynchronous(HttpApplication context, String routeServiceVirtualPath, Boolean flowContext, Boolean ensureWFService)   at System.ServiceModel.Activation.HttpModule.ProcessRequest(Object sender, EventArgs e)   at System.Web.HttpApplication.SyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()   at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)-->--.

    Regards,

    Kummi


    • Edited by Kummi Wednesday, June 20, 2012 12:25 AM Added exception details
    Wednesday, June 20, 2012 12:18 AM
  • You havent configured meta data correctly in your service .... In your configuration file you have create service behavior but add it to endpoint behavior .... you should add this as a service behavior

    Do something like the following ....

    <services>
      <service
          name="WcfService1.EmployeeService"
          behaviorConfiguration="EmployeeServiceBehavior">
     <endpoint name="EmployeeEndPoint"
                      address=""
                      binding="basicHttpBinding"
                      contract="WcfService1.IEmployee"/>
        <endpoint address="mex"
                  binding="mexHttpBinding"
                  contract="IMetadataExchange" />
      </service>
    </services>
    <behaviors>
      <serviceBehaviors>
        <behavior name="EmployeeServiceBehavior">
          <serviceMetadata httpGetEnabled="True" policyVersion="Policy15" />
        </behavior>
      </serviceBehaviors>
    </behaviors>


    Tanvir Huda Application Architect/Consultant http://thetechnocrate.wordpress.com/

    • Marked as answer by Kummi Wednesday, June 20, 2012 2:11 AM
    Wednesday, June 20, 2012 12:50 AM
  • Thanks Tanvir,

    It is now working.

    Thanks for your help


    Kummi

    Wednesday, June 20, 2012 2:11 AM