2013-01-01 2 views
0

클래스 객체와 함께 웹 서비스를 사용하는 방법이 궁금합니다. 고객, 작업, 프로젝트 등의 BOL에 클래스 객체가 있습니다. ADO.net을 사용하여 데이터 영역에 연결합니다. 그냥 내 프로젝트에서 웹 서비스를 사용하기 시작했다. "WebServices"라는 폴더를 추가했다. 그리고 BOL의 메소드를 사용하여 웹 서비스의 Json 객체에 데이터를 가져오고 데이터를 가져왔다. WebServices를 직접 데이터베이스에 연결하거나 BAL을 사용하여 Json으로 가져온 후 데이터를 가져와야하는지 궁금합니다.웹 서비스 및 클래스 객체

using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Web; 
using System.Web.Services; 
using Compudata_ProjectManager.CodeFile.BOL; 
using System.Web.Script.Services; 



namespace Compudata_ProjectManager.WebServices 
{ 
    /// <summary> 
    /// Summary description for CustomerList 
    /// </summary> 
    [WebService(Namespace = "http://tempuri.org/")] 
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)] 

    // 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 CustomerList : System.Web.Services.WebService 
    { 


      [WebMethod] 
      [ScriptMethod(ResponseFormat = ResponseFormat.Json)] 
      public List<Customer> FetchCustomersList(string name) 
      { 
       var cust = new Customer(); 
       var fetchNames = cust.GetAllCustomerNames().Where(n => n.FirstName.ToLower().StartsWith(name.ToLower())); 
       return fetchNames.ToList(); 
      } 


      [WebMethod] 
      [ScriptMethod(ResponseFormat = ResponseFormat.Json)] 
      public List<Location> FetchCustomerAddressList(string name) 
      { 
       var Addresses = new Location(); 
       var fetchAddress = Location.GetAllAddress(); 
       return fetchAddress.ToList(); 
      } 

     } 

}

답변

1

예, 당신은 직접 웹 서비스와 데이터베이스를 연결할 수 있습니다. 그러나 적절한 방법이 아닙니다.

데이터베이스에 직접 연결하면 코드가 증가하고 성능이 저하 될 수 있습니다. 또한 코드의 품질이 저하됩니다.

BAL을 사용하여 비즈니스 논리를 분리하면 코드가 깔끔하고 깨끗합니다.

여기에 우리가 일반적으로 사용하는 좋은 예가 있습니다. Consuming Webservice using JQuery ASP.NET Application

Web Services using JQuery AJAX

업데이트

데이터베이스에 직접 웹 서비스를 연결하고 싶다면, 여기에 링크이지만 : Call database from webservice

0

예, 이상적으로 소비하는 BL을 사용하여 웹 서비스. 그것은 모든 비즈니스 로직을 분리 할 것이고 코드도 확장 성을 가질 것입니다.