Not logged in. · Lost password · Register
Forum: MatriX and XmppDotNet RSS
Avatar
Hamid Wakili #1
Member since May 2013 · 6 posts
Group memberships: Members
Show profile · Link to this post
Subject: How To Search For A User
How Do I Search For A User That Is Within My Server using SearchIq ?

I am using OpenFire As My Server And I Have The Search Feature Enabled.

When I Do Use This Method Its Showing Me And Error.

  1. SearchIq sIq = new SearchIq();
  2. sIq.To = new Jid("hamid@hamidserver");
  3. sIq.Type = IqType.get;
  4. xmppClient.Send(sIq);

It Returns This Xml :

  1. <query xmlns="jabber:iq:search" />
  2.  <error code="503" type="cancel">
  3.     <service-unavailable xmlns="urn:ietf:params:xml:ns:xmpp-stanzas" />
  4.  </error>
  5. </query>


Thank You
This post was edited on 2013-05-27, 20:40 by Alex.
Avatar
Alex #2
Member since Feb 2003 · 4449 posts · Location: Germany
Group memberships: Administrators, Members
Show profile · Link to this post
User search needs several steps.
Its described here in XEP-0055: Jabber Search

first you have to figure out the Jid of the user search service on your server. This is done with service discovery. Normally its a subdomain like search.yourserver.com. The search queries get sent to this jid. You can also hardcode the jid when you want.

1) Then you first send a SearchIq of type get to the search service. The service will reply with fields you can search for then. Or an xdata form for the search.
2) based on the reply to 1 you create the search query of type set and sent it to the search service. The service then replies with the search results.

Here is some sampel XML

Query 1:
  1. <iq type='get'    
  2.    to='search.shakespeare.lit'
  3.    id='search1'>
  4.  <query xmlns='jabber:iq:search'/>
  5. </iq>            
  6.  
  7. <iq type='result'
  8.    from='search.shakespeare.lit'
  9.    id='search1'>
  10.  <query xmlns='jabber:iq:search'>
  11.     <instructions>
  12.       Fill in one or more fields to search
  13.       for any matching Jabber users.
  14.     </instructions>
  15.     <first/>
  16.     <last/>
  17.     <nick/>
  18.     <email/>
  19.  </query>
  20. </iq>

Query 2, we submit a search with the last (lastname) field only:
  1. <iq type='set'    
  2.    to='search.shakespeare.lit'
  3.    id='search2'>
  4.  <query xmlns='jabber:iq:search'>
  5.     <last>Capulet</last>
  6.  </query>
  7. </iq>
  8.    
  9.  
  10. <iq type='result'
  11.    from='search.shakespeare.lit'    
  12.    id='search2'>
  13.  <query xmlns='jabber:iq:search'>
  14.     <item jid='juliet@capulet.com'>
  15.       <first>Juliet</first>
  16.       <last>Capulet</last>
  17.       <nick>JuliC</nick>
  18.       <email>juliet@shakespeare.lit</email>
  19.     </item>
  20.     <item jid='tybalt@shakespeare.lit'>
  21.       <first>Tybalt</first>
  22.       <last>Capulet</last>
  23.       <nick>ty</nick>
  24.       <email>tybalt@shakespeare.lit</email>
  25.     </item>
  26.  </query>
  27. </iq>
This post was edited on 2013-05-27, 20:55 by Alex.
Avatar
Hamid Wakili #3
Member since May 2013 · 6 posts
Group memberships: Members
Show profile · Link to this post
Thank You Alot Alex :),

This Is What I Needed

Thanks
Avatar
Hamid Wakili #4
Member since May 2013 · 6 posts
Group memberships: Members
Show profile · Link to this post
In reply to post #2
Alex,

One More Last Thing.

I am using C#

  1. SearchIq sIq = new SearchIq();
  2. sIq.To = "search.nakibfatih";
  3. sIq.Type = IqType.set;
  4.          
  5. sIq.Id = "search1";
  6.            
  7. xmppClient.Send(sIq);

How Do I Set The <last>Capulet</last> In C# ?

Example :
  1. textbox1.text = "What Should Be Here";

Or

  1. var lastquery = "What Should Be Here";


Thank You, Looking forward to your reply.
This post was edited on 2013-05-28, 11:18 by Alex.
Avatar
Alex #5
Member since Feb 2003 · 4449 posts · Location: Germany
Group memberships: Administrators, Members
Show profile · Link to this post
  1. SearchIq sIq = new SearchIq();
  2. sIq.To = "search.nakibfatih";
  3. sIq.Type = IqType.set;
  4.  
  5. // you don't need the next line
  6. // MatriX creates automatically a unique Id for the Iq in the SearchIq class        
  7. sIq.Id = "search1";
  8.  
  9. sIq.Search.Last = "some lastname";
  10.            
  11. xmppClient.Send(sIq);
Avatar
Hamid Wakili #6
Member since May 2013 · 6 posts
Group memberships: Members
Show profile · Link to this post
Thanks Alot Alex :)
You Are A Life Saver :)

Thanks. I Appreciate
Close Smaller – Larger + Reply to this post:
Verification code: VeriCode Please enter the word from the image into the text field below. (Type the letters only, lower case is okay.)
Smileys: :-) ;-) :-D :-p :blush: :cool: :rolleyes: :huh: :-/ <_< :-( :'( :#: :scared: 8-( :nuts: :-O
Special characters: