I already have my methods to perform CRUD operations ready in one
class. which were used in a Windows Forms application
You can use yes, just call them within a web services method.
So I understand I can publish Web Service using IIS, so
any device that has my address using a local area network can
access my Web Service.
Yes, you can publish to IIS
, if your network was accessible by the device it will connect with your web services normally.
With a project with methods of type [WebMethod] properly
configured I will be able to use the methods in any language of
programming?
Ideally, it is in what you have more knowledge, but it can be done in other languages.
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;
}
}
}
}