服务器调用webservice时与500(内部服务器错误)的状态回应 [英] the server responded with a status of 500 (Internal Server Error) when calling webservice
问题描述
我没有与网络应用程序太多的经验,只是在我以为我有工作事情错了。我在C#中研究了在线演示,然后创建了自己的简单的版本,这似乎很好地工作。它所做的就是采取一些输入,并将其传递给web服务。
然后,我尝试在更复杂的应用程序中实现类似的web服务,我去没有明确的指示以下错误,为什么它不工作:
服务器500(内部服务器错误)的状态回应
这是浏览器调试器中,并没有明确的原因。
web服务网址:hostlocal:XXXXX / SVC / contact.asmx / ContactMessage
我的web code如下:
< System.Web.Services.WebService(命名空间:=http://tempuri.org/)> _
< System.Web.Services.WebServiceBinding(ConformsTo:= WsiProfiles.BasicProfile1_1)GT; _
<的ToolboxItem(假)> _
公共类接触
继承System.Web.Services.WebService&所述;的WebMethod()> _
公共职能ContactMessage(BYVAL clientProj作为字符串,电子邮件作为字符串,消息作为字符串)作为字符串
昏暗insert_succes为整数= load_data(,clientProj,,,,,,,,,电子邮件,消息,)
昏暗passedValidation由于布尔= TRUE 在这里你可以回到你可以在客户端相应的处理标志
如果你需要 返回值如果(passedValidation,1,0)结束功能
和调用它的JavaScript:
VAR dojoXhr; 需要([道场/分析器,道场/查询,道场/ DOM级,道场/ DOM式,
道场/上,道场/ _base /事件
道场/请求/ XHR,的dijit /表格/ ValidationTextBox,道场/ domready中!]
功能(分析器,查询,domClass,domStyle,上,事件,XHR){ parser.parse(); 变种btnSubmit按钮=的document.getElementById('btnSubmit按钮'); 功能correctInput(DIV,TD,味精){
domStyle.set(DIV,'显示','');
td.innerHTML =味精;
} 上(btnSubmit按钮,'点击',功能(E){
event.stop(E);
VAR clientProj = dijit.byId(CLIENTNAME)获得(值)。
。VAR clientKey = dijit.byId(clientKey)获得(值);
VAR的accessToken = dijit.byId(的accessToken)获得(值)。
。VAR lusername = dijit.byId(lusername)获得(值);
。VAR lpassword = dijit.byId(lpassword)获得(值);
VAR provid = dijit.byId(它提供)获得(值)。
VAR反馈=的document.getElementById('反馈');
变种feedbackTD =查询('td.feedback')[0]; domStyle.set(反馈,'显示','无'); 如果(!validateEmail(lusername)){
correctInput(反馈,feedbackTD,'请输入一个有效的电子邮件。');
返回;
} VAR端口= document.location.port;
VAR xhrPath ='//'+ document.location.hostname +(端口==(80 || 443)'/':':'+端口+'/'?)+'SVC / contact.asmx / ContactMessage'; VAR msgbody = {
clientProj:clientProj,
clientKey:clientKey,
的accessToken:的accessToken,
lusername:lusername,
lpassword:lpassword,
provid:provid
}; XHR(xhrPath,{
标题:{内容类型:应用/ JSON的;字符集= UTF-8},
方法:'后',
数据:JSON.stringify(msgbody)
})。然后(功能(数据){
如果(数据==0){
correctInput(反馈,feedbackTD,你的消息无法发送。');
返回;
}
警报('Bcrap仍然没有工作,赚大钱!');
//显示反馈给用户
domStyle.set(反馈,'显示','');
domStyle.set(的document.getElementById('msgBodyOutter'),'显示器','无');
feedbackTD.innerHTML =消息发送成功。
});
})
});
我想通了什么问题是,它是关系到XHR功能。
基本上传递的参数在名称和编号,以配合背后的code。
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.";
});
})
});
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.
这篇关于服务器调用webservice时与500(内部服务器错误)的状态回应的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!