如何在Visual Studio 2012或PHP中为MySQL编写Web服务并在Windows商店应用程序中使用它? [英] How to write a Web service for MySQL in Visual studio 2012 or PHP and consume it in the Windows store app?

查看:109
本文介绍了如何在Visual Studio 2012或PHP中为MySQL编写Web服务并在Windows商店应用程序中使用它?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在C#中开发了一个Windows商店应用程序,我有一个MySQL数据库(工作台),为商店应用程序提供数据。我没有任何网络服务直接连接这些。但现在我想在它们之间引入一个Web服务。我使用Visual Studio 2012开发了商店应用程序。我对Web服务的外观或编写方式没有任何想法。我在网上浏览了很多。我只是一个模糊的想法,我必须编写这个Web服务并在我的商店应用程序中使用它。但目前尚不清楚在哪里写和如何写。



我只有SQL服务器的样本,对我没用。任何人都可以为我提供正确的指导和步骤,如何编写此Web服务,在何处编写以及如何在Windows应用商店中访问它?



我有从我浏览的内容中尝试过。我在Visual Studio 2012中创建了一个Web服务项目,这是我的service1.asmx.cs文件:



I have developed a Windows store app in C# and I have a MySQL database(workbench) that provides data for the store app. I have connected these directly without any web service. But now I want to introduce a web service between them. I have developed the store app using Visual studio 2012. I have no ides on how a web service looks like or where it is written. I browsed a lot through the web. I have just a vague idea that I have to write this web service and consume it in my store app. But it is not clear on where to write and how to write.

I have only got samples for the SQL server which is not helpful for me. Can anyone provide me proper directions and steps as to how to write this web service, Where to write it and How to access it in my Windows store app?

I have tried from what I had browsed. I created a Web Service project in Visual Studio 2012 and here is my service1.asmx.cs file:

namespace WebService1 {

/// <summary>
/// Summary description for Service1
/// </summary>
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.ComponentModel.ToolboxItem(false)]
// To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line. 
// [System.Web.Script.Services.ScriptService]

public class Service1 : System.Web.Services.WebService
{
    [WebMethod]
    public DataSet GetStudents()
{
     using (MySqlConnection connection = new MySqlConnection 
     (ConfigurationManager.ConnectionStrings["myConnectionString"].ConnectionString))
     {
         string Query = "SELECT * FROM [student]";
         MySqlCommand command = new MySqlCommand(Query, connection);
         command.CommandType = CommandType.Text;           
         connection.Open();
         MySqlDataReader reader = command.ExecuteReader();

         DataTable StuTable = new DataTable("student");
         StuTable.Columns.Add("id", typeof(string));
         StuTable.Columns.Add("password", typeof(string));
         StuTable.Columns.Add("courseid", typeof(string));           

        while (reader.Read())
        {
             StuTable.Rows.Add(new object[]
             {
                  reader["id"].ToString(), reader["password"].ToString(), 
                  reader["courseid"].ToString()});
             }

             StuTable.AcceptChanges();
             DataSet ds = new DataSet();
             ds.Tables.Add(StuTable);
             ds.AcceptChanges();
             return ds;
        }
}


}
}





我尝试构建它并将其添加为我的应用程序的服务参考。它表示从地址下载元数据时出错。任何人都可以请帮助我如何在我的商店应用程序中使用此Web服务?这是正确的做法吗?

谢谢。



I tried to build this and add it as a service reference for my app. It says that there was an error downloading the metadata from the address. Can anyone please help as to how to consume this web service in my Store app? Is this the right way of doing this?
Thank you.

推荐答案

这篇关于如何在Visual Studio 2012或PHP中为MySQL编写Web服务并在Windows商店应用程序中使用它?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆