Using ServiceBrokerInterface!!!
Apr 2, 2007
How can we create a stored procedure (or Trigger) to make it send a message to an outside program, then the program process and return the message to the stored procedure by using ServiceBrokerInterface (an sample library code in MSDN 2005)??? Really need help! Thanks
View 1 Replies
Feb 15, 2007
Why would you want to suppress messages like CA1062:ValidateArgumentsOfPublicMethods? In a production system we wouldn't do this sort of thing, right? Was this just a shortcut, to save the developers the trouble of checking for null?
View 1 Replies
View Related
Oct 31, 2006
Using conversation timers, I would like to send a message to myself. I could then use the self-addressed message to check on the availability of a provider. What would be the recommended approach for doing this using the ServiceBrokerInterface? It seems that I might need to add a method to the Service class. Is it correct? Thanks,
View 1 Replies
View Related
Jan 25, 2008
I have been using the ServiceBrokerInterface example for a project of mine and so far it has been very successfull. However , I recently attempted to use it to send a large-ish message (32K xml file from MS Word) to SQL. The message is recieved but the Body member of the message is null when I try to retrieve the data from within my stored procedure CLR method.
The only differences I can see between the message that does not work and those that do are that the one that doesn't is large and it is XML data that I read from a .xml file produced by MS Word as opposed to internally generated strings in the other working messages.
Does anybody have any suggestions as to why the body of the message is not being sent in this case?
Is there something about the example code that precludes sending this type of message?
This is the code that sends the message (extracted from Conversation.cs in ServiceBrokerExample)
string query = "SEND ON CONVERSATION @ch MESSAGE TYPE @mt ";
param = cmd.Parameters.Add("@ch", SqlDbType.UniqueIdentifier);
param.Value = m_handle;
param = cmd.Parameters.Add("@mt", SqlDbType.NVarChar, 255);
param.Value = message.Type;
if (message.Body != null)
{
query += " (@msg)";
param = cmd.Parameters.Add("@msg", SqlDbType.VarBinary);
param.Value = new SqlBytes(message.Body);
param.Size = -1;
}
cmd.CommandText = query;
cmd.ExecuteNonQuery();
This is the code that reads the message from the SQL queue (extracted from Message.cs in ServiceBrokerExample)
m_reader = reader;
m_convGroupId = reader.GetGuid(0);
m_conv = new Conversation(service, reader.GetGuid(1));
m_sequenceNumber = reader.GetInt64(2);
m_serviceName = reader.GetString(3);
m_contractName = reader.GetString(4);
m_type = reader.GetString(5);
m_validation = reader.GetString(6);
if (!reader.IsDBNull(7))
{
SqlBytes sb = reader.GetSqlBytes(7);
Body = sb.Stream;
}
else
Body = null;
This is the MESSAGE TYPE used by this message.
CREATE MESSAGE TYPE CreateReport_Command VALIDATION = None;
Here is the code where msgReceived.Body == null in the SQL CLR method invoked by this message.
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1062:ValidateArgumentsOfPublicMethods"), System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1822:MarkMembersAsStatic"), BrokerMethod("AssessmentContract", "CreateReport_Command")]
public void CreateReport_Command(
Message msgReceived,
SqlConnection connection,
SqlTransaction transaction)
{
StreamReader reader = null;
try
{
reader = new StreamReader(msgReceived.Body);
And finally here is the code snippet that creates the stream that gets loaded into the message to be sent.
if (Report != null && ReportName != null)
{
MemoryStream ReportBody = new MemoryStream();
if (ReportID == null)
{
ReportID = Guid.NewGuid().ToString();
}
ReportBody.Write(Encoding.ASCII.GetBytes(ReportID), 0, ReportID.Length);
ReportBody.Write(Encoding.ASCII.GetBytes("|".ToCharArray()), 0, 1);
ReportBody.Write(Encoding.ASCII.GetBytes(ReportName), 0, ReportName.Length);
ReportBody.Write(Encoding.ASCII.GetBytes("|".ToCharArray()), 0, 1);
ReportBody.Write(Encoding.ASCII.GetBytes(Report), 0, Report.Length);
Microsoft.Samples.SqlServer.Message request = new Microsoft.Samples.SqlServer.Message("CreateAssessmentReport_Command", ReportBody);
// Send the message to the service
dialog.Send(request, conn, tran);
View 1 Replies
View Related