Click here to Skip to main content
15,899,935 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
How can I call a wen method from controller
Here is my code.
C#
[WebMethod]
      public IEnumerable<CitySearchResult>  SearchFromHomeBus(int fromid, int toid)
      {
         // DbDataReader sqlreader;
          SqlParameter []para=new SqlParameter[2];
          para[0]=new SqlParameter("@city1",fromid);
          para[1]=new SqlParameter("@city2",toid);
          using (cab_4_21Entities1 d = new cab_4_21Entities1())

          {
              ObjectResult<CitySearchResult> search =d.ExecuteStoreQuery<CitySearchResult>("usp_SearchcabResult @city1, @city2", para);
              //List<CitySearchResult> search = (d.ExecuteStoreQuery<CitySearchResult>("usp_SearchcabResult", para)).ToList<CitySearchResult>();
              List<CitySearchResult> searchResult=search.ToList<CitySearchResult>();

              return searchResult;
          }
      }

Please suggest me.
Posted
Comments
Sinisa Hajnal 8-Apr-15 2:10am    
If it is in the same project, you just call it as normal method. The fact that it is marked as web method only means it is accessible from ajax calls, otherwise it behaves much as any method would.

1 solution

If you are hosting the web service as a separate endpoint (outside the consuming MVC app), then you need to provide the WebGet or WebInvoke attributes on the operation contracts (assuming its WCF) or the current WebMethod as you have put it.

Then add a ServiceReference (if WCF) or WebReference (if ASMX) by browsing to the service. VS will create corresponding proxies and give you an object through which you can make the calls.

However, if the service is meant to be consumed by only ONE application, then its not a service by definition; its just a class library doing a given function. In such a case, it should be just taken in like that with the usual library reference and consumed.
 
Share this answer
 

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