919.459.6097 info@reso.org  

C# Connection Example

Please read: This example, using libRETS, shows a query pulling all listings with statuses of Active, Active CNT Misc, and Active CNT House, using a Visual Studio 05 (2.0) console application. The query uses system names from the metadata to reference the resource and class items.

Since we needed to pull all listings every day to update the real estate website, and this was impossible in one pull (due to a sort of RETS-imposed governor), we have it batched with the offset. Depending on the time of day, it will pull 300 at a time until it has exhausted the results of the query, and this quantity may differ with the association. A code gen was used to create a class to hold our sql server table fields to easily reference in mapping RETS fields to our db table. You’ll see reference to this in Populate() as “currentlisting.(columnname)”.

In your app.config or equivalent:

<appSettings>
   <clear/>
   <add key="RetsUrl" value="*1"/>
   <add key="RetsUserAgent" value="*2"/>
   <add key="RetsUserName" value="*3" />
   <add key="RetsPassword" value="*4"/>
   <add key="ListingPhotoSavePath" value="C:\Inetpub\wwwroot\homeview\house_photo\"/>
 </appSettings>   

    1 = your association’s login url. you can probably find it here: http://rapmls.com/supp/mls/rets/rets_servers.asp
    2 = user agent should be supplied by the association who purchased the rets server
    3 = user name should be supplied by the association who purchased the rets server
    4 = password should be supplied by the association who purchased the rets server

In the console app (this part is in vb):

Imports System.Configuration
 Imports System.Collections.Generic
 
 Module RetsDownload
 
    <MTAThread()> _ 
    Sub Main()
        Dim url As String = ConfigurationManager.AppSettings("RetsUrl")
        Dim userAgent As String = ConfigurationManager.AppSettings("RetsUserAgent")
        Dim userName As String = ConfigurationManager.AppSettings("RetsUserName")
        Dim pass As String = ConfigurationManager.AppSettings("RetsPassword")
 
 
        Using retsHelper As New RetsHelper(url, userAgent, userName, pass)
             retsHelper.DownloadAllListings()
        End Using
     End Sub

In the C# class associated with the vb console app:

This console application has references set for librets-dotnet.dll, System, System.configuration, System.Data, System.Drawing, System.Transactions, and System.Xml. They may not all apply to the below code. My application also pulls photos, which will be in another post. Also important to note: the librets-pinvoke.dll needs to be in the root of the application, but does not need to be set as a reference. But since it is a C library, and is not COM or .Net compliant, the Copy to Output Directory property of this dll in your Solution Explorer should be set to Copy if newer, so it will be added to either the Debug or Release folder under your bin when the project builds.

Click here C# Connection Example for the code.