调用webservice时,服务器响应状态为500(内部服务器错误)

时间:2013-07-11 15:31:20

标签: asp.net vb.net web-services dojo

我对网络应用程序没有多少经验,就在我认为工作有问题的时候。我在C#中在线学习了一个演示,然后创建了我自己的简单版本,似乎工作正常。它只需要一些输入并将其传递给Web服务。 然后我尝试在更复杂的应用程序中实现类似的Web服务,并且我得到以下错误,但没有明确说明它为什么不起作用:

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

这是在浏览器调试器中,并没有说明原因。

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

我的网络服务代码如下:

<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

以及调用它的javascript:

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.";
        });
    })
});

2 个答案:

答案 0 :(得分:1)

您的服务可以通过一些异常处理来捕获错误并将其写入事件日志(或其他内容),以便您可以看到正在发生的事情。或者,通过Visual Studio在调试模式下运行它并发出测试 - 它应该在断点处捕获并允许您逐步查看问题所在。

答案 1 :(得分:1)

我弄清楚问题是什么,它与xhr函数有关。 基本上传递的参数必须与后面代码中的名称和数字相匹配。