Integration of Web Service Information

Asked

Viewed 339 times

2

I’m having a little trouble making a Web Service.

I have a database Mysql simple to register people.

I already have my methods for performing operations CRUD ready in a classe . that were used in an application Windows Forms

I want my operations CRUD operate from requests by Web service.

From what I understand I can publish Web Service using IIS , so any device that has my address using a rede local can access my Web Service.

To build this kind of functionality I’m thinking of migrating my methods and configuration of connections to a project of the type ASP.NET Web Service Application

With a design with the methods of type [WebMethod] duly configured will be able to use the methods in any language programming ?

I have vague knowledge about web services , but from what I understood that the main goal would be the integration of information .

My goal with this project is to promote a Web Service hosted on my local machine to perform basic operations , to understand how it works integration and consumption of the Web Service in C# and the others linguagens de programação.

1 answer

2


I already have my methods to perform CRUD operations ready in a class . that were used in a Windows Forms application

You can use yes, just call them within a web services method.

From what I understand I can publish Web Service using IIS , so any device that has my address using a local network can access my Web Service.

Yes, you can publish on IIS, if your network was accessible by the device it will connect with your web services normally.

With a project with the methods of type [Webmethod] properly configured will be able to use the methods in any language programming ?

The ideal is that it is in what you have the most knowledge, but it can be done in other language.

I have vague knowledge about web services, but from what I understand that the main objective would be the integration of information .

Web service is a solution used in systems integration and communication between different applications

using System;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Web.Script.Serialization;
using System.Web.Script.Services;
using WebServiceRohr.Classes.Banco;
using RohrLib.Classes;
using WebServiceRohr.Classes;
using RohrApp.Classes;
using System.Data;
using System.Data.SqlClient;
using Newtonsoft.Json;
using System.Collections.Generic;

namespace WebService
{
    /// <summary>
    /// 
    /// </summary>
    [WebService(Description = "Web Service to Work with the Mobile Application", Namespace = "www.seusite.com.br")]
    [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 MobileWebService1 : WebServiceBase
    {

        [ScriptMethod(ResponseFormat = ResponseFormat.Json)]
        [WebMethod()]
        public void MeuMetodo(Int64 id, String Nome)
        {
            using (var DBCtx = new RohrdbContext())
            {
                try
                {
                    // Aqui eu uso entity framework .... 
                    // faça suas alterações de acordo com suas classes...
                    var Tabela = DBCtx.SuaTabela
                        .Where(O => O.id == id)
                        .ToList();


                    // se precisar retornar dados com json
                    JavaScriptSerializer js = new JavaScriptSerializer();

                    string RespJson = js.Serialize(Tabela);
                    writeJsonData(RespJson);
                }
                catch (Exception exc)
                {
                }
            }
        }

        protected void writeJsonData(string s)
        {
            HttpContext context = this.Context;
            HttpResponse response = context.Response;
            context.Response.ContentType = "application/json";
            byte[] b = response.ContentEncoding.GetBytes(s);
            response.AddHeader("Content-Length", b.Length.ToString());
            response.BinaryWrite(b);
            try
            {
                this.Context.Response.Flush();
                this.Context.Response.Close();
            }
            catch (Exception) { }
        }
    }
}

base class for connections

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Configuration;
using RohrLib.Classes;
using System.Web.UI;

namespace WebServiceRohr.Classes
{
    public class WebServiceBase : WebService
    {
        private Int32 m_VSParams = 0;

        StateBag ViewState = new System.Web.UI.StateBag();

        // Create a new VSParam with a unique name
        public ViewstateParam<T> CreateParam<T>()
        {
            m_VSParams++;
            return new ViewstateParam<T>(ViewState, "VSP__" + m_VSParams.ToString());
        }

        // Usado nos diversos DBConn
        protected ConnectionStringSettings ConnString
        {
            get
            {
                return ConfigurationManager.ConnectionStrings["DBConn"];
            }
        }

        protected String ConnString_
        {
            get
            {
                return Convert.ToString(ConfigurationManager.ConnectionStrings["DBConn"]);
            }
        }

        private DBConnection m_DBConn = null;
        public DBConnection DBConn
        {
            get
            {
                if (m_DBConn == null)
                    m_DBConn = new DBConnection(ConnString.ConnectionString);
                return m_DBConn;
            }
        }
    }
}
  • Thank you very much ! then I noticed I was doing a lot of thinking, I should have asked only if my ASP.NET Web Service Application project could be consumed in another language, but thank you very much for the answer =D +1 .

  • Yes, it can be consumed yes.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.