Blog coding and discussion of coding about JavaScript, PHP, CGI, general web building etc.

Friday, January 29, 2016

Could not find default endpoint element that references contract

Could not find default endpoint element that references contract


I know this has been beaten to death, but I cannot get this to work as it should. I have a WCF service with several contracts. They all work fine when calling them directly e.g. http://merlin.com/CompanyServices/CompanyWcfService.svc/Get_Document_Dates_Received/223278 I have used this WCF service successfully on InfoPath Forms and Nintex Workflows. Now I create a simple ASP.Net application, such as was done in http://www.webcodeexpert.com/2013/04/how-to-create-and-consume-wcf-services.html. I was able to add a service reference as described in the article. I added a button the form, and added the following code in the 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 I click on the button I get the error:

"Could not find default endpoint element that references contract 'ServiceReference1.ICompanyWcfService' 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."

So I tried adding the following to the web.config: (copied directly from the web.config file of the CompanyWcfService.

                                                                                                                                                                                                                                                                              

I get the same exact error, there has to be something else going on.

I finally gave up and called the service like this:

HttpWebRequest request = WebRequest.Create(@"http://merlin/Companyservices/CompanyWcfService.svc/Get_Document_Dates_Received/223278") as HttpWebRequest;  request.Credentials = CredentialCache.DefaultCredentials;  HttpWebResponse response = null;    var result = "";  try  {      response = request.GetResponse() as 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 and most of them suggest to copy the config information to the web.config file. This seems problematic to me (besides the fact that it doesn't seem to work). What if I need to consume a third party WCF service? Do I have to request the config information from the third party? And Visa Versa, if I create a WCF service designed to be consumed by third parties, do I need to provide them the config file as well?

Answer by Matt Klepeis for Could not find default endpoint element that references contract


The error indicates that you don't have an endpoint defined in the client configuration section. When you add the service reference to your project it should create the client section for you. If not then in the web.config for your app within the system.serviceModel section add the following

        

Answer by Anand for Could not find default endpoint element that references contract


If we have layered architecture make sure to 1) add app.config in "all projects" 2) Add service config details in all app.config 3) run the project

Answer by user1337493 for Could not find default endpoint element that references contract


Actually the trick to this one was to use the svcutil.exe to create the proxy. I had been trying to create the proxy through Visual Studio "Add Service" wizard. Once I did that, the configuration was a breeze.

SvcUtil.exe

Answer by AbbasFaisal for Could not find default endpoint element that references contract


If your project is referencing a library and trying to use the WCF functions from the functions of that library, then you can try copying the client endpoint from the project config file to the dll's config file. Some thing like this happened to me a while ago as the library that I referenced in the project would not use the project config file (in which the client end point was configured since the service was being referenced there) but its own so the result was the system could not find the endpoint configurations.

Answer by user1501363 for Could not find default endpoint element that references contract


Adding binding and client values from app.config to default web.config resolved my issue.

Answer by Aleksandr Albert for Could not find default endpoint element that references contract


In my case I had a WPF project referencing an external UserControl which had a service reference. I had to add the service reference to the main project as well.


Fatal error: Call to a member function getElementsByTagName() on a non-object in D:\XAMPP INSTALLASTION\xampp\htdocs\endunpratama9i\www-stackoverflow-info-proses.php on line 72

0 comments:

Post a Comment

Popular Posts

Powered by Blogger.