精通
英语
和
开源
,
擅长
开发
与
培训
,
胸怀四海
第一信赖
锐英源精品开源心得,转载请注明:“锐英源www.wisestudy.cn,孙老师作品,电话13803810136。”需要全文内容也请联系孙老师。
The article describes a simple XMPP client application based on the Windows Workflow Foundation, which allows to send and receive messages and also to add and remove contacts from your contact list.
本文介绍了一个基于Windows Workflow Foundation的简单XMPP客户端应用程序,它允许发送和接收消息,还可以添加和删除联系人列表中的联系人。
The Extensible Messaging and Presence Protocol (XMPP) is an open technology for real time communication, using Extensible Markup Language (XML) as the base format for exchanging information. In essence, XMPP provides a way to send small pieces of XML from one entity to another in close to real time.
The XMPP protocol is taken as the RFC standard, and is described by the following documents:
可扩展消息和存在协议(XMPP)是一种用于实时通信的开放技术,使用可扩展标记语言(XML)作为交换信息的基本格式。本质上,XMPP提供了一种近乎实时地将小块XML从一个实体发送到另一个实体的方法。
XMPP协议被视为RFC标准,并由以下文档描述:
Windows Workflow Foundation (WF) is a Microsoft technology for defining, executing, and managing workflows. This technology was first released in November 2006 as a part of .NET Framework 3.0.
WF is a special runtime environment that manages the execution of programs that are composed of resumable program statements. In WF, a resumable program statement is called an Activity. A resumable program is a composition of activities. In WF, such a program is often called a Workflow.
Windows Workflow Foundation(WF)是一种用于定义,执行和管理工作流的Microsoft技术。该技术于2006年11月作为.NET Framework 3.0的一部分首次发布。
WF是一个特殊的运行时环境,用于管理由可恢复的程序语句组成的程序的执行。在WF中,可恢复的程序语句称为活动。可恢复的程序是活动的组合。在WF中,这样的程序通常称为工作流程。
The project consists of two libraries and an XOML-file: JabberClient.dll (root namespace is Jabber.Client), WorkflowActivities.dll (root namespace is Workflow), and Sequence.xml.该项目由两个库和一个XOML文件组成:JabberClient.dll(根名称空间为Jabber.Client),WorkflowActivities.dll(根名称空间为Workflow)和Sequence.xml。
The Jabber.Client namespace includes the types for the XMPP client realization with minimal functionality, which are presented in the following list:
该Jabber.Client命名空间包含类型的XMPP客户端实现以最小的功能,这在下面的列表中提出:
The Worflow namespace includes the set of activities and helper classes which help to specify the program algorithm. You can see the list of main activities below.
Thus, the simple XMPP client's XOML-file is represented below:
该Worflow命名空间包括一系列活动和辅助类,这有助于指定程序算法。您可以在下面看到主要活动列表。
因此,简单的XMPP客户端的XOML文件如下所示:
<Sequence x:Name="root"
xmlns="http://Workflow/Activities"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:wf="http://schemas.microsoft.com/winfx/2006/xaml/workflow">
<Switch x:Name="sw1">
<StateSequence x:Name="Auth" Queue="AuthInputQueue">
<StateSendAndReceive Name="step1_0" AssemblyFile="JabberClient.dll"
SendType="Jabber.Client.Xml.PacketBuilder" SendMethod="AuthStreamHeader"
ReceiveType="Jabber.Client.Xml.PacketParser" ReceiveMethod="AuthStreamHeader1"
Context="{wf:ActivityBind Auth, Path=Context}" />
<StateSendAndReceive Name="step1_1" AssemblyFile="JabberClient.dll"
ReceiveType="Jabber.Client.Xml.PacketParser"
ReceiveMethod="AuthStreamHeader2"
Context="{wf:ActivityBind step1_0, Path=Context}" />
........
</StateSequence>
<Receiver x:Name="Receive" Queue="ReceiveQueue"
AssemblyFile="JabberClient.dll"
ReceiveType="Jabber.Client.Xml.PacketParser"
ReceiveMethod="ResponseMessage" />
<Sender x:Name="Send" Queue="SendQueue"
AssemblyFile="JabberClient.dll"
SendType="Jabber.Client.Xml.PacketBuilder"
SendMethod="ChatMessage"/>
<Sender x:Name="Status" Queue="StatusQueue"
AssemblyFile="JabberClient.dll"
SendType="Jabber.Client.Xml.PacketBuilder"
SendMethod="PresenceShow"/>
<Sender x:Name="Roster" Queue="RosterQueue"
AssemblyFile="JabberClient.dll"
SendType="Jabber.Client.Xml.PacketBuilder"
SendMethod="Roster"/>
<Sender x:Name="Subscribe" Queue="RosterQueue"
AssemblyFile="JabberClient.dll"
SendType="Jabber.Client.Xml.PacketBuilder"
SendMethod="Subscribe"/>
<Sender x:Name="Unsubscribe" Queue="RosterQueue"
AssemblyFile="JabberClient.dll"
SendType="Jabber.Client.Xml.PacketBuilder"
SendMethod="Unsubscribe"/>
</Switch>
</Sequence>
It follows from the XOML-file that the StateSequence activity performs the client authentication on the XMPP-server according to RFC2831. Dynamic binding of the Context property is used in child Activities.
An example of using a simple XMPP-client is shown below:
从XOML文件开始,StateSequence活动根据RFC2831在XMPP服务器上执行客户端身份验证。动态绑定Context属性用于子活动。
使用简单XMPP客户端的示例如下所示:
....
using Jabber.Client;
using Jabber.Client.Core;
....
using (JabberClient jabber =
new JabberClient("jabber.org", "vba32cc", "1234qwer"))
{
//subscribe to events
jabber.Authentificated += new EventHandler(jabber_Authentificated);
jabber.RosterReceived += new RosterHandler(jabber_RosterReceived);
jabber.MessageReceived += new MessageHandler(jabber_MessageReceived);
Console.WriteLine("Authentification...");
jabber.Auth();
string s = Console.ReadLine();
Console.WriteLine("Client state={0}", jabber.State);
while (!string.IsNullOrEmpty(s))
{
if (jabber.State == ClientState.Authentificated)
{
Contact contact = new Contact("", "veleslaff@jabber.ru");
jabber.AddToContacts(contact); //Add to contacts
jabber.SetStatusForContact(contact, UserStatus.Online);//Set status
jabber.Send(contact, s); //Send message
jabber.Contacts(); //Get roster list
}
s = Console.ReadLine();
}
}
....