Communication between Silverlight and WCF (1) SL Client timed request WCF Service

Source: Internet
Author: User
Tags datetime silverlight

These days in doing a Silverlight page chat tool, basically looked at Silverlight and WCF related things, but also encountered a lot of problems, just started with Silverlight did the timing of the server data information, late preparation to use WCF duplex communication To do, the communication process is divided into two parts records.

One, you need to build a WCF server

Here, a new WCF service is created directly in the Silverlight site, with the following code:

Define Service Contracts First
[ServiceContract]
public interface Ichatservice
{
[OperationContract]
BOOL SendMessage (Messageinfo msg);
[OperationContract]
List<messageinfo> getmessages (string useraccount);
}
Define data contracts again
[DataContract]
public class Messageinfo
{
[DataMember]
public string ID {set;
[DataMember]
public string Title {set;
[DataMember]
public string Message {set;
[DataMember]
Public DateTime Sendtime {set;
[DataMember]
Public DateTime? readtime {set; get;}
[DataMember]
public string Sender {set;
[DataMember]
public string Receiveuser {set;
[DataMember]
public string Receiveorgan {set;
[DataMember]
public string Receivemode {set;
[DataMember]
public int State {set; get;}
[DataMember]
public int Receipt {set; get;}
[DataMember]
public string Source {set;
}
Finally, configure the service in the Webconfig
<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior name= "Chatbehavior" >
<servicemetadata httpgetenabled= "true"/>
<servicedebug includeexceptiondetailinfaults= "false"/>
</behavior>
</serviceBehaviors>
</behaviors>
<services>
<service behaviorconfiguration= "Chatbehavior" name= "WebChat.Web.ChatService" >
<endpoint address= "" binding= "BasicHttpBinding" contract= "WebChat.Web.IChatService" ></endpoint>
</service>
</services>
<servicehostingenvironment multiplesitebindingsenabled= "true"/>
</system.serviceModel>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.