WCF Web Services 使用方法 (SOAP Server Side / SOAP Client Side – return List<string>)
(SOAP Server Side)
Service1.svc.cs |
using System.Collections.Generic; namespace WcfService1 { public class Service1 : IService1 { public List<string> SendList() { List<string> listrow = new List<string>(); listrow.Add("Row 1"); listrow.Add("Row 2"); listrow.Add("Row 3"); listrow.Add("Row 4"); return listrow; } } } |
IService1.cs |
using System.Collections.Generic; namespace WcfService1 { [ServiceContract] public interface IService1 { [OperationContract] List<string> SendList(); } } |
(SOAP Client Side – 需自行增加 Service References)
Default.aspx.cs |
using WebApplication1.ServiceReference1; private void WCFGetData() { Service1Client WCFObj = new Service1Client(); GridView1.DataSource = WCFObj.SendList(); GridView1.DataBind(); WCFObj.Close(); } |