小编Ste*_*uiz的帖子

ASMX webservice不返回JSON,只能使用application/x-www-form-urlencoded contentType进行POST

我可以使用jQuery IF调用我的web服务contentType ="application/x-www-form-urlencoded; charset = utf-8"

但是,这将返回xml: <string>[myjson]</string>

如果我尝试使用"application/json; charset = utf-8"对服务进行POST,我会收到500错误,其中包含空StackTrace和ExceptionType.我的网络服务功能从未被打过,所以我不太确定如何调试这种情况.

我的方法和类使用适当的属性进行修饰,并设置为使用JSON作为其响应类型(与我的wsdl和disco文件一样).我安装了Ajax扩展和web.config中的必需条目.

这是在SharePoint服务器场上,但我不确定这会产生太大的影响.我在所有WFE上部署了web.config更改,并安装了ajax扩展.服务再次起作用,除了默认内容类型之外,它不会接受任何其他内容.

不知道我在这里缺少什么,伙计......

我的ajax电话:

$.ajax({
type: "POST",
url: "/_vti_bin/calendar.asmx/Test",
dataType: "json",
data: "{}",
contentType: "application/json; charset=UTF-8",
success: function(msg){
    alert(msg);
    },
error: function(xhr, msg){ alert(msg + '\n' + xhr.responseText); }
});
Run Code Online (Sandbox Code Playgroud)

我的webservice类:

[WebService(Namespace = "http://namespace")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[ScriptService()]
public class CalendarService : WebService
{
    [WebMethod]
    [ScriptMethod(ResponseFormat = ResponseFormat.Json)]
    public string Test()
    {
        return "Hello World";
    }
}
Run Code Online (Sandbox Code Playgroud)

c# sharepoint jquery web-services asmx

8
推荐指数
1
解决办法
2万
查看次数

在C#中有更简单的方法吗?(null-coalescing type question)

有更简单的方法吗?

string s = i["property"] != null ? "none" : i["property"].ToString();
Run Code Online (Sandbox Code Playgroud)

注意它和null-coalesce(??)之间的区别是在返回之前访问not-null值(op的第一个操作数).

c# null if-statement null-coalescing-operator

3
推荐指数
1
解决办法
205
查看次数