从Asp.net MVC访问web服务 [英] Accessing Webservice from Asp.net MVC

查看:105
本文介绍了从Asp.net 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服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆