[WCF] WCF의 기초 통신



기본적인 통신으로서 Http 를 이용하겠다.


서버측 인터페이스 (DLL 으로 뽑을것)
 
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ServiceModel;

namespace StikusFrameServiceInterFace
{
    [ServiceContract]
    public interface ISFServerProtocol
    {
        [OperationContract]
        string StikusFrameAuth(string AuthXmlDataString);


        [OperationContract]
        string StikusFrameClose(string AuthXmlDataString);
        
    }
}


서버측 구현

using System; using System.Collections.Generic; using System.Linq; using System.Text; using StikusFrameServiceCore.JUtil.Trace; using StikusFrameServiceInterFace; using System.ServiceModel; namespace StikusFrameServiceCore { public class StikusFrameServiceStart { ServiceHost SFService; public StikusFrameServiceStart() { JTrace.trace("start!"); SFService = new ServiceHost( typeof(SFServiceProtocol), //ISFServerProtocol 를 구현한 클래스 new Uri("http://wow/wowblahblah"));

SFService.AddServiceEndpoint( typeof(ISFServerProtocol) , new BasicHttpBinding() , ""); SFService.Open(); } public void CloseSFService() { SFService.Close(); } } }




클라이언트 ( 위의 인터페이스를 .DLL 으로 공유 한다. )

 using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.ServiceModel;
using System.ServiceModel.Description;
using StikusFrameServiceInterFace;
namespace WCFClient
{
    /// <summary>
    /// MainWindow.xaml에 대한 상호 작용 논리
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
        }

        protected override void OnInitialized(EventArgs e)
        {
            base.OnInitialized(e);

            Uri uri = new Uri("http://wow/wowblahblah");
            ServiceEndpoint ep = new ServiceEndpoint(
                ContractDescription.GetContract(typeof(ISFServerProtocol)) ,
                new BasicHttpBinding() ,
                new EndpointAddress(uri));

            ChannelFactory<ISFServerProtocol> factory =
                new ChannelFactory<ISFServerProtocol>(ep);

            ISFServerProtocol proxy = factory.CreateChannel();
            string result = proxy.StikusFrameAuth("auth");
            Console.WriteLine(result);
        }
    }
}




클라이언트 배포시 보안상의 이유호 서버측의 인터페이스만 DLL 로 공유하는 방법을 선택한다.

Yamecoder 야매코더_
tags :
C# 2011.12.19 10:02
Powerd by Tistory, designed by criuce
rss