Class Project and WCF Could not find default endpoint element - c#

I am adding a WCF client via “Add Service Reference” to the Class project with Visual Studio 2012. However I am getting the well known error:
Could not find default endpoint element that references contract ‘Service1.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.
The steps I followed was : (1) Create the Service1.cs and output.config via svcutil.exe, (2) Add service reference I am giving reference namespace as “MyFirstWcfWebServiceReference”. (3) add your existing Service1.cs file to the project. (4) in app.config Removed “MyFirstWcfWebServiceReference” and keep only IService1 in contract, (6) Build Project.
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
</configSections>
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="WCFServiceBinding" />
</basicHttpBinding>
</bindings>
<client>
<endpoint address="http://localhost/webiste/WebService.svc"
binding="basicHttpBinding" bindingConfiguration="WCFServiceBinding"
contract="IService1" name="WCFServiceBinding" />
</client>
</system.serviceModel>
</configuration>

Related

C# - How to set service reference configuration in a third party application

I am currently implementing a plugin for a third party application in C#. The plugin is a library (DLL) and it calls some Web services. So, I created a Service Reference in Visual Studio, which is configured in the app.config file of the plugin as such:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="AuthenticationEndpointImplServiceSoapBinding" />
</basicHttpBinding>
</bindings>
<client>
<endpoint address="http://localhost:8080/services/auth"
binding="basicHttpBinding" bindingConfiguration="AuthenticationEndpointImplServiceSoapBinding"
contract="AuthenticationWebService.AuthenticationEndpoint"
name="AuthenticationEndpointImplPort" />
</client>
</system.serviceModel>
</configuration>
I have another project, that I use for testing the plugin. When I call the service from that project, it works fine, provided I have copied the same configuration to this project's app.config file also. But when I build the plugin and run it from within the third party application, I get the following message:
Could not find default endpoint element that references contract
'AuthenticationWebService.AuthenticationEndpoint' 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 suspect the reason for the error is the fact that there is no configuration file for the third party application. Do you have any ideas how to work around this?
You could set up your parameters(binding, endpoint, etc.) explicitly in your plugin code after reading them from ordinary text file...
Here you will find some example:
https://msdn.microsoft.com/en-us/library/ms731862(v=vs.110).aspx

Could not find default endpoint element that references contract

I have a ASP .NET MVC app that I want to be able to connect to SOAP API.
I have created a wrapper project were I have my common methods that are working with the API. I have created this wrapper because the file generated by tool is so huge the project build would take ages.
From api doc site:
The tool then generates a single file named EconomicWebService.cs with the proxy code. This file can then be included directly in a project (this can slow down your Visual Studio as it is a rather big file) or built into a dll that can be referenced from your project)
I have referenced this wrapper as dll in my class library (middle layer) that is referenced into my MVC application.
Sadly it is not working, and I am getting this error:
Could not find default endpoint element that references contract 'S2s.Economic.WebService.EconomicWebServiceSoap' 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.
Webconfig
<system.web>
.....
</system.web>
<runtime>
...
</runtime>
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="EconomicWebServiceSoap">
<security mode="Transport" />
</binding>
<binding name="EconomicWebServiceSoap1" />
</basicHttpBinding>
</bindings>
<client>
<endpoint address="https://api.e-conomic.com/secure/api1/economicwebservice.asmx"
binding="basicHttpBinding" bindingConfiguration="EconomicWebServiceSoap"
contract="PTS.S2s.Economic.WebService.EconomicWebServiceSoap"
name="EconomicWebServiceSoap" />
</client>
</system.serviceModel>
</configuration>
I have managed to find a workarround with manual endpoint setup in the code.
EndpointAddress endpoint = new EndpointAddress( "https://api.e-conomic.com/secure/api1/economicwebservice.asmx" );

Cannot get Sharepoint 2010s Lists.asmx service to work

I'm trying to access Sharepoint 2010's Lists.asmx web service. I've created new console project in C#, added reference to a web service (http://[SITE]/_Vti_Bin/Lists.asmx) and it found the Lists web service all right. However, when I try to do
ListsService.Lists objLists = new ...
It says that Lists does not exist! In object viewer, I see all sorts of things in the ListsService namespace:
AddAttachmentRequest
AddAttachmentRequestBody
....
but I don't see Lists. However, every example I found online says that after I add a reference, I should have Lists in the namespace...
What am I doing wrong?
EDIT: app.config
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
</startup>
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="ListsSoap" />
</basicHttpBinding>
</bindings>
<client>
<endpoint address="http://SITE/_Vti_Bin/Lists.asmx"
binding="basicHttpBinding" bindingConfiguration="ListsSoap"
contract="ListsService.ListsSoap" name="ListsSoap" />
</client>
</system.serviceModel>
</configuration>
Make sure you are doing ListsService.Lists objLists = new ListsService.Lists() (not "new Lists()")
Make sure that the web service reference is setup correctly in the Settings.settings file and web.config/app.config file. Try removing the web service reference and re-adding it
The problem was that I have created "service" reference, not a "web service" reference. You have to click "Advanced" and then "Add Web Service reference" in order to add a web service refernce, otherwise it creates a WCF service reference that works differently.

Test a WCF service

This question must be newbie and i know it but i haven't found the answer for some time now. I have implemented a WCF service which i want to test. So when i click open in browser it opened something like
So i created the configuration file and the code file and i have input it into my solution in the same folder where the web service lies. When i have put the c# code mentioned above in a button of a web form this
EDIT: This is the output.config that i have mentioned above (i hope that is the client's config)
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="BasicHttpBinding_Icheck_for_quantity" />
</basicHttpBinding>
</bindings>
<client>
<endpoint address="http://localhost:51182/check_for_quantity.svc"
binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_Icheck_for_quantity"
contract="Icheck_for_quantity" name="BasicHttpBinding_Icheck_for_quantity" />
</client>
</system.serviceModel>
</configuration>
If i run wcftestservice the following appears:

Could not find default endpoint element that references contract... But application still works

I am currently working on a WPF Application, using a different project to call a WebService.
When I try to build i get this error:
Could not find default endpoint element that references contract
'VisitorRegistrationWebService.VisitorRegistrationWebServiceSoap' 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.
The app.config from my webservice project is just the same as the one from my WPF project.
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="VisitorRegistrationWebServiceSoap" />
</basicHttpBinding>
</bindings>
<client>
<endpoint address="http://localhost/webservices/VisitorRegistrationWebService.asmx"
binding="basicHttpBinding" bindingConfiguration="VisitorRegistrationWebServiceSoap"
contract="BasicVisitorRegistrationWebService.VisitorRegistrationWebServiceSoap"
name="VisitorRegistrationWebServiceSoap" />
</client>
</system.serviceModel>
</configuration>
The strange thing is that I can run the project and use the webservice to get data, but the error will not go away, no matter how many times I clean and rebuild my solution.
in error message, contract name is 'VisitorRegistrationWebService.VisitorRegistrationWebServiceSoap'
and in endPoint configuration, contract="BasicVisitorRegistrationWebService.VisitorRegistrationWebServiceSoap"

Categories