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


i know has been beaten death, cannot work should. have wcf service several contracts. work fine when calling them directly e.g. http://merlin.com/companyservices/companywcfservice.svc/get_document_dates_received/223278 have used wcf service on infopath forms , nintex workflows. create simple asp.net application, such done in http://www.webcodeexpert.com/2013/04/how-to-create-and-consume-wcf-services.html. able add service reference described in article. added button form, , added following code in button1_click event:

protected void button1_click(object sender, eventargs e) {     servicereference1.companywcfserviceclient x = new servicereference1.companywcfserviceclient();     var result = x.get_document_dates_received("223278"); } 

when click on button error:

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

so tried adding following web.config: (copied directly web.config file of companywcfservice.

<system.servicemodel> <services>   <service name="companywcfservices.companywcfservice" behaviorconfiguration="servicebehavior">     <endpoint address="" binding="webhttpbinding" contract="companywcfservices.icompanywcfservice" behaviorconfiguration="webhttpendpointbehavior" >       <identity>         <dns value="localhost"/>       </identity>     </endpoint>     <endpoint address="mex" binding="mexhttpbinding" contract="imetadataexchange">                                                                     </endpoint>   </service> </services> <bindings>   <webhttpbinding>     <binding>       <security mode="none">       </security>     </binding>   </webhttpbinding> </bindings> <behaviors>   <endpointbehaviors>     <behavior name ="webhttpendpointbehavior">       <webhttp helpenabled ="true" faultexceptionenabled="true" automaticformatselectionenabled="true"/>     </behavior>   </endpointbehaviors>   <servicebehaviors>     <behavior name="servicebehavior">       <servicemetadata httpgetenabled="true" />       <servicedebug includeexceptiondetailinfaults="true" />     </behavior>     <behavior name="">       <servicemetadata httpgetenabled="true" />       <servicedebug includeexceptiondetailinfaults="true" />     </behavior>   </servicebehaviors> </behaviors> <servicehostingenvironment multiplesitebindingsenabled="true"/>   </system.servicemodel> 

i same exact error, there has else going on.

i gave , called service this:

httpwebrequest request = webrequest.create(@"http://merlin/companyservices/companywcfservice.svc/get_document_dates_received/223278") httpwebrequest; request.credentials = credentialcache.defaultcredentials; httpwebresponse response = null;  var result = ""; try {     response = request.getresponse() httpwebresponse;     if (response.statuscode == httpstatuscode.ok)     {         using (stream stream = response.getresponsestream())         {             streamreader reader = new streamreader(stream, encoding.utf8);             result = reader.readtoend();         }     } } catch (exception ex) {     result = ""; } 

i have spent hours reading posts , of them suggest copy config information web.config file. seems problematic me (besides fact doesn't seem work). if need consume third party wcf service? have request config information third party? , visa versa, if create wcf service designed consumed third parties, need provide them config file well?

the error indicates don't have endpoint defined in client configuration section. when add service reference project should create client section you. if not in web.config app within system.servicemodel section add following

<client>   <endpoint        name="companywcfservice_webhttpbinding"       address="http://merlin.com/companyservices/companywcfservice.svc"        binding="webhttpbinding"        contract="companywcfservices.icompanywcfservice"        behaviorconfiguration="webhttpendpointbehavior"   /> </client> 

Comments

Popular posts from this blog

javascript - Count length of each class -

What design pattern is this code in Javascript? -

hadoop - Restrict secondarynamenode to be installed and run on any other node in the cluster -