Click here to Skip to main content
15,887,485 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
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.
C#
public ActionResult AddCpty(string Id, string Type)
        {
            //code for Addcp
            return result;
        }


What I have tried:

I am trying to convert it by putting a [WebMethod] attribute on the top of the method.
C#
[WebMethod]
public ActionResult AddCpty(string Id, string Type)
        {
            //code for Addcp
            return result;
        }
Posted
Updated 5-Jan-17 5:07am
Comments
Where is the issue?
Afzaal Ahmad Zeeshan 5-Jan-17 13:32pm    
Instead of a web service, consider making it an API function, that is pretty much simple and doesn't require much other stuff.

Did you consider that?

1 solution

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,
C#
public ActionResult AddCpty
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[^]
 
Share this answer
 
v2
Comments
F-ES Sitecore 5-Jan-17 11:17am    
There is nothing in the OP that suggests he is using MVC? He mentions WebMethod and ASMX, both of which are WebForms technologies.
David_Wimbley 5-Jan-17 12:08pm    
He indicates in his code
public ActionResult AddCpty
, ActionResult being an MVC keyword so there is where my assumption comes from. Since he is using MVC code and trying to implement .ASMX, MVC's routing will intercept calls to .ASMX endpoints and special handling will need to be implemented to support .ASMX in MVC when in my opinion, you probably should either take the code out of MVC to implement .ASMX/WCF or implement it using Web API

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900