0

I got stuck with creating/registering a new user using jabber.net library in C#. I am using a ejabberd as server. here is my code:

 private void btnCreateAccount_Click(object sender, EventArgs e)
    {
        IQ iq1 = new IQ(jabberClient1.Document);
        iq1.ID = "reg1";
        iq1.Type = IQType.set;
        iq1.InnerXml = "<query xmlns='jabber:iq:register'></query>";
        jabberClient1.Tracker.BeginIQ(iq1, new jabber.connection.IqCB(on_create_user), null);


        IQ iq = new IQ(jabberClient1.Document);
        iq.ID = "reg2";
        iq.Type = IQType.set;
        iq.InnerXml = "<query xmlns='jabber:iq:register'><username>hax0r</username><password>god</password></query>";
        jabberClient1.Tracker.BeginIQ(iq, new jabber.connection.IqCB(on_create_user), null);
    }

    private void on_create_user(object sender, IQ iq, object data)
    {
        Error err = iq.Error;
        if (err != null)
            Console.WriteLine("Error " + err.Condition + " on querying user " + data);
    }

When I run the above code, C# throws an error:

Exception:Thrown: "Object reference not set to an instance of an object." (System.NullReferenceException) A System.NullReferenceException was thrown: "Object reference not set to an instance of an object."

What am I doing wrong? Any help is highly appreciated.

I am still confused how to create a new user with jabber.net in C#. I have done the following but no success yet:

 JabberClient jc = new jabber.client.JabberClient(this.components);
 jc.AutoReconnect = 3F;
 jc.AutoStartCompression = true;
 jc.AutoStartTLS = true;
 jc.InvokeControl = this;
 jc.KeepAlive = 30F;
 jc.LocalCertificate = null;
 jc.Password = "username";
 jc.User = "password";
 jc.Server = "example.com";
 jc.Register(new JID(jc.User, jc.Server, null));

Any hints is highly appreciated.

mjan635
  • 82
  • 10

1 Answers1

1

Please check out the Example directory. MainForm.cs does exactly what you want. In particular, the Register call at line 764, then the callbacks for OnRegisterInfo and OnRegistered.

Joe Hildebrand
  • 9,616
  • 1
  • 32
  • 45
  • Thanks for your reply. I am still confused how to register a new user. Could you please share some codes so that I can do that by providing Username, password, Servername and then I can register a user? – mjan635 Jul 09 '14 at 11:31