1

This is my Web.config in WCF service:

    <?xml version="1.0" encoding="utf-8"?>
<configuration>

  <system.web>
    <compilation debug="true" targetFramework="4.0" />
  </system.web>
  <system.serviceModel>
    <services>
      <service name="Mobile55.Service1">
        <endpoint address="../Service1.svc"
          binding="webHttpBinding"
          contract="Mobile55.IService1"
          behaviorConfiguration="webBehaviour" />
      </service>
    </services>
    <behaviors>
      <serviceBehaviors>
        <behavior>
          <serviceMetadata httpGetEnabled="true"/>
          <serviceDebug includeExceptionDetailInFaults="false"/>
        </behavior>
      </serviceBehaviors>
      <endpointBehaviors>
        <behavior name="webBehaviour">
          <webHttp/>
        </behavior>
      </endpointBehaviors>
    </behaviors>
    <serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
  </system.serviceModel>
 <system.webServer>
   <httpProtocol>
     <customHeaders>
       <add name="Access-Control-Allow-Origin" value="*" />
       <add name="Access-Control-Allow-Headers" value="Content-Type, Accept" />
     </customHeaders>
   </httpProtocol>
   <modules runAllManagedModulesForAllRequests="true"/>
    <directoryBrowse enabled="true"/>
  </system.webServer>

</configuration>

This is the first time I am working with WCF and I cannot add an endpoint for this service in my WinForms application.

I added this service as a reference and I can access the methods, but when I Debug and try to call a method it throws an exception:

Could not find default endpoint element that references contract 'MyService.IService1' 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.

My application app.config file is empty.

I tried the following answers, but didn't work for me:

Could not find default endpoint element

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

WCF Error - Could not find default endpoint element that references contract 'UserService.UserService'

How do I add an endpoint to finally be able to use my service?

Thanks in advance.

EDIT: My app.config file:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.serviceModel>
<services>
  <service name="Mobile55.Service1">
    <endpoint address=""
      binding="webHttpBinding"
      contract="Mobile55.IService1"
      behaviorConfiguration="webBehaviour" />
  </service>
</services>

<behaviors>
  <serviceBehaviors>
    <behavior name="webBehaviour">
      <serviceDebug includeExceptionDetailInFaults="true" />
    </behavior>
  </serviceBehaviors>
</behaviors>

<client>
  <endpoint address="http://localhost:1008/Service1.svc"
    binding="webHttpBinding"
    contract="Mobile55.IService1"
    behaviorConfiguration="webBehaviour" />
</client>
</system.serviceModel>  
</configuration>
Community
  • 1
  • 1
FireFalcon
  • 831
  • 11
  • 23

4 Answers4

0

Something like this should do the trick hopefully

  <service name="MyService.Service1">
    <endpoint address="YourEndPointHere"
      binding="webHttpBinding"
      contract="MyService.IService1"
      behaviorConfiguration="webBehaviour" />
  </service>
uTeisT
  • 2,256
  • 14
  • 26
0

You can try with this

 <service name="Mobile55.Service1">
        <endpoint address=""
          binding="webHttpBinding"
          contract="Mobile55.IService1"
          behaviorConfiguration="webBehaviour" />
      </service>

You can call your rest service with like this

localhost:port/Service1.svc/Pathname 

Here Pathname is which you mentioned in operationcontract of uritemplate.

Hope it helps!

Akhilesh
  • 171
  • 2
  • 20
0

Well, the error message specifically says in the client configuration section. So the error occurs client-side, i.e. from the code where you try to invoke on your service - more is hard to tell without a proper exception/stacktrace and a complete/compilable example that exhibits the behaviour.

Anyway, your configuration file is missing the client section completely.

Add something like this:

<system.serviceModel>
    <!-- ... other stuff you have ... -->
    <client>
        <endpoint address="../Service1.svc"
          binding="webHttpBinding"
          contract="Mobile55.IService1"
          behaviorConfiguration="webBehaviour" />
    </client>
</system.serviceModel>
Christian.K
  • 47,778
  • 10
  • 99
  • 143
  • thanks. But after adding this section now I am getting this: `There is no endpoint behavior named 'webBehaviour'` – FireFalcon Jul 19 '16 at 04:17
  • Did you really _add_ the `client` element to your `system.serviceModel` section, or did you replace the whole section with what I wrote? – Christian.K Jul 19 '16 at 04:27
  • I added my app.config content above. Can you take a look? – FireFalcon Jul 19 '16 at 04:43
  • That looks completely different than what you had initially?! You no longer have a value for the `address` attribute and the "webBehaviour" is something different. Please consider editing your question (again) so that it only reflects the current / wanted state of things, along with the current (full) error message, along with compilable code so that we can reproduce your issues. Until then, I give up. – Christian.K Jul 19 '16 at 04:46
  • in my question I posted `Web.config` file of my WCF service, but now I added `app.config` of my win application. `Web.config` file is still the same as before and the current error is `There is no endpoint behavior named 'webBehaviour'` when I try to connect. – FireFalcon Jul 19 '16 at 04:51
  • but did you mean to add client section in my `Web.config` or `app.config`? Thanks. – FireFalcon Jul 19 '16 at 05:12
  • To the "relevant" one. In case of doubt add the same (system.serviceModel) content to both and work from there. If your console application is only the "client", you can remove the "services"-element later on. – Christian.K Jul 19 '16 at 05:19
0
<system.serviceModel>
<client>
<endpoint address="http://localhost:1008/Service1.svc" 
binding="webHttpBinding"
bindingConfiguration="webHttpBinding_IService"  
contract="Mobile55.IService1"
name="webHttpBinding_IService" />
</client>
</system.serviceModel>


----------
## Heading ##


Try....