简体   繁体   中英

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 .

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

在此处输入图片说明

2) IHelloService.cs

在此处输入图片说明

3) HelloService.svc

在此处输入图片说明

4) Business Logic in Factory - ServiceProfile.cs

在此处输入图片说明

4) Entity - Profile.cs

在此处输入图片说明

5) Calling a Service on Page

在此处输入图片说明

This will work fine!! but when i access this service through android app that must return JSON. 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({
            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. This service will provide data in JSON format which you can use in Web app / Mobile app.

More info: How to create such service. 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. :)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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