什么是创建JSON Web服务的最佳方式?我们有另一个使用Java的团队,他们坚持要使用JSON进行所有通信。我更喜欢使用WCF而不是任何第三方框架。
我发现了这篇博客:http://www.west-wind.com/weblog/posts/164419.aspx,它指出Microsoft的实现存在M$特定的问题。
我发现了这篇博客:http://www.west-wind.com/weblog/posts/164419.aspx,它指出Microsoft的实现存在M$特定的问题。
public class Hello {
public string Name { get; set; }
}
public class HelloResponse {
public string Result { get; set; }
}
public class HelloService : IService<Hello> {
public object Execute(Hello request)
{
return new HelloResponse { Result = "Hello, " + request.Name };
}
}
var client = new JsonServiceClient(baseUrl);
var response = client.Send<HelloResponse>(new Hello { Name = "World!" });
Console.WriteLine(response.Result); // => Hello, World
使用jQuery:
$.getJSON('hello/World!', function(r){
alert(r.Result);
});
http://mikesknowledgebase.com/pages/Services/WebServices-Page1.htm
它使用了微软备受喜爱的Northwind SQL Server数据库,并展示了如何编写一个简单的JSON WCF Web服务来读取和写入它的数据。 哦,然后它展示了如何使用JavaScript或iOS应用程序消耗JSON数据。 祝你好运!最终我使用了JayRock。这是一款非常棒的技术,它能够完美地工作。如果你没有正确配置WCF,你将不会遇到任何NullReferenceExceptions等问题。