简体   繁体   English

如何使用WCF服务支持Web应用程序和移动应用程序?

[英]How to use WCF service to support Web Application as well as Mobile Application?

I want to develop a Web application with WCF service that supports not only My web application but Mobile Application as well which is doing all the manipulation using JSON . 我想用WCF服务开发一个Web应用程序,该服务不仅支持My Web应用程序,还支持Mobile Application,该应用程序使用JSON进行所有操作。

So can someone suggest the best architecture for it and how to implement it? 那么,有人可以建议最佳的体系结构以及如何实现它吗?

Update 更新资料

Here is what i have tried so far 到目前为止,这是我尝试过的

1) This is the structure of my application 1)这是我的应用程序的结构

在此处输入图片说明

2) IHelloService.cs 2)IHelloService.cs

在此处输入图片说明

3) HelloService.svc 3)HelloService.svc

在此处输入图片说明

4) Business Logic in Factory - ServiceProfile.cs 4)工厂中的业务逻辑-ServiceProfile.cs

在此处输入图片说明

4) Entity - Profile.cs 4)实体-Profile.cs

在此处输入图片说明

5) Calling a Service on Page 5)在页面上调用服务

在此处输入图片说明

This will work fine!! 这样会很好! but when i access this service through android app that must return JSON. 但是当我通过必须返回JSON的android应用访问此服务时。 That is where i got stuck. 那就是我被困住的地方。 how to use same service that can be used both side. 如何使用可以同时使用的相同服务。

To test this service i used ajax call as below. 为了测试该服务,我使用了如下的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 () { }
        });

Create a restful WCF service. 创建一个宁静的WCF服务。 This service will provide data in JSON format which you can use in Web app / Mobile app. 此服务将以JSON格式提供数据,您可以在Web应用程序/移动应用程序中使用。

More info: How to create such service. 更多信息:如何创建这样的服务。 http://www.compilemode.com/2015/09/creating-wcf-rest-service-to-get-json.html http://www.compilemode.com/2015/09/creating-wcf-rest-service-to-get-json.html

I hope this is what you wanted. 希望这就是您想要的。

I think you missed the binding details webHttpBinding. 我认为您错过了webHttpBinding的绑定详细信息。 :) :)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM