Content of the invention
In order to make up the deficiency of above technology, the invention provides a kind of method with realizing for the design of MSN based on WCF.The main function of this software is tentatively to realize based on the real-time Communication for Power in the LAN of WCF, with service-oriented as guiding theory.The design of software includes the design of general module Common.dll, the definition of contract of service IChat and realization, three parts of definition of the callback interface IChatCallback of client.End points(Endpoints)It is the key element that WCF realizes communication, client and service end are all by end points come exchange message, WCFUs are allowed to be that multiple bindings and end points are added in service.End points is by address(Address), binding(Binding)And contract(Contract)Three part compositions, call data to transmit by message exchange come Method Of Accomplishment between client and service, and3 kinds of message exchange patterns defined in WCF.Software development process is divided into:The design of instant messaging service with realize, host design with realize and instant communication client design with realize three parts so that application program has preferable safety, concurrency, extensibility and maintainability.This software on stream, takes full advantage of WCF basic framework and is developing service-oriented Distributed Application.Provide a kind of programmed method and Programming Methodology developing distributed software system based on WCF.
?3 kinds of message exchange patterns defined in WCF.
OneWay:The message that this message exchange pattern can return without waiting service end after call method immediately returns.
Request/Reply:This message exchange pattern belongs to synchronization call.Need to wait the message of service end to return after calling method of servicing.
Duplex:This message exchange pattern has the function of client and service end two-way communication, and its realization simultaneously can also make message exchange have the effect of asynchronism callback.
Shell frame products of new generation under the .NET platform that WCF is released based on SOA as Microsoft are integrated with the advantage of prior art, represent the developing direction of Future Software architecture design and exploitation.Therefore, grasp and can in following application reasonable utilization WCF technology, it is very necessary for being based particularly on for the programmer that micro soft technique is developed for programmer.
After setting up host end end points, equally also it is necessary for the end points that distributed application program defines client, and only when the end points of client is mutually matched with certain end points at host end, the request of client could be listened to by host end.If service provides issue metadata, then utilize .NETThe SvcUtil.exe instrument that Framework 3.0 SDK is provided can easily automatically generate Client Agent corresponding with host end and client configuration file very much.
The design of serviceDesign includes the design of general module Common.dll, the definition of contract of service IChat and realization, three parts of definition of the callback interface IChatCallback of client.General module Common.dll mainly includes the definition to chat person's type Person, and it includes name(The title of chat person or code name)And ImageURL(The store path of the head portrait picture that chat person selects)Two privately owned fields and corresponding attribute access device.Due to PersonType is user-defined dada type it is therefore necessary to add DataContractAttributeCome explicit definition it.
Main inclusion tetra- basic skills of Join, Say, Whisper and Leave in the definition of contract of service IChat.Wherein Join represents:Enter chat;Say represents to all user's broadcasts;WhisperRepresent and message is sent to specified user;Leave represents and leaves chat.ServiceContract attribute need to be added by IChat interface flag is contract of service, due to the function of client to be realized and service end two-way communication, therefore must also arrange CallbackContract parameter, and its parameter IChatCallback is DuplexClient readjustment type under pattern.The definition of the callback interface IChatCallback of client includes tetra- basic skills of UserEnter, Receive, ReceiveWhisper and UserLeave corresponding to Join, Say, Whisper and Leave respectively.UserEnter represents that all chat user receive a corresponding notice when there being new chat user to add;Receive represents the message of receive user broadcast;ReceiveWhisper represents the message that reception associated user sends;UserLeave represents that all chat user receive a corresponding notice when there being chat user to leave.The design of clientThe main inclusion of design of client is realized Client Agent and is realized this three part with configuration file, the realization of callback interface contract of client and client login, Main form, the design of chat window interfaces and code logic.In client configuration file, address, binding, contract are corresponded with the configuration of host end respectively.
The object that main interface mainly uses the Proxy_Singleton type of singleton pattern establishment completes to exit, receive broadcast, the process receiving message and the function of showing chat forms for new user addition, user.
The method that the present invention provides, also certain deficiency, constantly change in needing to put into practice afterwards.