wcf - Could not find default endpoint element that references contract 'SumServiceReference.IService1' in the ServiceModel client configuration section -


i want call service both code behind & ajax. able call client script using ajax getting exception, while calling code behind.

here sample code, it's simple sum operation demo purpose.

service contract:

using system.servicemodel; using system.servicemodel.web;  namespace sum_wcfservice { [servicecontract] public interface iservice1 {     [operationcontract]     [webinvoke(method = "post", responseformat = webmessageformat.json)]     int addnums(int num1, int num2); } } 

service implementation:

using system.servicemodel.activation;  namespace sum_wcfservice { [aspnetcompatibilityrequirements(requirementsmode = aspnetcompatibilityrequirementsmode.allowed)] public class service1 : iservice1 {     public int addnums(int num1, int num2)     {         return num1 + num2;     } } } 

added client app in same solution consume service , added service reference name "sumservicereference"

client application:

using system; using system.globalization; using sum_wcfservice.sumservicereference;  namespace sum_wcfservice { public partial class addserviceclient : system.web.ui.page {     protected void page_load(object sender, eventargs e)     {      }      protected void getsum(object sender, eventargs e)     {         var serviceproxy = new service1client();         int num1,num2;         int.tryparse(txtnum1.value, out num1);         int.tryparse(txtnum1.value, out num2);         var sum = serviceproxy.addnums(num1, num2);         txtresult.value = sum.tostring(cultureinfo.invariantculture);     } } } 

and config file is:

<?xml version="1.0"?> <configuration>  <system.web> <compilation debug="true" targetframework="4.0"/> </system.web>  <system.servicemodel> <servicehostingenvironment multiplesitebindingsenabled="true" /> <behaviors>   <servicebehaviors>     <behavior name ="sumservicebehavior">       <servicemetadata httpgetenabled="true"/>       <servicedebug includeexceptiondetailinfaults="true"/>     </behavior>   </servicebehaviors>    <endpointbehaviors>     <behavior name="endpointbehavior">       <enablewebscript />     </behavior>   </endpointbehaviors> </behaviors>  <services>   <service name="sum_wcfservice.service1" behaviorconfiguration="sumservicebehavior">     <endpoint address="" binding="webhttpbinding" contract="sum_wcfservice.iservice1"       behaviorconfiguration="endpointbehavior" />   </service> </services>  <client>   <endpoint address="http://localhost/sum_wcf/service1.svc"    binding="basichttpbinding" bindingconfiguration="basichttpbinding_iservice1"    contract="sum_wcfservice.sumservicereference.iservice1" name="basichttpbinding_iservice1" /> </client>  <bindings>   <basichttpbinding>     <binding name="basichttpbinding_iservice1" closetimeout="00:01:00" opentimeout="00:01:00"               receivetimeout="00:10:00" sendtimeout="00:01:00" allowcookies="false"               bypassproxyonlocal="false" hostnamecomparisonmode="strongwildcard"               maxbufferpoolsize="524288" maxbuffersize="65536" maxreceivedmessagesize="65536"               textencoding="utf-8" transfermode="buffered" usedefaultwebproxy="true"               messageencoding="text">       <readerquotas maxdepth="32" maxstringcontentlength="8192" maxarraylength="16384"        maxbytesperread="4096" maxnametablecharcount="16384" />     </binding>    </basichttpbinding> </bindings> </system.servicemodel>  <system.webserver> <modules runallmanagedmodulesforallrequests="true"/> <directorybrowse enabled="true"/> </system.webserver>  </configuration> 

and error getting

could not find default endpoint element references contract    'sumservicereference.iservice1' in servicemodel client configuration section.  might because no configuration file found application, or because no endpoint element matching contract found in client element. 

change service element as:

<service name="sum_wcfservice.service1" behaviorconfiguration="sumservicebehavior">     <endpoint address="" binding="webhttpbinding" contract="sum_wcfservice.iservice1" behaviorconfiguration="endpointbehavior" />     <endpoint address="mex" binding="mexhttpbinding" contract="imetadataexchange"/>   </service> </services> 

and client element as:

<client> <endpoint address="http://localhost/sum_wcf/service1.svc" binding="webhttpbinding" behaviorconfiguration="endpointbehavior" contract="sumservicereference.iservice1" name="webhttpbinding_sum" /> </client> 

Comments

Popular posts from this blog

javascript - Jquery show_hide, what to add in order to make the page scroll to the bottom of the hidden field once button is clicked -

javascript - Highcharts multi-color line -

javascript - Enter key does not work in search box -