Win10 Development: A simple MobileService

Source: Internet
Author: User

Win10 Development: A simple MobileService

1. added the MobileService project.

1. Create a Win10 project named MobileServiceDemo. In the solution, add a MobileService project.

2. To facilitate debugging, modify the properties of the solution and set the startup project to "currently selected content"

 

3. Test the API

Run this MobileService project. VS will automatically open the local IIS Server to host the current client project and run the result. This http: // localhost: 1827/is the entry to access the current Service. 1827 is the port number and will be used later.

Click try it out to view the list of Apis supported by Mobile Service.

Test the API,

Click "POST tables/TodoItem", click "try this out", modify the items to be inserted in the Sample, and click "Send" to insert data to the database. If the operation succeeds, a status code is returned.

Return to the previous page and select "GET tables/TodoItem". Similarly, click "try this out" and send to view the data items in table TodoItem, including the data items inserted in the previous step.

4. view the TodoItem table

In VS, choose View> server resource manager from the menu ", on the "server resource manager" Panel, select "Data Connection" to find our TodoItem table (why TodoItems is not understood yet ), the text and complete fields are defined in the TodoItem class, and the others are added to EntityData, so that we can view and update table definitions and data.

Ii. Brief Analysis of MobileService project structure

Observe the directory results of this project. If you have developed ASP. net mvc, you will find that the results of the entire project are very similar to ASP. net mvc. In fact, this is a simplified version of MVC project. The following is a brief description of several files. Because I am also a beginner, I can only perform brief analysis. For further analysis, please refer to other materials.

1. In the DataObjects folder, The TodoItem class inherits EntityData. When EntityData is defined by F12, you can see many attributes to facilitate future project development. EntityData is not described too much here, because I do not understand 23333 too well...

 public class TodoItem : EntityData    {        public string Text { get; set; }        public bool Complete { get; set; }    }
2. The TodoItemController class under Controllers inherits TableController The input TodoItem indicates that the current Controller is the TodoItem table of the operation. In the initialization function Initialize, an EntityDomainManager is added. This class is used for better scalability and supports different DataSource projects, such as sqlDatabase, Storage, Table, Blob, and Mongodb.
You can add a Controller to the current folder to implement various Custom APIs.

Iii. Release

If the operations on the MobileService project have been completed, we can Publish the project to Microsoft Azure. (Of course you need to have an Azure account)

Here is a description. What should I do if I have no Azure account? The two methods are always looking for Microsoft's Azure version in China. I don't know if the one-dollar trial of the 21 vianet operation is available. The other is that the remote Azure is not used for the time being, using the local "Azure" is actually not doing this release operation, and the host is stored locally. The Demo section below will be explained. Don't get me wrong. I am also poor, but I have an MSDN subscription from Microsoft, so I have an Azure account...

1. Right-click the project name and choose publish from the shortcut menu. If you select import, You need to import a configuration file corresponding to your Azure account, which can be found in the Azure Portal panel. Find the MobileService you want to update and enter the dashboard to download and publish the configuration file.

Select Microsoft Azure mobile services to add or update mobile services directly on Azure. If you select an item in the list, you can perform the update operation or create a new item. The new operation is basically the same as the operation on the Azure Portal.

The subsequent steps are relatively simple, and some items can be left by default if they are unfamiliar. The Destination URL under the connection tag is the URL to access this Service.

After the release is successful, access this URL and select try it out again, you will be asked to enter the corresponding account password, as long as you enter the password to log on. The key can be viewed under the "manage key" corresponding to the mobile service in the Azure Portal panel.

To perform remote debugging, follow these steps:

On the "server resource manager" Panel, right-click the corresponding mobile service and choose "add debugging program. Forgot! In the previous release, you must select the Debug version to support remote debugging. In addition, remote debugging seems to be a special card, so be prepared.

Iv. Win10 Demo

Since it is a MobileService, you should manage and operate the data through the client, rather than in the Web, so the previous part can be considered a preparation work.

The following describes how to operate the data in the Win10 application.

In step 1, we have created a MobileServiceDemo Win10 project. Now we can modify this project.

1. Right-click the project name, select "manage Nuget packages", search for "WindowsAzure. MobileServices", and install the program.

2. Open the App. xaml. cs file and add a MobileServiceClient class.

If you want to connect to the local MobileService, add the following code. 1827 is the port number mentioned above. Tip: If you are performing local operations, remember to run the MobileService service.

public static MobileServiceClient MobileService = new MobileServiceClient("http://localhost:1827");
If you want to connect to a remote Azure server, add the following code. The *** here is the key required to manage access to the mobile service.
public static MobileServiceClient MobileService = new MobileServiceClient("https://mspmonthreport.azure-mobile.net/","********************");
3. added the TodoItem class.
public class TodoItem    {        public string Id { get; set; }        [JsonProperty(PropertyName = "text")]        public string Text { get; set; }        [JsonProperty(PropertyName = "complete")]        public bool Complete { get; set; }    }

4. Modify the MainPage. xaml page and add a TextBox and a Button.
<Stackpanel> <textbox x: name = "txtVal"> <button content = "add" click = "btnAdd_Click"> </button> </textbox> </stackpanel>
5. added the btnAdd_Click event.
 private async void btnAdd_Click(object sender, RoutedEventArgs e)        {            var item = new TodoItem { Text = txtVal.Text };            await InsertItem(item);        }        private async Task InsertItem(TodoItem todoItem)        {            await todoTable.InsertAsync(todoItem);        }

Here, todoTable is used to obtain the TodoItem table.
private IMobileServiceTable
  
    todoTable = App.MobileService.GetTable
   
    ();
   
  

6. Run the project to insert data. Of course, there are no more complex addition, deletion, modification, and query operations for data checksum. However, the operations are similar. I will not explain them in detail here.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.