I have a problem when calling web Services in ASP.net MVC , I do the following
我在ASP.net MVC中调用Web服务时遇到问题,我执行以下操作
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
通过向解决方案添加服务引用来添加Web服务,并且我也将service.cs文件包含到解决方案中,但是当我尝试在home controller中创建对象时,我出现以下错误
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.
无法在ServiceModel客户端配置部分中找到引用合同“服务”的默认端点元素。这可能是因为没有为您的应用程序找到配置文件,或者因为在客户端元素中找不到与此合同匹配的端点元素。
can any one help me please
任何人都可以帮助我
thanks
谢谢
1 个解决方案
#1
1
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
.
这里有几件事情要发生。首先,您使用SVCUTIL为非WCF服务生成代理和配置设置 - .asmx是遗留的。我能够生成代理和配置设置,但要克服错误,您需要调用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.
原因是配置文件中定义了两个端点(一个用于SOAP 1.1,另一个用于SOAP 1.2),并且由于两个端点都已命名,因此没有可供选择的默认端点。
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.
当我使用var x = new WeatherHttpClient(new BasicHttpBinding(“WeatherSoap”),新的EndpointAddress(“http://wsf.cdyne.com/WeatherWS/Weather.asmx”));我能够很好地创建代理。
However, when I called GetCityForecastByZip
I got the following error:
但是,当我调用GetCityForecastByZip时,我收到以下错误:
Server did not recognize the value of HTTP Header SOAPAction: http://ws.cdyne.com/WeatherWS/WeatherHttpGet/GetCityForecastByZIPRequest.
服务器无法识别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):
然后,我使用WSDL.exe生成代理la .ASMX样式。我在我的项目中包含了这个,并且以下代码返回了一个结果(在包含对System.Web.Services的引用之后 - 我使用的是控制台应用程序):
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.
为简单起见,我建议使用WSDL.exe为您的服务生成代理,因为它似乎更简单。
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.
我还要补充一点,我做了很少的MVC,但我不认为这是一个MVC问题。我希望这可以帮助你。
#1
1
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
.
这里有几件事情要发生。首先,您使用SVCUTIL为非WCF服务生成代理和配置设置 - .asmx是遗留的。我能够生成代理和配置设置,但要克服错误,您需要调用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.
原因是配置文件中定义了两个端点(一个用于SOAP 1.1,另一个用于SOAP 1.2),并且由于两个端点都已命名,因此没有可供选择的默认端点。
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.
当我使用var x = new WeatherHttpClient(new BasicHttpBinding(“WeatherSoap”),新的EndpointAddress(“http://wsf.cdyne.com/WeatherWS/Weather.asmx”));我能够很好地创建代理。
However, when I called GetCityForecastByZip
I got the following error:
但是,当我调用GetCityForecastByZip时,我收到以下错误:
Server did not recognize the value of HTTP Header SOAPAction: http://ws.cdyne.com/WeatherWS/WeatherHttpGet/GetCityForecastByZIPRequest.
服务器无法识别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):
然后,我使用WSDL.exe生成代理la .ASMX样式。我在我的项目中包含了这个,并且以下代码返回了一个结果(在包含对System.Web.Services的引用之后 - 我使用的是控制台应用程序):
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.
为简单起见,我建议使用WSDL.exe为您的服务生成代理,因为它似乎更简单。
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.
我还要补充一点,我做了很少的MVC,但我不认为这是一个MVC问题。我希望这可以帮助你。