我想开发一个带有WCF
服务的Web应用程序,该服务不仅支持我的Web应用程序,还支持使用JSON
进行所有操作的移动应用程序。
那么有人可以为它建议最好的架构以及如何实现它吗?
更新
这是我到目前为止所尝试的内容
1)这是我的应用程序的结构
2)IHelloService.cs
3)HelloService.svc
4)工厂中的业务逻辑 - ServiceProfile.cs
4)实体 - Profile.cs
5)在页面上调用服务
这样可以正常使用!!但当我通过Android应用程序访问此服务,必须返回JSON。那是我被困的地方。如何使用可以双方使用的相同服务。
为了测试这项服务,我使用了如下的ajax调用。
$.ajax({
url: "Service/HelloService.svc/TestService",
type: 'POST',
//dataType: 'json',
//contentType: "application/json; charset=utf-8",
data: JSON.stringify({ "_Profile": [{ "Name": "Aijaz from JSON" }] }),
success: function (data) {
$('[Id$="Label1"]').text(data);
},
error: function (e) {
},
complete: function () { }
});
答案 0 :(得分:0)
创建一个宁静的WCF服务。此服务将提供JSON格式的数据,您可以在Web应用程序/移动应用程序中使用。
更多信息:如何创建此类服务。 http://www.compilemode.com/2015/09/creating-wcf-rest-service-to-get-json.html
我希望这就是你想要的。
答案 1 :(得分:0)
我认为你错过了webHttpBinding的绑定细节。 :)