Could not find default endpoint element that references contract - Hosting wcf

46,883

Solution 1

Copy system.serviceModel section from the app.config in your library project and put it in your web.config and refresh service reference. See also this answer. Could not find default endpoint element

Solution 2

Add "WSHttpBinding" end point in your WCF service web.config file like below

 <endpoint address="web" behaviorConfiguration="jsonBehavior" binding="webHttpBinding" bindingConfiguration="webHttpBindingWithJsonP" contract="DataService.IDataService"/>
 <endpoint address="" binding="wsHttpBinding" bindingConfiguration="wsHttpBinding" contract="DataService.IDataService"  />

and in your app.config file write code like below

<system.serviceModel>
<bindings>
  <wsHttpBinding>
    <binding name="WSHttpBinding_IDataService" maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647">
      <security mode="None" />
    </binding>
  </wsHttpBinding>
</bindings>
<client>
  <endpoint address="http://localhost/pricedataservice/DataService.svc" binding="wsHttpBinding"
      bindingConfiguration="WSHttpBinding_IDataService" contract="DataService.IDataService"
      name="WSHttpBinding_IDataService" />
</client>

I am sure this will fix your problem and below blog will help you to understand different type of binding in WCF service

http://www.dotnet-tricks.com/Tutorial/wcf/VE8a200713-Understanding-various-types-of-WCF-bindings.html

Solution 3

Add client definition in your client web.config file like below;

 <system.serviceModel>
  /////
 <client>
         <endpoint  address="referencedurl"
          binding="webHttpBinding" bindingConfiguration=""
          contract="MemberService.IMemberService"
          name="MemberServiceEndPoint"
          behaviorConfiguration="Web">
      </endpoint>
 </client> 
////
 </system.serviceModel>

AND Service Reference Name must same as the Interfaces prefix. contract="ReferenceName.IMemberService"

Share:
46,883
Jackie Ngo Anh Khoi
Author by

Jackie Ngo Anh Khoi

Updated on September 06, 2020

Comments

  • Jackie Ngo Anh Khoi
    Jackie Ngo Anh Khoi over 3 years

    I have one wcf service on this site http://wswob.somee.com/wobservice.svc

    I try to consume that service with my winform app. This is the error I receive when I create an instant of the service

    com.somee.wobservice.IwobserviceClient myservice = new com.somee.wobservice.IwobserviceClient();
    

    error:

    Could not find default endpoint element that references contract
    'com.somee.wobservice.Iwobservice' 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.
    

    I searched and modified my app.config file:

    <system.serviceModel>
    <behaviors>
      <endpointBehaviors>
        <behavior name="wobservice">
          <clientVia />
        </behavior>
      </endpointBehaviors>
    </behaviors>
    
    <client>
      <endpoint
          name="wobservice"
          address="http://wswob.somee.com/wobservice.svc"
          binding="webHttpBinding"
          contract="com.somee.wobservice"
          behaviorConfiguration="wobservice" />
    </client>
    
    </system.serviceModel>
    </configuration>
    

    And my web.config in wcf folder:

    <system.serviceModel>
        <behaviors>
          <serviceBehaviors>
            <behavior>
              <serviceMetadata httpGetEnabled="true"/>
    
              <serviceDebug includeExceptionDetailInFaults="false"/>
            </behavior>
          </serviceBehaviors>
    
            <endpointBehaviors>
                <behavior name="Web">
                    <webHttp/>
                </behavior>
            </endpointBehaviors>
        </behaviors>
    
          <serviceHostingEnvironment  multipleSiteBindingsEnabled="true">
              <baseAddressPrefixFilters>
                  <add prefix="http://wswob.somee.com/"/>
              </baseAddressPrefixFilters>
          </serviceHostingEnvironment>
    
          <bindings>
              <webHttpBinding>
                  <binding>
                      <security mode="None" />
                  </binding>
              </webHttpBinding>
          </bindings>
    
          <protocolMapping>
               <add binding="basicHttpsBinding" scheme="https"/>
               <add binding="basicHttpBinding" scheme="http"/>
          </protocolMapping>
    
          <services>
               <service name="wobwcf.wobservice">
                  <endpoint address="" 
                            binding="webHttpBinding" 
                            behaviorConfiguration="Web" 
                            contract="wobwcf.Iwobservice" />
               </service>
          </services>
       </system.serviceModel>
    

    I don't really sure which part I got wrong. My experience of wcf is just a week...

  • Jackie Ngo Anh Khoi
    Jackie Ngo Anh Khoi almost 10 years
    When I set address="wswob.somee.com" or "wswob.somee.com/wobservice.svc", the service didn't work...
  • Jackie Ngo Anh Khoi
    Jackie Ngo Anh Khoi almost 10 years
    Finally I got it!!! I set binding and then client. The contract should be like this: contract="com.somee.wobservice.Iwobservice"
  • Jackie Ngo Anh Khoi
    Jackie Ngo Anh Khoi almost 10 years
    Yeah, that is what exactly what I did, but I didn't use JSON though... Thanks a lot
  • Rachit Patel
    Rachit Patel almost 10 years
    It's not related to JSON but you have not added "wsHttpBinding" end point in your WCF service web.config file and that's why your are facing error.