从Asp.net MVC访问web服务

编程入门 行业动态 更新时间:2024-10-25 04:27:05
本文介绍了从Asp MVC访问web服务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我有一个 MVC2 应用还包括非MVC部分(常规Asp.net 3.5页)。

I have a MVC2 App which also includes a Non MVC part (regular Asp.Net 3.5 pages).

我是从非MVC的页面调用Web服务(不WCF)来填充自动完成。

I am calling webservice (Not WCF) from Non MVC pages to populate autocompletes.

这两个MVC件和非标准件MVC在我的机器的开发工作正常。

Both MVC parts and Non-MVC parts work fine in my developers machine.

当我在IIS托管我的申请,我不能访问的webMethods在我的web服务。我用萤火检查其返回

When i host my application in IIS, i cant access the webmethods in my webservice. I checked with firebug it returns

The controller for path '/payroll/WS/MVCArch.asmx/JqUiGetEmp' was not found or does not implement IController. '

下面我的虚拟目录名称为工资。我不MVC页位于一个名为RepDocs文件夹,它是应用程序的根目录下下。我的web文件夹WS也是应用程序的根目录下。该请求是由非MVC页下的RepDocs文件夹发送。

Here my virtual directory name is Payroll. and my Non MVC pages are located under a folder called "RepDocs" which is under the root of the application. My Webservice folder "WS" is also under the root of the application. The request was sent from a non mvc page under "RepDocs" folder.

怎么进来 VSHOST 同一code ++工程,而不是在 IIS(XP SP3)?我这么想吗?

How come the same code works in VSHOST and not in IIS (XP sp3) ? am i missing something ?

请帮忙。

修改

我修改我的Global.asax排除路线如下

I have modified my global.asax to exclude routes as follow

routes.IgnoreRoute("{resource}.axd/{*pathInfo}"); routes.IgnoreRoute("favicon.ico"); routes.IgnoreRoute("WS/{resource}.asmx/{*pathInfo}"); //routes.IgnoreRoute("{*allasmx}", new { allasmx = @".*\.asmx(/.*)?" }); routes.MapRoute( "Default", // Route name "{controller}/{action}/{id}", // URL with parameters new { controller = "Home", action = "Index", id = UrlParameter.Optional } // Parameter defaults );

现在我得到这个错误

The HTTP verb POST used to access path '/Payroll/ws/MVCArch.asmx/JqUiGetOffice' is not allowed.

我添加了以下到Web.config

I added the following to the Web.config

<webServices> <protocols> <add name="HttpGet"/> <add name="HttpPost"/> </protocols> </webServices>

仍然没有运气。

推荐答案

您必须忽略在Global.asax.cs中

You have to ignore the route to the web service in Global.asax.cs

routes.IgnoreRoute("{*allasmx}", new {allasmx=@".*\.asmx(/.*)?"});

更多推荐

从Asp.net MVC访问web服务

本文发布于:2023-11-08 14:18:07,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1569609.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:net   Asp   web   MVC

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!