RProgrammer
RProgrammer

Reputation: 47

Could not find default endpoint element that references contract 'Service' error in consuming web Services in asp.net mvc

I have a problem when calling web Services in ASP.net MVC , I do the following

add the web service by add service reference to solution, and I include the service.cs file to the solution also, but when I try to create object in home controller , I have the following error

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

can any one help me please

thanks

Upvotes: 0

Views: 2007

Answers (1)

Tim
Tim

Reputation: 28530

There's a couple things going on here. First, you're using SVCUTIL to generate a proxy and configuration settings for a non-WCF service - .asmx is legacy. I was able to generate a proxy and config settings, but to overcome the error you got you need to call one of the overloaded versions of WeatherHttpClient.

I'm not 100% sure, but this is what I think based on what I observed.

The reason is because there are two endpoints defined in the configuration file (one for SOAP 1.1 and one for SOAP 1.2), and since both endpoints are named there is no default endpoint to choose from.

When I used var x = new WeatherHttpClient(new BasicHttpBinding("WeatherSoap"), new EndpointAddress("http://wsf.cdyne.com/WeatherWS/Weather.asmx")); I was able to create the proxy just fine.

However, when I called GetCityForecastByZip I got the following error:

Server did not recognize the value of HTTP Header SOAPAction: http://ws.cdyne.com/WeatherWS/WeatherHttpGet/GetCityForecastByZIPRequest.

So then I used WSDL.exe to generate the proxy a la .ASMX style. I included that in my project, and the following code returned a result (after including a reference to System.Web.Services - I was using a console app):

var x = new Weather();

ForecastReturn result = x.GetCityForecastByZip("91504");`

I would suggest for simplicity using WSDL.exe to generate the proxy for your service, as it seems to be simpler.

I will also add that I've done very little MVC, but I don't think this is an MVC issue. I hope this helps you.

Upvotes: 1

Related Questions