Advertisement
Yurry

Untitled

Apr 14th, 2011
191
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
F# 1.61 KB | None | 0 0
  1. open System
  2. open System.ServiceModel
  3. open System.ServiceModel.Security
  4. open System.Security.Cryptography.X509Certificates
  5.  
  6. type ChatCallback = class
  7.     new () = {}
  8.     interface IChatCallback with
  9.         member p.Message(who: string, text: string) =
  10.             printfn "%s: %s" who text
  11. end
  12.  
  13. let main =
  14.     let binding = new NetTcpBinding()
  15.     binding.Security.Mode <- SecurityMode.Message
  16.     binding.Security.Message.ClientCredentialType <- MessageCredentialType.UserName
  17.     let client = new ChatClient(new InstanceContext(new ChatCallback()),
  18.                                 binding,
  19.                                 new EndpointAddress(new Uri("net.tcp://127.0.0.1/Pochtochat/Chat"),
  20.                                                     EndpointIdentity.CreateDnsIdentity("localhost")))
  21.     client.ClientCredentials.ServiceCertificate.Authentication.CertificateValidationMode <- X509CertificateValidationMode.None
  22.    
  23.     printfn "Login: "
  24.     client.ClientCredentials.UserName.UserName <- Console.ReadLine()
  25.     printfn "Password: "
  26.     client.ClientCredentials.UserName.Password <- Console.ReadLine()
  27.    
  28.     client.Open()
  29.     client.Login()
  30.    
  31.     printfn "Talk!\n"
  32.    
  33.     let rec say msg = do match msg with
  34.                          | null -> ()
  35.                          | str -> client.SaySomething(str)
  36.                                   say (Console.ReadLine())
  37.                              
  38.     say (Console.ReadLine())
  39.                              
  40.     client.Logout()
  41.     client.Close()
  42.    
  43.     printfn "\n\nPress <ENTER> to terminate client"
  44.     let empty = Console.ReadLine()
  45.     0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement