Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- open System
- open System.ServiceModel
- open System.ServiceModel.Security
- open System.Security.Cryptography.X509Certificates
- open System.Windows.Forms
- (* Create a window and set a few properties *)
- let form = new Form(Visible=true, TopMost=true, Text="Welcome to F#")
- let login = new TextBox(Location = new Drawing.Point(5, 5), Size = new Drawing.Size(64, 16))
- let pass = new TextBox(Location = new Drawing.Point(80, 5), Size = new Drawing.Size(64, 16))
- let btn = new Button(Location = new Drawing.Point(180, 5), Text="Connect")
- let log = new TextBox(Location = new Drawing.Point(5, 32), Size = new Drawing.Size(256, 64), ReadOnly = true)
- log.Multiline <- true
- let msg = new TextBox(Location = new Drawing.Point(5, 128), Size = new Drawing.Size(256, 64), ReadOnly = true)
- type ChatCallback = class
- new () = {}
- interface IChatCallback with
- member p.Message(who: string, text: string) =
- ()
- //log.AppendText(sprintf "%s: %s\n" who text)
- end
- (* Add the label to the form *)
- form.Controls.Add(login)
- form.Controls.Add(pass)
- form.Controls.Add(btn)
- form.Controls.Add(msg)
- form.Controls.Add(log)
- (* Finally, run the form *)
- let binding = new NetTcpBinding()
- binding.Security.Mode <- SecurityMode.Message
- binding.Security.Message.ClientCredentialType <- MessageCredentialType.UserName
- let client = new ChatClient(new InstanceContext(new ChatCallback()),
- binding,
- new EndpointAddress(new Uri("net.tcp://127.0.0.1/Pochtochat/Chat"),
- EndpointIdentity.CreateDnsIdentity("localhost")))
- client.ClientCredentials.ServiceCertificate.Authentication.CertificateValidationMode <- X509CertificateValidationMode.None
- btn.Click.Add(fun _ ->
- client.ClientCredentials.UserName.UserName <- login.Text
- client.ClientCredentials.UserName.Password <- pass.Text
- client.Open()
- client.Login()
- msg.ReadOnly <- false)
- msg.KeyDown.AddHandler(fun _ (e:KeyEventArgs) ->
- if e.KeyCode = Keys.Return then
- client.SaySomething(msg.Text)
- msg.Clear()
- ())
- do Application.Run(form)
- if client.State = CommunicationState.Opened then
- client.Logout()
- client.Close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement