the server responded with a status of 500 (Internal Server Error) when calling webservice

做~自己de王妃 提交于 2019-12-11 01:57:00

问题


I do not have much experience with web applications and just when I thought I have it working something is going wrong. I studied a demo online in C# and then created my own simple version which seems to work fine. All it does is take some input and pass it to the webservice. I then tried implementing a similar webservice in a more complex application and I get the following error with no clear indication as to why it does not work:

the server responded with a status of 500 (Internal Server Error) 

This is within the browser debugger and it does not clarify why.

webservice url :hostlocal:xxxxx/SVC/contact.asmx/ContactMessage

my webservice code as follows:

<System.Web.Services.WebService(Namespace:="http://tempuri.org/")> _
<System.Web.Services.WebServiceBinding(ConformsTo:=WsiProfiles.BasicProfile1_1)> _
 <ToolboxItem(False)> _
Public Class contact
Inherits System.Web.Services.WebService

<WebMethod()> _
Public Function ContactMessage(ByVal clientProj As String, email As String, message As String) As String


    Dim insert_succes As Integer = load_data("", clientProj, "", "", "", "", "", "", "", "", email, message, "")
    Dim passedValidation As Boolean = True

    ' here you can return a flag which you can handle on client side accordingly
    ' if you need to

    Return If(passedValidation, "1", "0")

End Function

and the javascript that calls it:

var dojoXhr;

 require(["dojo/parser", "dojo/query", "dojo/dom-class", "dojo/dom-style", 
    "dojo/on", "dojo/_base/event",
"dojo/request/xhr", "dijit/form/ValidationTextBox", "dojo/domReady!"],
function (parser, query, domClass, domStyle, on, event, xhr) {

    parser.parse();

    var btnSubmit = document.getElementById('btnSubmit');

    function correctInput(div, td, msg) {
        domStyle.set(div, 'display', '');
        td.innerHTML = msg;
    }

    on(btnSubmit, 'click', function (e) {
        event.stop(e);
        var clientProj = dijit.byId("clientName").get("value");
        var clientKey = dijit.byId("clientKey").get("value");
        var accessToken = dijit.byId("accessToken").get("value");
        var lusername = dijit.byId("lusername").get("value");
        var lpassword = dijit.byId("lpassword").get("value");
        var provid = dijit.byId("provID").get("value");




        var feedback = document.getElementById('feedback');
        var feedbackTD = query('td.feedback')[0];

        domStyle.set(feedback, 'display', 'none');

        if (!validateEmail(lusername)) {
            correctInput(feedback, feedbackTD, 'Please enter a valid email.');
            return;
        }

        var port = document.location.port;
        var xhrPath = '//' + document.location.hostname + (port == (80 || 443) ? '/' : ':' + port + '/') + 'SVC/contact.asmx/ContactMessage';

        var msgbody = {
            clientProj: clientProj,
            clientKey: clientKey,
            accessToken: accessToken,
            lusername: lusername,
            lpassword: lpassword,
            provid: provid
        };

        xhr(xhrPath, {
            headers: { "Content-Type": "application/json; charset=utf-8" },
            method: 'post',
            data: JSON.stringify(msgbody)
        }).then(function (data) {
            if (data == "0") {
                correctInput(feedback, feedbackTD, 'Your message could not be sent.');
                return;
            }
            alert('Bcrap STILL NOT WORKING NOW!');
            // show feedback to the user
            domStyle.set(feedback, 'display', '');
            domStyle.set(document.getElementById('msgBodyOutter'), 'display', 'none');
            feedbackTD.innerHTML = "Message was sent successfully.";
        });
    })
});

回答1:


Your service could do with some exception handling to trap an error and write it to the event log (or something) so you can see what's going on. Alternatively, run it in Debug Mode through Visual Studio and issue your test -- it should catch at the breakpoint and allow you to step through to see what the problem is.




回答2:


I figured out what the problem was and it was related to the xhr function. Basically the parameters passed has to match in name and number in the code behind.



来源:https://stackoverflow.com/questions/17597571/the-server-responded-with-a-status-of-500-internal-server-error-when-calling-w

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!