我需要一些帮助。请温和我,我不是专家 - 但。c#webservice返回错误
的事情是,我试着通过JSON从客户端(浏览器)服务器(web服务)发送数据。 当我在Fiddler中观看POST数据时,我可以看到我发送的JSON。这是有效的(测试)。 但我的web服务,(当我手动测试,然后我得到一个返回OK),返回如下:“{”消息“:”有一个错误处理的请求“”堆栈跟踪“:””,‘ExceptionType’: “”}”
不幸的是,其只对内部使用,所以我不能发布web服务为您服务。
有人可以给我什么是错解释一下吗?
1)的Javascript代码:
<script>
var markers = "{param1:1, param2:\"test\"}";
$.ajax({
type: "POST",
url: "http://xxx.xxx.xxx.xxx/site/util.asmx/CreateMarkers",
// The key needs to match your method's input parameter (case-sensitive).
data: JSON.stringify({ Markers: markers }),
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (data) { alert(data); },
failure: function (errMsg) {
alert(errMsg);
}
});
</script>
2.)ASMX代码
<%@ WebService Language="C#" Class="site.Util" %>
using System;
using System.Web.Services;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Script.Services;
namespace site{
[WebService(Namespace="http://xxx.xxx.xxx.xxx/site/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
public class Util: WebService
{
[WebMethod]
[ScriptMethod(ResponseFormat = ResponseFormat.Json)]
public string CreateMarkers(int param1, string param2)
{
return "OK";
}
}
尝试匹配的web服务方法的数据,而不字符串化:数据:标记,...看起来您的数据已经是json格式,并且参数param1和param2的参数相匹配。你不想要一个根Markers属性。 – Andez
您也可以尝试使用Postman(https://www.getpostman.com/)等应用来测试您的Web服务API。它可以单独使用或作为浏览器的插件。它允许你测试纯API来发送和接收数据,所以你可以确保你发送和接收的是预期的 –
@Andez谢谢,但没有你的修改,这是我可以看到的小提琴手:{“标记” :“{param1:1,param2:\”test \“”}我假设这部分是正确的,如果我改变它,因为你建议然后我得到{param1:1,param2:“测试”}这是无效的JSON。这可能是我不明白这是正确的。你能进一步帮助我吗? –