1: public void SendMsgToSSB()
2: { SqlTransaction tran = null;
3: SqlConnection conn = null;
4: Conversation dialog = null;
5: Service client = null;
6: string ConnectionString = "Persist Security Info = False; Integrated Security = True; Initial Catalog = MyServiceBrokerDB; Data Source = .; Connect Timeout = 30;";
7: try
8: {
9: conn = new SqlConnection(ConnectionString);
10: if (conn.State != ConnectionState.Open)
11: {
12: conn.Open();
13: }
14: if (Transaction.Current != null)
15: {
16: conn.EnlistTransaction(Transaction.Current);
17: }
18: else
19: {
20: tran = conn.BeginTransaction();
21: }
22:
23: // Create a service object
24: client = new Service("MyCoolService", conn, null);
25: client.FetchSize = 1;
26:
27: // Begin a dialog with the MyCoolService
28: dialog = client.BeginDialog(
29: "MyCoolServiceTarget", null, "DEFAULT",
30: TimeSpan.FromMinutes(1), false, conn, null);
31:
32: // Create request message
33: string outgoingBody = "my really cool msg that broker understands";
34: Message request = new Message("DEFAULT",
35: new MemoryStream(Encoding.UTF8.GetBytes(outgoingBody)));
36:
37: dialog.Send(request, conn, null);
38: dialog.End(conn, null);
39: if (tran != null)
40: {
41: tran.Commit();
42: }
43: }
44: catch (ServiceException ex)
45: { //deal with the exception
46: }
47: finally
48: { //clean up
49: }
50: }