views:

751

answers:

1

I need to create a user control in either vb.net or c# to search a RightNow CRM database. I have the documentation on their XML API, but I'm not sure how to post to their parser and then catch the return data and display it on the page.

Any sample code would be greatly appreciated!

Link to API: http://community.rightnow.com/customer/documentation/integration/82_crm_integration.pdf

+1  A: 

I don't know RightNow CRM, but according to the documentation you can send the XML requests using HTTP post. The simplest way to do this in .NET is using the WebClient class. Alternatively you might want to take a look at the HttpWebRequest/HttpWebResponse classes. Here is some sample code using WebClient:

using System.Net;
using System.Text;
using System;

namespace RightNowSample
{
    class Program
    {
        static void Main(string[] args)
        {
            string serviceUrl = "http://<your_domain>/cgi-bin/<your_interface>.cfg/php/xml_api/parse.php";
            WebClient webClient = new WebClient();
            string requestXml = 
@"<connector>
<function name=""ans_get"">
<parameter name=""args"" type=""pair"">
<pair name=""id"" type=""integer"">33</pair>
<pair name=""sub_tbl"" type='pair'>
<pair name=""tbl_id"" type=""integer"">164</pair>
</pair>
</parameter>
</function>
</connector>";

            string secString = "";
            string postData = string.Format("xml_doc={0}, sec_string={1}", requestXml, secString);
            byte[] postDataBytes = Encoding.UTF8.GetBytes(postData);

            byte[] responseDataBytes = webClient.UploadData(serviceUrl, "POST", postDataBytes);
            string responseData = Encoding.UTF8.GetString(responseDataBytes);

            Console.WriteLine(responseData);
        }
    }
}

I have no access to RightNow CRM, so I could not test this, but it can serve as s tarting point for you.

csgero