You must Sign In to post a response.
  • Category: WCF

    Server Error in '/' Application. Could not find default endpoint element that references contract

    I am creating my first rest api. I followed below link. http://www.codeproject.com/Articles/105273/Create-RESTful-WCF-Service-API-Step-By-Step-Guide.Link is excellent. Steps 1: I have created new project WCFservice application.Deleted already created Interface and class.Added new service into it.Project name is 'RestService' and service name is 'IRestServiceImpl'

    step 2: Interface

    namespace RestService
    {
    // NOTE: You can use the "Rename" command on the "Refactor" menu to change the interface name "IRestServiceImpl" in both code and config file together.
    [ServiceContract]
    public interface IRestServiceImpl
    {
    [OperationContract]
    [WebInvoke(Method="GET",ResponseFormat=WebMessageFormat.Xml,BodyStyle=WebMessageBodyStyle.Wrapped,UriTemplate="xml/{id}") ]
    string XmlData(string id);

    [OperationContract]
    [WebInvoke(Method = "GET", ResponseFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.Wrapped, UriTemplate = "json/{id}")]
    string JSONData(string id);
    }
    }
    step 3: Class Implementing Interface
    namespace RestService
    {
    // NOTE: You can use the "Rename" command on the "Refactor" menu to change the class name "RestServiceImpl" in code, svc and config file together.
    // NOTE: In order to launch WCF Test Client for testing this service, please select RestServiceImpl.svc or RestServiceImpl.svc.cs at the Solution Explorer and start debugging.
    public class RestServiceImpl : IRestServiceImpl
    {
    public string XmlData(string id)
    {
    return "Your id is " + id;
    }

    public string JSONData(string id)
    {
    return "Your id is " + id;
    }
    }
    }
    step 4 : Webconfig
    <?xml version="1.0"?>
    <configuration>

    <appSettings>
    <add key="aspnet:UseTaskFriendlySynchronizationContext" value="true" />
    </appSettings>
    <system.web>
    <compilation debug="true" targetFramework="4.5" />
    <httpRuntime targetFramework="4.5"/>
    </system.web>
    <system.serviceModel>
    <services>
    <service name="RestService.RestServiceImpl" behaviorConfiguration="ServiceBehaviour">
    <endpoint address="" binding="webHttpBinding" contract="RestService.IRestServiceImpl" behaviorConfiguration="web"></endpoint>
    </service>
    </services>
    <behaviors>
    <serviceBehaviors>
    <behavior name="ServiceBehaviour">
    <!-- To avoid disclosing metadata information, set the values below to false before deployment -->
    <serviceMetadata httpGetEnabled="true" httpsGetEnabled="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>
    <endpointBehaviors>
    <behavior name="web">
    <webHttp/>
    </behavior>
    </endpointBehaviors>
    </behaviors>
    <protocolMapping>
    <add binding="basicHttpsBinding" scheme="https" />
    </protocolMapping>
    <serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
    </system.serviceModel>
    <system.webServer>
    <modules runAllManagedModulesForAllRequests="true"/>
    <!--
    To browse web app root directory during debugging, set the value below to true.
    Set to false before deployment to avoid disclosing web app folder information.
    -->
    <directoryBrowse enabled="true"/>
    </system.webServer>

    </configuration>

    Working well when accessing through browser.But when I try to consume it through client/web application ,I am getting error.I unable to see any endpoint in client's webconfig file.When I am adding service reference ,it is showing 2 reference found.How 2?So again I deleted and entered new service reference ,that time I unchecked reused type in referenced asseblies" but no success.What to do now?
  • #768379
    Hi,

    Try copying the endpoint definitions from the config file (e.g. ServiceReferences.ClientConfig) of the class library to the config file of your application.

    Also go through this:
    http://keithelder.net/2008/01/17/exposing-a-wcf-service-with-multiple-bindings-and-endpoints/


Sign In to post your comments