如何将ASP.NET方法转换为ASP.NET .asmx Web服务 [英] How do I convert a ASP.NET method to ASP.NET .asmx web service

查看:65
本文介绍了如何将ASP.NET方法转换为ASP.NET .asmx Web服务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我有以下asp.net方法,我想将其转换为.asmx网络服务。我怎么能这样做请帮助。

Hi,
I have following asp.net method which I want to convert it into .asmx web service. How I can do that. Any help please.

public ActionResult AddCpty(string Id, string Type)
        {
            //code for Addcp
            return result;
        }





我的尝试:



我试图通过在方法的顶部放置一个[WebMethod]属性来转换它。



What I have tried:

I am trying to convert it by putting a [WebMethod] attribute on the top of the method.

[WebMethod]
public ActionResult AddCpty(string Id, string Type)
        {
            //code for Addcp
            return result;
        }

推荐答案

除非我完全遗漏了一些东西,否则你正在使用ASP.NET MVC。 MVC框架与.asmx不兼容,因为MVC路由将拦截.asmx请求。



澄清,
Unless I am missing something completely you are utilizing ASP.NET MVC. The MVC framework is not compatible with .asmx as MVC routing will intercept a .asmx request.

To clarify,
public ActionResult AddCpty

是如何在ASP.NET MVC框架中的MVC控制器中声明Action的。



基于你的问题,我建议你阅读更多关于你想要做什么/完成的内容,因为试图解释MVC路由的工作方式可能会增加混淆。



我的建议是放弃创建.ASMX Web服务的概念(除非你需要以这种方式创建它)并将Web API视为Web API将允许您更轻松地将MVC代码用于Web服务。



Web API - Google搜索 [ ^ ]



ASP.NET MVC到.ASMX [ ^ ]



ASP.NET MVC - Google搜索 [ ^ ]

is how you declare an Action within an MVC controller in the ASP.NET MVC Framework.

Based on your question, I would suggest you read more on what it is you are trying to do/accomplish as trying to explain how MVC routing works may add to the confusion.

My suggestion is to drop the notion of creating .ASMX web services (unless you have a need to create it in that manner) and look at Web API as Web API will allow you to more easily use MVC code for a web service.

Web API - Google Search[^]

ASP.NET MVC to .ASMX[^]

ASP.NET MVC - Google Search[^]


这篇关于如何将ASP.NET方法转换为ASP.NET .asmx Web服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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