locked
Web Service Fails After Deployment RRS feed

  • Question

  • User1231829591 posted

    Hi all, I have searched the web for a solution to my problem and thus far I've had no luck. My web service worked in development environment but once my project was deployed it stopped working. Prior to publishing my site, I made sure to change the path of the web service in my AJAX method to the correct path which is my domain name/asmx file/web method name. I get the error, 

    Failed to load resource: the server responded with a status of 500 (Internal Server Error) missing parameter: firstname

    Please help me resolve this problem, thanks in advance.

    Friday, October 2, 2015 7:25 AM

Answers

  • User281315223 posted

    What does the path that is being generated for your AJAX call look like? Based on the error message it states that you are explicitly missing a parameter called "firstname". You may want to make sure that this is present within the URL itself (i.e. "domain/Service/?firstname=value").

    Any other code that you have related to how you are generating this or calling it might be useful as well.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, October 2, 2015 8:48 AM
  • User475983607 posted

    The data property is not properly serialized.

    data: JSON.stringify(jdata),

    You're telling the server to expect XML but you're posting regular old form data.

    dataType: "xml",

    The web.config is looking for JSON.  Update the AJAX method as follows.

    dataType: "json",
    contentType: "application/json; charset=utf-8",

    I imagine you updated more than just he URL?  Please use the developer tools to verify HTTP message is what you expect.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, October 2, 2015 9:23 AM

All replies

  • User487807879 posted

    Post the AJAX script code you use for calling your web service.

    Friday, October 2, 2015 8:31 AM
  • User281315223 posted

    What does the path that is being generated for your AJAX call look like? Based on the error message it states that you are explicitly missing a parameter called "firstname". You may want to make sure that this is present within the URL itself (i.e. "domain/Service/?firstname=value").

    Any other code that you have related to how you are generating this or calling it might be useful as well.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, October 2, 2015 8:48 AM
  • User1231829591 posted

    Here is my web config file, please take a look to see if I am missing any thing important.

    <?xml version="1.0"?>
    
    <!--
      For more information on how to configure your ASP.NET application, please visit
      http://go.microsoft.com/fwlink/?LinkId=169433
      -->
    
    
    <configuration>
      <system.web>
        <compilation debug="true" targetFramework="4.5" />
        <httpRuntime targetFramework="4.5" />
    
        <webServices>
          <protocols>
            <add name="HttpSoap"/>
            <add name="HttpGet"/>
            <add name="HttpPost"/>
          </protocols>
        </webServices>
    
        <sessionState timeout="15"></sessionState>
      </system.web>
    
    
      <system.webServer>
        <defaultDocument>
          <files>
            <remove value="default.aspx" />
            <add value="default.aspx" />
          </files>
        </defaultDocument>
        <directoryBrowse enabled="false" />
    
        <staticContent>
          <mimeMap fileExtension=".json" mimeType="application/json" />
        </staticContent>
    
        <validation validateIntegratedModeConfiguration="false"/>
        <modules runAllManagedModulesForAllRequests="true"/>
        <handlers>
          <add verb="*" path="*.asmx" name="asmx" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
        </handlers>
        
      </system.webServer>
    
      <connectionStrings>
        <add name="Register"
          connectionString="Data Source=my-PC\SQLEXPRESS2012;Initial Catalog=StudentsDB;Integrated Security=True"  providerName="System.Data.SqlClient"/>
      </connectionStrings>
    
      <system.net>
        <mailSettings>
          <smtp deliveryMethod="Network" from="me@gmail.com">
            <network host="smtp.gmail.com" enableSsl="true" port="587" userName="me@gmail.com" password="password"/>
          </smtp>
        </mailSettings>
      </system.net>
    </configuration>
    

    Friday, October 2, 2015 9:05 AM
  • User1231829591 posted

    Hi all the following is my AJAX

     function StudentIsUnique(callback) {            
                var jdata = {firstname: u_fname , lastname: u_lname , email: u_email };
                $.ajax({
                   
                    url: "http://www.mywebsite.com/StudentService.asmx/CheckStudentIsUnique",
                   
                    data:jdata,
                    method: "post",                
                    dataType: "xml",
                    success: function (data) {
                        var response = $(data);
                        if (response.find('string').text() === "false") {
                            alert("A student by this name already exists.");
                        } else
                            // 'string' is the name of the xml element inside of the web service 
                            if (response.find('string').text() === "true") {
                                callback();                            
                            }  
                    }
                });
            }

    I am wondering if the server is correctly configured or if my config file is correct.

    Friday, October 2, 2015 9:06 AM
  • User475983607 posted

    The data property is not properly serialized.

    data: JSON.stringify(jdata),

    You're telling the server to expect XML but you're posting regular old form data.

    dataType: "xml",

    The web.config is looking for JSON.  Update the AJAX method as follows.

    dataType: "json",
    contentType: "application/json; charset=utf-8",

    I imagine you updated more than just he URL?  Please use the developer tools to verify HTTP message is what you expect.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, October 2, 2015 9:23 AM
  • User1231829591 posted

    Hi, thanks for replying, if I don't want to use json because I don't want to rewrite many of my methods what should I put in the <staticContent> element of the webconfig file.

    Friday, October 2, 2015 9:29 AM
  • User475983607 posted

    Gotcha, my bad for not paying attention.

    Web method arguments are case sensitive.  Make sure the firstname args match.

    Friday, October 2, 2015 9:38 AM
  • User1231829591 posted

    Hi, my arguments do match so that is probably not the cause of the problem.

    I added the json data type from <to the AJAX call  but it doesn't appear to do any thing.

    Friday, October 2, 2015 10:08 AM