locked
Call asmx webservice redirects to my custom 404 error page! RRS feed

  • Question

  • User-79977429 posted

    Hi

    in my asmx file, i have a web method as follow :

    [WebService(Namespace = "http://tempuri.org/")]
        [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
        [System.ComponentModel.ToolboxItem(false)]
        // To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line. 
        [System.Web.Script.Services.ScriptService]
        public class SmartWebService : System.Web.Services.WebService
        {
    [WebMethod(enableSession: true)]        
            public string GetLastWeekVisits()
            {
                string strResult = string.Empty;
    
                DateTime dteCurDate = Utilities.DateInfo.GetCurrentServerDateTime(Singleton.StaticConnectionString);
                DateTime dte7DaysAgo = dteCurDate.AddDays(-7);
    
                string strMinDate = Utilities.DateInfo.GetPersianDate(dte7DaysAgo);
                string strMaxDate = Utilities.DateInfo.GetPersianDate(dteCurDate);
                DataTable dtData = HelperClass.GetVisitsByDates(strMinDate, strMaxDate);
                if (dtData != null)
                {
                    strResult = HelperClass.ConvertDataTableToJson(dtData);
                }
    
                return strResult;
            }
    }

    This works when i run from this url and click on my web method, then invoke it :

    http://localhost:9748/SmartWebService.asmx

    The above action redirect to this url & it works correctly :

    http://localhost:9748/SmartWebService.asmx/GetLastWeekVisits

    But when i copy/paste above url into new webBrowser tab page, i'm facing my custom error 404!

    I've also do a lot of search on the web & found some links such as this, but does not works for me!

    Can anybody help me where is the problem & how to solve it?

    Thanks in advance

    Saturday, June 27, 2020 8:03 AM

Answers

  • User-79977429 posted

    I found solution!

    You must add the following configuration in your web.config :

    <configuration>
      <system.web>
        <webServices>
          <protocols>
            <add name="HttpGet"/>
            <add name="HttpPost"/>
          </protocols>
        </webServices>
      </system.web>
    </configuration>

    Reference link.

    Best regards ...

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Sunday, June 28, 2020 11:48 AM

All replies

  • User1738843376 posted

    Hi hamed,

    My guess is that the URL your trying to reach directly on a new browser is of a temporary virtual server created by Visual Studio, so when you try to access it directly, via the temporary port, such virtual IIS application is non existant. 

    Try creating an application on your default website on your local IIS, place the service there, and then access it like http://localhost/myIISApplication/SmartWebService.asmx/GetLastWeekVisits where myIISApplication is whatever name you set on IIS.

    Sunday, June 28, 2020 12:19 AM
  • User-79977429 posted

    Sorry, but i don't think!

    Please take a look at this sample project.

    1. Open with vs 2019
    2. Run the project
    3. Go to this url : http://YourLocalHostAddress/Services.asmx/HelloWorld & see the result!
    Sunday, June 28, 2020 8:01 AM
  • User-79977429 posted

    I found solution!

    You must add the following configuration in your web.config :

    <configuration>
      <system.web>
        <webServices>
          <protocols>
            <add name="HttpGet"/>
            <add name="HttpPost"/>
          </protocols>
        </webServices>
      </system.web>
    </configuration>

    Reference link.

    Best regards ...

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Sunday, June 28, 2020 11:48 AM