searcho Sheer dO Sheer PsearchssearchM Freesite s Www a Szh esearchopsearchesearche Sheer I Undies s Www n Undies R Sites susearchti Szh Ssearch searchhsearchns Freesite r
{}
else
{}
}
Thongs o Nekkidnaked d Undies C Sheer mp Nekkidnaked e Szh euesearchr Szh hsearchs Dating ac Sheer e
Dsearchtsearchn Szh Sites searchesearchkdn Sites k Freesite d g Singles esearchrc
( Szh e Nekkidnaked rc
AsearchSsearchnles Undies it Sites s
cR Sheer e Undies rhsearch Www esearchksearchd Sites asearche Szh l Sites ssearchasearchc Www a
)
{}
catch (Exception ex)
{}
}
void IUniversalDuplexContract.SendToService(DuplexMessage msg)
{}
}
//If it's a Disconnect message, treat as disconnection
if (msg is DisconnectMessage)
{}
//Otherwise, if it's a payload-carrying message (and not just a simple "Connect"), process it
else if (!(msg is ConnectMessage))
{}
}
void Channel_Closing(object sender, EventArgs e)
{}
void Channel_Faulted(object sender, EventArgs e)
{}
void ClientDisconnected(string sessionId)
{}
try
{}
catch (Exception ex)
{}
}
//Helper class for tracking both a channel and its session ID together
class PushMessageState
{}
}
}
The DuplexService can be used as base class of other business services.
3. Creating Base Duplex Service Factory
DuplexServiceFactory<T>
/// <summary>
/// Derive from this class to create a duplex Service Factory to use in an .svc file
/// </summary>
/// <typeparam name="T">The Duplex Service type (typically derived from DuplexService)</typeparam>
public abstract class DuplexServiceFactory<T> : ServiceHostFactoryBase
where T : IUniversalDuplexContract, new()
{}
}
The factory is responsible for creating the appropriate host while the host defines the service endpoint.
4. Create Base Duplex Message
/// <summary>
/// Base message class. Please add [KnownType] attributes as necessary for every
/// derived message type.
/// </summary>
[DataContract(Namespace = "silverlight2/duplex")]
[KnownType(typeof(ConnectMessage))]
[KnownType(typeof(DisconnectMessage))]
[KnownType(typeof(LiveDataMessage))]
public class DuplexMessage {}
Any business objects intend to be pushed from the duplex service to silverlight clients must derive from this DuplexMessage class, and with a [KnownType] attribute.
Now we have constructed the infrastructure of the duplex service. Next Let's create a concrete duplex business service to push business data to silverlight clients.
5. Create a Business Service
LiveDataMessage
[DataContract]
public class LiveDataMessage: DuplexMessage
{}
[DataMember]
public string Description {}
}
public class LiveDataService :DuplexService
{}
void LiveDataUpdate(object o)
{};
PushToAllClients(liveDataMessage);
}
}
<%@ ServiceHost
Language="C#"
Debug="true"
Service="DuplexExample.Web.LiveDataService"
%>
6. Config the Duplex Service
The Web.config file looks like below.
<system.serviceModel>
<!-- Create the polling duplex binding. -->
<bindings>
<pollingDuplexHttpBinding>
<binding name ="duplexHttpBinding"
receiveTimeout="00:04:00"
inactivityTimeout="00:03:00"
>
<security mode="None" />
</binding>
<binding name ="duplexHttpsBinding"
receiveTimeout="00:04:00"
inactivityTimeout="00:03:00"
>
<security mode="Transport">
<transport clientCredentialType="None" proxyCredentialType="None" realm="" />
</security>
</binding>
</pollingDuplexHttpBinding>
</bindings>
<services>
<service name="DuplexExample.Web.LiveDataService"
behaviorConfiguration="DuplexService.OrderServiceBehavior">
<!-- Specify the service endpoints. -->
<endpoint address=""
binding="pollingDuplexHttpBinding"
behaviorConfiguration="devleapBehavior"
bindingConfiguration="duplexHttpBinding"
contract="Microsoft.Silverlight.Cdf.Samples.Duplex.IUniversalDuplexContract">
</endpoint>
<endpoint address="ssl"
binding="pollingDuplexHttpBinding"
behaviorConfiguration="devleapBehavior"
bindingConfiguration="duplexHttpsBinding"
contract="Microsoft.Silverlight.Cdf.Samples.Duplex.IUniversalDuplexContract">
</endpoint>
<endpoint address="mex"
binding="mexHttpsBinding"
contract="IMetadataExchange"/>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="DuplexService.OrderServiceBehavior">
<serviceMetadata httpsGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="true"/>
</serviceCredentials>
<serviceThrottling maxConcurrentSessions="2147483647"/>
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
7. Create a Silverlight Client Application
The core code to create DuplexServiceClient looks like below.
DuplexServiceClient receiver;
ObservableCollection<string> liveDataMessages = new ObservableCollection<string>();
string address = "DuplexService/LiveDataService.svc";
EndpointAddress endpoint = new EndpointAddress(address);
PollingDuplexHttpBinding binding = new PollingDuplexHttpBinding();
receiver = new DuplexServiceClient(binding,endpoint);
receiver.SendToClientReceived += (sender, e) =>
{}. Value = {}", msg.Description, msg.Value));
}
};
Of course it is required to add reference to the LiveDataService.svc we created earlier.
8. Build and Run the Application
Before the application can build and run, we must add reference to System.ServiceModel.PollingDuplex in both the web site hosting the duplex service and the silverlight project. There are 2 DLL file for service side and Silverlight side, they locate in:
%ProgramFiles%Microsoft SDKsSilverlightv3.0LibrariesServer (this is the one for service)
%ProgramFiles%Microsoft SDKsSilverlightv3.0LibrariesClient (this is the one for Silverlight)
Now build and run the application, and watch the result shown as below.
9. Step Forward
Now we have an executable sample application built on WCF duplex service and Silverlight3.
I did not apply security future on this application. You can refer to my other blogs to get knowledge about WCF service security.
Now we have a executable sample application built on WCF duplex service and Silverlight3.