none
Unhandled Exception: System.InvalidOperationException: Could not find default endpoint element that references contract 'Iservice' in the ServiceModel client configuration section. This might be because no configuration file was found for your application RRS feed

  • Question

  • I have a minimal JSON REST service that seems to work with the browsers (IE, Chrome, Firefox) and Cygwin/curl.

    I use this statement as per the instructions resulting from "iexplore http://localhost/SimpleJSONREST/service.svc"

    svcutil.exe http://localhost/SimpleJSONREST/service.svc?wsdl


    I compile it with the instructions from IE (in the above page):

    csc /t:library /out:SimpleJSONREST.dll SimpleJSONREST.cs 
    


    I created a simple client as per the instructions:

     public static void Main(string[] args){
        var client = new IserviceClient();
        Console.WriteLine(client.JSONData("abc"));
        client.Close();
     }
    

    Instead of calling close, can I use a "using" statement?

    I'm getting this error (note the line numbers are different because I deleted a lot of comments):

    Unhandled Exception: System.InvalidOperationException: Could not find default endpoint element that references contract 'Iservice' in the ServiceModel client configuration section. This might be because no configuration file was found for your application, or because no endpoint element matching this contract could be found in the client element.
       at System.ServiceModel.Description.ConfigLoader.LoadChannelBehaviors(ServiceEndpoint serviceEndpoint, String configurationName)
       at System.ServiceModel.ChannelFactory.InitializeEndpoint(String configurationName, EndpointAddress address)
       at System.ServiceModel.ChannelFactory`1..ctor(String endpointConfigurationName, EndpointAddress remoteAddress)
       at System.ServiceModel.ConfigurationEndpointTrait`1.CreateSimplexFactory()
       at System.ServiceModel.ClientBase`1.CreateChannelFactoryRef(EndpointTrait`1 endpointTrait)
       at System.ServiceModel.ClientBase`1.InitializeChannelFactoryRef()
       at client.Main(String[] args) in c:\Users\siegfried\Documents\WinOOP\WCF\clients\SimpleJSONREST\client.cs:line 47
    terminating client.cs
    Process compilation finished


    Here is my Service.svc file:

    <%@ ServiceHost Language="C#" Debug="true" Service="RestService.service"  %>
    
    using System.ServiceModel;
    using System.ServiceModel.Web;
    
    namespace RestService {
        [ServiceContract]
        public interface Iservice {
            [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);
        }
        public class service : Iservice {
            public string XMLData(string id) { return "You requested product " + id; }
            public string JSONData(string id) { return "You requested product " + id; }
        }
    }
    

    Here is my web.config

    <?xml version="1.0"?>
    <configuration>
      <system.web>
        <compilation debug="true" targetFramework="4.0" />
      </system.web>
      <system.serviceModel>
        <services>
          <service name="RestService.service" behaviorConfiguration="ServiceBehaviour">
            <!-- Service Endpoints -->
            <!-- Unless fully qualified, address is relative to base address supplied above -->
            <endpoint address ="" binding="webHttpBinding" contract="RestService.Iservice" behaviorConfiguration="web">
            </endpoint>
            <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
          </service>
        </services>
    
        <behaviors>
          <serviceBehaviors>
            <behavior name="ServiceBehaviour">
              <!-- 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="true"/>
            </behavior>
          </serviceBehaviors>
          <endpointBehaviors>
            <behavior name="web">
              <webHttp/>
            </behavior>
          </endpointBehaviors>
        </behaviors>
        <serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
      </system.serviceModel>
      <system.webServer>
        <modules runAllManagedModulesForAllRequests="true"/>
      </system.webServer>
    </configuration>
    

    Pease help me make this client work. Thanks!

    Siegfried


    siegfried heintze

    Monday, June 2, 2014 4:26 PM

Answers