ㅁㅁㅁ
서버측(ServerSide [Host])
Interface
using System.ServiceModel;
namespace TESTWCF_2_Server
{
//콜백할 인터페이스 이다. 곧 Client 가 된다..
[ServiceContract]
public interface ISomeCallback
{
[OperationContract]
void SendMessageToClient(string someStr);
}
//WCF host에서 구현할 인터페이스 이다.
//ServiceContract 에 콜백 인터페이스를 등록 하였다.
[ServiceContract(CallbackContract = typeof(ISomeCallback))]
public interface ISome
{
[OperationContract]
void StartService();
[OperationContract]
void SendMessageToServer(string someStr);
}
}
namespace TESTWCF_2_Server
{
//콜백할 인터페이스 이다. 곧 Client 가 된다..
[ServiceContract]
public interface ISomeCallback
{
[OperationContract]
void SendMessageToClient(string someStr);
}
//WCF host에서 구현할 인터페이스 이다.
//ServiceContract 에 콜백 인터페이스를 등록 하였다.
[ServiceContract(CallbackContract = typeof(ISomeCallback))]
public interface ISome
{
[OperationContract]
void StartService();
[OperationContract]
void SendMessageToServer(string someStr);
}
}
구현
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ServiceModel;
using JUtil;
namespace TESTWCF_2_Server
{
/// <summary>
/// ISome 을 구현한 클래스이다.
/// 클라이언트 구현시 서비스 참조의 명세가 되는 클래스 이다.
/// ServiceBehavior 의 속성을 제어 할수 있다.
/// </summary>
[ServiceBehavior(InstanceContextMode = InstanceContextMode.Single , ConcurrencyMode = ConcurrencyMode.Single)]
public class Service : ISome , IDisposable
{
/// <summary>
/// 편의를 위해 싱글턴으로 만든다.
/// </summary>
private static Service inst = null;
public static Service getInst()
{
if(inst == null)
{
inst = new Service();
}
return inst;
}
//클라이언트들을 모을 배열이다.
private List<ISomeCallback> clients;
private Service()
{
inst = this;
TraceBox.trace("Start Service");
clients = new List<ISomeCallback>();
}
//접속
//클라이언트들이 접속되자 마자 실행하게될 메소드
//접속한 클라이언트 정보를 받아 클라이언트 배열에 넣는다.&#
public void StartService()
{
OperationContext ctx = OperationContext.Current;
ISomeCallback client = ctx.GetCallbackChannel<ISomeCallback>();
clients.Add(client);
//클라이언트 들은 IClientChannel로 타입캐스팅을 하여
//각종 정보를 얻는다.668;
//각종 정보를 얻는다.
IClientChannel channel = client as IClientChannel;
TraceBox.trace("info : client Add" + Environment.NewLine , channel.SessionId);
}
//전송
//서버가 클라이언트들에게 전송송/클라이언트들에게 전송/
public void brodcast(string message)
{
foreach (ISomeCallback client in clients)
{
//클라이언트 들은 IClientChannel로 타입캐스팅을 하여
//상태 체크를 한다. 그중 접속이 꺼지거나,
//전송을 할수 없는 상황을 체크하여 활성 클라이언트만 골라낼수 있다
// cf)channel.State
IClientChannel channel = client as IClientChannel;
client.SendMessageToClient(message);
}
}
public void Dispose()
{
}
public void SendMessageToServer(string someStr)
{
TraceBox.trace(someStr);
}
}
}
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ServiceModel;
using JUtil;
namespace TESTWCF_2_Server
{
/// <summary>
/// ISome 을 구현한 클래스이다.
/// 클라이언트 구현시 서비스 참조의 명세가 되는 클래스 이다.
/// ServiceBehavior 의 속성을 제어 할수 있다.
/// </summary>
[ServiceBehavior(InstanceContextMode = InstanceContextMode.Single , ConcurrencyMode = ConcurrencyMode.Single)]
public class Service : ISome , IDisposable
{
/// <summary>
/// 편의를 위해 싱글턴으로 만든다.
/// </summary>
private static Service inst = null;
public static Service getInst()
{
if(inst == null)
{
inst = new Service();
}
return inst;
}
//클라이언트들을 모을 배열이다.
private List<ISomeCallback> clients;
private Service()
{
inst = this;
TraceBox.trace("Start Service");
clients = new List<ISomeCallback>();
}
//접속
//클라이언트들이 접속되자 마자 실행하게될 메소드
//접속한 클라이언트 정보를 받아 클라이언트 배열에 넣는다.&#
public void StartService()
{
OperationContext ctx = OperationContext.Current;
ISomeCallback client = ctx.GetCallbackChannel<ISomeCallback>();
clients.Add(client);
//클라이언트 들은 IClientChannel로 타입캐스팅을 하여
//각종 정보를 얻는다.668;
//각종 정보를 얻는다.
IClientChannel channel = client as IClientChannel;
TraceBox.trace("info : client Add" + Environment.NewLine , channel.SessionId);
}
//전송
//서버가 클라이언트들에게 전송송/클라이언트들에게 전송/
public void brodcast(string message)
{
foreach (ISomeCallback client in clients)
{
//클라이언트 들은 IClientChannel로 타입캐스팅을 하여
//상태 체크를 한다. 그중 접속이 꺼지거나,
//전송을 할수 없는 상황을 체크하여 활성 클라이언트만 골라낼수 있다
// cf)channel.State
IClientChannel channel = client as IClientChannel;
client.SendMessageToClient(message);
}
}
public void Dispose()
{
}
public void SendMessageToServer(string someStr)
{
TraceBox.trace(someStr);
}
}
}
using System;
using System.Windows;
using System.ServiceModel;
using System.ServiceModel.Description;
using JUtil;
namespace TESTWCF_2_Server
{
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}
ServiceHost host;
protected override void OnInitialized(EventArgs e)
{
base.OnInitialized(e);
TraceBox.InitailizeTraceBOX(textBox1);
/**
* Tcp 바인딩을 선언한다. * */
NetTcpBinding binding = new NetTcpBinding();
binding.Security.Mode = SecurityMode.None;
binding.ReliableSession.Enabled = false;
/*
* ServiceMetadataBehavior 를 선언하여 서비스 참조를 할수있도록 한다* */
ServiceMetadataBehavior behavior = new ServiceMetadataBehavior();
behavior.HttpGetEnabled = true;
//WCF host 생성//;
host = new ServiceHost(
typeof(Service),
new Uri("http://192.168.0.7:8507/wcf"),
new Uri("net.tcp://192.168.0.7/wcf")
);
host.AddServiceEndpoint(typeof(ISome), binding, "");
////behavior 를 등록한다;
host.Description.Behaviors.Add(behavior);
host.Open();
}
protected override void OnClosed(EventArgs e)
{
host.Close();
base.OnClosed(e);
}
private void button1_Click(object sender, RoutedEventArgs e)
{
Service.getInst().brodcast(ChatBox.Text);
}
}
}
using System.Windows;
using System.ServiceModel;
using System.ServiceModel.Description;
using JUtil;
namespace TESTWCF_2_Server
{
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}
ServiceHost host;
protected override void OnInitialized(EventArgs e)
{
base.OnInitialized(e);
TraceBox.InitailizeTraceBOX(textBox1);
/**
* Tcp 바인딩을 선언한다. * */
NetTcpBinding binding = new NetTcpBinding();
binding.Security.Mode = SecurityMode.None;
binding.ReliableSession.Enabled = false;
/*
* ServiceMetadataBehavior 를 선언하여 서비스 참조를 할수있도록 한다* */
ServiceMetadataBehavior behavior = new ServiceMetadataBehavior();
behavior.HttpGetEnabled = true;
//WCF host 생성//;
host = new ServiceHost(
typeof(Service),
new Uri("http://192.168.0.7:8507/wcf"),
new Uri("net.tcp://192.168.0.7/wcf")
);
host.AddServiceEndpoint(typeof(ISome), binding, "");
////behavior 를 등록한다;
host.Description.Behaviors.Add(behavior);
host.Open();
}
protected override void OnClosed(EventArgs e)
{
host.Close();
base.OnClosed(e);
}
private void button1_Click(object sender, RoutedEventArgs e)
{
Service.getInst().brodcast(ChatBox.Text);
}
}
}
클라이언트(ClientSide)
using System;
using System.Windows;
using System.ServiceModel;
using TESTWCF_2_Client.SomeService;
using JUtil;
namespace TESTWCF_2_Client
{
/// <summary>
/// MainWindow.xaml에 대한 상호 작용 논리
/// </summary>>
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}
SomeClient proxy;
protected override void OnInitialized(EventArgs e)
{
base.OnInitialized(e);
TraceBox.InitailizeTraceBOX(textBox1);
/**
* app.config 를 이용하지 않기 위해 아래와 같이 binding 을 따로 선언한다.
* => 차후 동적으로 WCF 호스트를 열기 위해서 이다.
* */*/
NetTcpBinding bindig = new NetTcpBinding();
bindig.Security.Mode = SecurityMode.None;
bindig.ReliableSession.Enabled = false;
//콜백 인스턴스를 구현한 클래스를 아래와 같이 적용한다;
InstanceContext ctx2 = new InstanceContext(new SomeCallbackHandler());
/**
* SomeClient 는 서비스참조에 의해 자동으로 생성된 클래스로서
DuplexClientBase<ISome> 을 상속하고
ISome 을 구현 한다
(정의로 이동) 하여 내용을 볼수 있다.
* */*/
proxy = new SomeClient(
ctx2,
bindig,
new EndpointAddress("net.tcp://192.168.0.7/wcf"));
//호스트에 접속한다. 만약 호스트가 실행중이 아니라면 Exception..
proxy.Open();
proxy.StartService();
}
private void button1_Click(object sender, RoutedEventArgs e)
{
//프록시를 통하여 호스트(Server) 로 메시지를 보낸다;
proxy.SendMessageToServer(ChatBox.Text);
}
}
/// <summary>
/// 호스트 로 부터 메시지를 받을 콜백 클래스
/// </summary>>
class SomeCallbackHandler : SomeService.ISomeCallback
{
public void SendMessageToClient(string someStr)
{
TraceBox.trace(someStr);
}
}
}
using System.Windows;
using System.ServiceModel;
using TESTWCF_2_Client.SomeService;
using JUtil;
namespace TESTWCF_2_Client
{
/// <summary>
/// MainWindow.xaml에 대한 상호 작용 논리
/// </summary>>
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}
SomeClient proxy;
protected override void OnInitialized(EventArgs e)
{
base.OnInitialized(e);
TraceBox.InitailizeTraceBOX(textBox1);
/**
* app.config 를 이용하지 않기 위해 아래와 같이 binding 을 따로 선언한다.
* => 차후 동적으로 WCF 호스트를 열기 위해서 이다.
* */*/
NetTcpBinding bindig = new NetTcpBinding();
bindig.Security.Mode = SecurityMode.None;
bindig.ReliableSession.Enabled = false;
//콜백 인스턴스를 구현한 클래스를 아래와 같이 적용한다;
InstanceContext ctx2 = new InstanceContext(new SomeCallbackHandler());
/**
* SomeClient 는 서비스참조에 의해 자동으로 생성된 클래스로서
DuplexClientBase<ISome> 을 상속하고
ISome 을 구현 한다
(정의로 이동) 하여 내용을 볼수 있다.
* */*/
proxy = new SomeClient(
ctx2,
bindig,
new EndpointAddress("net.tcp://192.168.0.7/wcf"));
//호스트에 접속한다. 만약 호스트가 실행중이 아니라면 Exception..
proxy.Open();
proxy.StartService();
}
private void button1_Click(object sender, RoutedEventArgs e)
{
//프록시를 통하여 호스트(Server) 로 메시지를 보낸다;
proxy.SendMessageToServer(ChatBox.Text);
}
}
/// <summary>
/// 호스트 로 부터 메시지를 받을 콜백 클래스
/// </summary>>
class SomeCallbackHandler : SomeService.ISomeCallback
{
public void SendMessageToClient(string someStr)
{
TraceBox.trace(someStr);
}
}
}
* 서비스 호스트 참조법
참조를 위해선 ServiceMetadataBehavior 를 위의 샘플 처럼 구현을 해야 한다.
우선 위와 같이 서버 호스트를 실행 시킨다.
[참조] 오른쪽버튼 -> 서비스참조 추가
에서 서버의 바인딩중 선언한 http 주소를 입력한다
'C#' 카테고리의 다른 글
[Tcp] 연속적인 정보를 송출시 유의점 (91) | 2012.11.04 |
---|---|
[MEMO] (58) | 2012.10.14 |
[WCF] 간단한 채팅 샘플 (61) | 2012.05.12 |
[ASP.NET] 클라이언트가 멀티파트 보내고 서버가 받기 (77) | 2012.05.05 |
[lamda] 메서드 안에 이벤트 핸들러 선언하기 , 삭제가능 (내장 Delegate) (98) | 2012.04.05 |
EnCrypto / DeCrypto (77) | 2012.03.09 |
어관Basketball Jerseys
What is the distinction in between a swingman basketball jersey and a replica jersey?
Swingman jerseys commonly have a single layer of stitched material for that player/ staff names and numbers whilst replica jerseys possess the names and numbers screen printed on them. Swingman jerseys are closer on the authentic jerseys since the letters and numbers stitched on. Nevertheless일려
다되Your ISP shut your services down even if you are running opt-in email lists because of some complaints from some users that forget they were opted in? Then our overseas BP (bullet proof) web hosting services are your choice. We will help you on getting a stable web hosting and make money with ease.
Your ISP shut your services down even if you are running opt-in email lists because of some com지려
는지Adult dating email lists어되
이용약관위배로 관리자 삭제된 댓글입니다.
선습Fifty percent the actual knockout circular is placed
It appears as though the planet Mug simply started, as well as currently fifty percent the actual knockout circular places happen to be used. 8 groups have been in having a opportunity; 8 tend to be soaring house. Here is a glance at every team which has been made the decision.
Team The: South america as well as South america within, Croat일그
이용약관위배로 관리자 삭제된 댓글입니다.
이용약관위배로 관리자 삭제된 댓글입니다.
이용약관위배로 관리자 삭제된 댓글입니다.
이용약관위배로 관리자 삭제된 댓글입니다.
이용약관위배로 관리자 삭제된 댓글입니다.
이용약관위배로 관리자 삭제된 댓글입니다.
이용약관위배로 관리자 삭제된 댓글입니다.
이용약관위배로 관리자 삭제된 댓글입니다.
이용약관위배로 관리자 삭제된 댓글입니다.
이용약관위배로 관리자 삭제된 댓글입니다.
이용약관위배로 관리자 삭제된 댓글입니다.
이용약관위배로 관리자 삭제된 댓글입니다.
예관Zhou Enlai à Alger pour participer à la Conférence afro - asiatique il a dit "Tianjin" en 1898 a publié la traduction de journaux britanniques et burberry parfum femme je n'aime pas les t shirt burberry pas cher fleurs. il n'y a pas de conception "virginité", il a été considéré sans espoir, mange très doux. où il est tomb마적
를조In fact, AIRMAX and not stand still, today we join in the use of special powers of the Nike Air Max 2009 sale, AIRMAX identification of a new era to create. Nike Air Max 2009 sale, the use of a feature of the technology of today's most ardent Flywire.
Although the use of new technologies and maintaining AIRMAX traditional shoe design line of the body,5 Geeky Ways to Make Money Th, new techn표마
데전and even better news is that their greatest extent EVER!Beautiful flowers and fittings add a touch of tartan jackets that unmistakable feminine essence, while injections of red.
Purple and orange make this the biggest ever range of colors.Barbour waxed jackets, Barbour International Quilt Jacket,Utilizing, Jackets Barbour Polar Quilt .
Online shopping has opened doors for both merchant로알