Silverlight에서 Duplex Communication
-
29 Kasım 2011 Salı 08:57
Silverlight에서 Duplex Communication에 대해 알려주세요.
Tüm Yanıtlar
-
29 Kasım 2011 Salı 09:30Moderatör
안녕하십니까? 김도남 님
Microsoft TechNet의 Forum 사이트를 방문해 주셔서 감사합니다.
문의 하신 “Silverlight에서 Duplex Communication”에 대한 답변을 드리겠습니다.
Silverlight에서 HTTP Polling Duplex방식을 구현을 할 수 있습니다. 보통 서비스 방식은 Client -> Server 방식입니다. 이러한 방식은 서버에서 Event가 발생하고 Client에게 전달하는 시나리오에서는 Client가 Server에서 일어나는 이벤트를 확인해야 하기에 많은 Request가 발생을 합니다. 이러한 Request를 줄이기 위해서 Duplex방식을 사용해서 간단히 서버에서 Callback Service를 호출해서 바로 Client에게 메시지를 전달할 수 있습니다.
Project
ServiceContract2
SilverlightApplication58
SilverlightApplication58.Web
Step 1 : Assembly
System.ServiceModel.PollingDuplex.DLL을 이용해서 HTTP Polling Duplex방식을 구현할 수 있습니다.
ServiceContract2, SilverlightApplication57.Web Project에 아래의 경로에서 Assembly를 추가를 합니다.
C:\Program Files\Microsoft SDKs\Silverlight\v4.0\Libraries\Server
System.ServiceModel.PollingDuplex.dll
SilverlightApplication58에 아래의 경로에서 Assembly를 추가를 합니다.
C:\Program Files\Microsoft SDKs\Silverlight\v4.0\Libraries\Client
System.ServiceModel.PollingDuplex.dll
모든 Project에 아래의 Assembly를 추가를 합니다.
System.ServiceModel
System.Runtime.Serialization
Step 2 : Binding
아래와 같이 Service 설정을 합니다. WCF Configuration Editor를 사용할 해서 설정할 수 도 있습니다.
<extensions>
<bindingExtensions>
<!--BiningExtensions Element를 이용해서 HTTPPollingDeplex기능을 사용할 수 있습니다.-->
<add name="pollingDuplexHttpBinding"
type="System.ServiceModel.Configuration.PollingDuplexHttpBindingCollectionElement,
System.ServiceModel.PollingDuplex, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
</bindingExtensions>
</extensions>
<bindings>
<!--Service Element에서 사용할 Binding을 선언을 합니다.-->
<pollingDuplexHttpBinding>
</pollingDuplexHttpBinding>
</bindings>
<!--aspNetCompatibilityEnabled 속성을 사용안함으로 설정을 합니다.-->
<serviceHostingEnvironment aspNetCompatibilityEnabled="false"
multipleSiteBindingsEnabled="true" />
<services>
<!--Client에게 pollingDuplexHttpBinding 방식으로 서비스를 제공을 합니다.-->
<service name="SilverlightApplication58.Web.Class1">
<endpoint address="" binding="pollingDuplexHttpBinding"
contract="ServiceContract2.IClass1" />
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
</service>
</services>
Step 3 : Service Contract
ServiceContract2 Project
ServiceContract2.IClass1
[ServiceContract(Namespace = "Silverlight", CallbackContract = typeof(ICallBackClass1))]
public interface IClass1
{
[OperationContract(IsOneWay = true)]
void Connect(string clientID);
[OperationContract(IsOneWay = true)]
void Trigger(string clientid);
}
ServiceContract2.ICallbackClass1
[ServiceContract]
public interface ICallBackClass1
{
[OperationContract(IsOneWay = true)]
void SendMessage(string message);
}
Step 4 : Client
//PollingDuplexBindingElement설정을 하기 위해 CodeBehehind 방식으로 Service Proxy Instance를 생성을 합니다.
EndpointAddress address = new EndpointAddress("http://localhost:49342/Class1.Svc");
CustomBinding binding = new CustomBinding(new PollingDuplexBindingElement(),
new BinaryMessageEncodingBindingElement(), new HttpTransportBindingElement());
proxy = new Class1Svc.Class1Client(binding, address);
//생성한 Proxy Instance를 이용해서 현재 Client를 등록을 합니다.
proxy.ConnectAsync("User01");
proxy.SendMessageReceived += new EventHandler<Class1Svc.SendMessageReceivedEventArgs>(proxy_SendMessageReceived);
//Callback 함수의 완료 Event Handler를 작성을 합니다.
void proxy_SendMessageReceived(object sender, Class1Svc.SendMessageReceivedEventArgs e)
{
MessageBox.Show(e.message);
}
Project Explorer
참고 자료
ServiceContract 클래스
Duplex Services
http://msdn.microsoft.com/en-us/library/ms731064.aspx
제가 문제에 대해 더 알아야 할 것이 있다면 응답 주시면 감사하겠습니다.
제시해 드린 답변이 도움이 되었기를 바랍니다.
- Düzenleyen SangHyuk KimModerator 29 Kasım 2011 Salı 09:32
- Yanıt Olarak İşaretleyen 김도남 05 Aralık 2011 Pazartesi 04:27