How do you put a message on a queue from C#?

I've created the activity. Now I want to route it to a particular user.

This code runs without effect or exception:

The queuetypecode is 1.

static void Main(string[] args)
{

// strServer should be set with the name of the platform Web server
string strServer = "jasper";

// virtualDirectory should be set with the name of the Microsoft CRM
// virtual directory on the platform Web server
string virtualDirectory = "mscrmservices";
string strDir = "http://" + strServer + "/" + virtualDirectory + "/";

// BizUser proxy object
Microsoft.Crm.Platform.Proxy.BizUser bizUser = new
Microsoft.Crm.Platform.Proxy.BizUser ();
bizUser.Credentials = System.Net.CredentialCache.DefaultCredentials;
bizUser.Url = strDir + "BizUser.srf";

// CRMActivity proxy object
Microsoft.Crm.Platform.Proxy.CRMActivity activity = new
Microsoft.Crm.Platform.Proxy.CRMActivity ();
activity.Credentials = System.Net.CredentialCache.DefaultCredentials;
activity.Url = strDir + "CRMActivity.srf";

string strErrorMsg;
string strActivityId = "{C5D32245-23E1-4298-ADD4-C83034517155}";
string strQueueId = "{F2662B9F-0FF5-4D7E-89B2-356A9EA7D00A}";
try
{
Microsoft.Crm.Platform.Proxy.CUserAuth userAuth = bizUser.WhoAmI();

// Route the activity
activity.Route(userAuth, strActivityId, strQueueId,
Microsoft.Crm.Platform.Proxy.ROUTE_TYPE_CODE.RTC_QUEUE, strQueueId);
}
catch (System.Web.Services.Protocols.SoapException err)
{
// Process the platform error here
strErrorMsg = ("ErrorMessage: " + err.Message + " " + err.Detail.OuterXml +
" Source: " + err.Source );
}
catch (Exception err)
{
// Process other errors here
strErrorMsg = ("ErrorMessage: " + err.Message );
}
}

RE: Programmatically put a message on a queue. by BillAltmann

BillAltmann
Tue May 24 22:49:16 CDT 2005

Got it. CRMActivity.Create puts the task in the current user's WIP Queue.
Then CRMActivity.Route(..., SourceQueue,...,DestinationQueue) moves it where
you want, where SourceQueue = WIP Queue.

Re: Programmatically put a message on a queue. by alan

alan
Wed May 25 23:20:08 CDT 2005

Hi Bill,

activity.Route(myAuth,strActivityId,ownerQueueId,Microsoft.Crm.Platform.Proxy.ROUTE_TYPE_CODE.RTC_QUEUE,strQueueId);

Your syntax looks correct for the routing


This is our full implementation (and i can guarantee that this works...


Set up your Guids (User and QueueOwner - or even THe Queue you want)

try
{
Microsoft.Crm.Platform.Proxy.CUserAuth myAuth = RetreiveAuthUser();


// Set up the XML string for the activity
string strXml = "<activity>";
strXml += "<subject>" + taskTitle + "</subject>";
strXml += "<description>" + taskBody + "</description>";
strXml += "<activitytypecode>134</activitytypecode>";
strXml += "<ownerid type=\"" +
Microsoft.Crm.Platform.Types.ObjectType.otSystemUser.ToString() +
"\">";
strXml += ownerId + "</ownerid>";
strXml += "<objectid>" + salesOrderId + "</objectid>";
strXml += "<objecttypecode>1088</objecttypecode>";
strXml += "</activity>";


// Create the activity
string strActivityId = activity.Create(myAuth, strXml, "");
//string strActivityId = "{3DE19BAE-971F-457C-8EC9-F74AC404BF17}";

Debug.WriteLine("\n\n\nActivity Id:" + strActivityId );

activity.Route(myAuth,strActivityId,ownerQueueId,Microsoft.Crm.Platform.Proxy.ROUTE_TYPE_CODE.RTC_QUEUE,strQueueId);

}
catch (System.Web.Services.Protocols.SoapException err)
{
// Process the platform error here
throw(new Exception("SOAP Exception - RetreiveContract: " +
err.Detail.OuterXml));
}
catch (Exception err)
{
// Process other errors here
throw(new Exception("General Exception - RetreiveContract: " +
err.Message));
}


I hope this helps


Cheers

Alan



Bill Altmann wrote:
> How do you put a message on a queue from C#?
>
> I've created the activity. Now I want to route it to a particular user.
>
> This code runs without effect or exception:
>
> The queuetypecode is 1.
>
> static void Main(string[] args)
> {
>
> // strServer should be set with the name of the platform Web server
> string strServer = "jasper";
>
> // virtualDirectory should be set with the name of the Microsoft CRM
> // virtual directory on the platform Web server
> string virtualDirectory = "mscrmservices";
> string strDir = "http://" + strServer + "/" + virtualDirectory + "/";
>
> // BizUser proxy object
> Microsoft.Crm.Platform.Proxy.BizUser bizUser = new
> Microsoft.Crm.Platform.Proxy.BizUser ();
> bizUser.Credentials = System.Net.CredentialCache.DefaultCredentials;
> bizUser.Url = strDir + "BizUser.srf";
>
> // CRMActivity proxy object
> Microsoft.Crm.Platform.Proxy.CRMActivity activity = new
> Microsoft.Crm.Platform.Proxy.CRMActivity ();
> activity.Credentials = System.Net.CredentialCache.DefaultCredentials;
> activity.Url = strDir + "CRMActivity.srf";
>
> string strErrorMsg;
> string strActivityId = "{C5D32245-23E1-4298-ADD4-C83034517155}";
> string strQueueId = "{F2662B9F-0FF5-4D7E-89B2-356A9EA7D00A}";
> try
> {
> Microsoft.Crm.Platform.Proxy.CUserAuth userAuth = bizUser.WhoAmI();
>
> // Route the activity
> activity.Route(userAuth, strActivityId, strQueueId,
> Microsoft.Crm.Platform.Proxy.ROUTE_TYPE_CODE.RTC_QUEUE, strQueueId);
> }
> catch (System.Web.Services.Protocols.SoapException err)
> {
> // Process the platform error here
> strErrorMsg = ("ErrorMessage: " + err.Message + " " + err.Detail.OuterXml +
> " Source: " + err.Source );
> }
> catch (Exception err)
> {
> // Process other errors here
> strErrorMsg = ("ErrorMessage: " + err.Message );
> }
> }