public static void DoSession() { object[] o = null; try { // instantiate web service pubs_endpoint e = new pubs_endpoint(); e.Url = "http://localhost/pubs"; e.sqlSession = new SqlSoapHeader.sqlSession(); e.sqlSession.initiate = true; //e.sqlSession.MustUnderstand = true; //e.sqlSession.timeout = 5; // use security of current client principal e.Credentials = System.Net.CredentialCache.DefaultCredentials; // must define MySoapBroker SERVICE and associated QUEUE in SQL Server e.sqlNotif = new SqlSoapHeader.notificationRequest(); e.sqlNotif.deliveryService = "MySoapBroker"; e.sqlNotif.notificationId = Guid.NewGuid().ToString(); e.sqlNotif.timeout = "10000"; // set up the parameter(s) SqlParameter[] p = null; // invoke parameterized query and return result(s) o = e.sqlbatch("SELECT job_id, job_desc FROM dbo.jobs", ref p); // process array of results ProcessWSResults(o); // invoke parameterized query and return result(s) e.sqlSession.terminate = true; e.sqlSession.timeoutSpecified = false; e.sqlNotif = null; o = e.sqlbatch("", ref p); // process array of results ProcessWSResults(o); // now change a row on SQL Server with a different client // and note a notification is inserted in the queue... } catch (SoapException se) { Console.WriteLine("SoapException:"); Console.WriteLine("Message = {0}", se.Message); Console.WriteLine("Code = {0}", se.Code); Console.WriteLine("Detail message = {0}", se.Detail.OuterXml); } catch (Exception e) { // other exceptions Console.WriteLine(e.GetType().ToString()); } }
public static void DoTransaction() { object[] o = null; try { // instantiate web service pubs_endpoint e = new pubs_endpoint(); e.Url = "http://localhost/pubs"; e.sqlSession = new SqlSoapHeader.sqlSession(); e.sqlSession.initiate = true; //e.sqlSession.MustUnderstand = true; //e.sqlSession.timeout = 5; e.sqlChangeNotif = new SqlSoapHeader.environmentChangeNotifications(); e.sqlChangeNotif.transactionBoundary = true; // use security of current client principal e.Credentials = System.Net.CredentialCache.DefaultCredentials; // set up the parameter(s) SqlParameter[] p = null; // invoke parameterized query and return result(s) o = e.sqlbatch("BEGIN TRAN;INSERT jobs VALUES('Row1', 10, 10)", ref p); // process array of results ProcessWSResults(o); Console.WriteLine(e.sqlSession.sessionId); // use the current session e.sqlSession.initiate = false; e.sqlSession.timeoutSpecified = false; e.sqlSession.transactionDescriptor = g_tx.Descriptor; e.sqlChangeNotif = null; /* or this * System.Byte[] b; * b = e.sqlSession.sessionId; * e.sqlSession = new SqlSoapHeader.sqlSession(); * e.sqlSession.sessionId = b; */ // invoke parameterized query and return result(s) o = e.sqlbatch("INSERT jobs VALUES('Row2', 10, 10)", ref p); // process array of results ProcessWSResults(o); // use the current session e.sqlSession.initiate = false; e.sqlSession.timeoutSpecified = false; e.sqlSession.transactionDescriptor = g_tx.Descriptor; // you don't need this here, it will cause an error // but still get notified, ...strange //e.sqlChangeNotif = new SqlSoapHeader.environmentChangeNotifications(); //e.sqlChangeNotif.transactionBoundary = true; // invoke parameterized query and return result(s) // ROLLBACK TRAN also works as expected o = e.sqlbatch("COMMIT TRAN", ref p); // process array of results ProcessWSResults(o); // invoke parameterized query and return result(s) e.sqlSession.terminate = true; e.sqlSession.timeoutSpecified = false; // Not needed, will cause error //e.sqlSession.transactionDescriptor = g_tx.Descriptor; //e.sqlChangeNotif.transactionBoundary = false; o = e.sqlbatch("", ref p); // process array of results ProcessWSResults(o); } catch (SoapException se) { Console.WriteLine("SoapException:"); Console.WriteLine("Message = {0}", se.Message); Console.WriteLine("Code = {0}", se.Code); Console.WriteLine("Detail message = {0}", se.Detail.OuterXml); } catch (Exception e) { // other exceptions Console.WriteLine(e.GetType().ToString()); } }
public static void DoSession() { object[] o = null; try { // instantiate web service pubs_endpoint e = new pubs_endpoint(); e.Url = "http://localhost/pubs"; e.sqlSession = new SqlSoapHeader.sqlSession(); e.sqlSession.initiate = true; //e.sqlSession.MustUnderstand = true; //e.sqlSession.timeout = 5; // use security of current client principal e.Credentials = System.Net.CredentialCache.DefaultCredentials; // set up the parameter(s) SqlParameter[] p = null; // invoke parameterized query and return result(s) o = e.sqlbatch("INSERT jobs VALUES('Row1', 10, 10)", ref p); // process array of results ProcessWSResults(o); Console.WriteLine(e.sqlSession.sessionId); // use the current session e.sqlSession.initiate = false; e.sqlSession.timeoutSpecified = false; /* or this * System.Byte[] b; * b = e.sqlSession.sessionId; * e.sqlSession = new SqlSoapHeader.sqlSession(); * e.sqlSession.sessionId = b; */ // invoke parameterized query and return result(s) o = e.sqlbatch("INSERT jobs VALUES('Row2', 10, 10)", ref p); // process array of results ProcessWSResults(o); // invoke parameterized query and return result(s) e.sqlSession.terminate = true; e.sqlSession.timeoutSpecified = false; o = e.sqlbatch("", ref p); // process array of results ProcessWSResults(o); } catch (SoapException se) { Console.WriteLine("SoapException:"); Console.WriteLine("Message = {0}", se.Message); Console.WriteLine("Code = {0}", se.Code); Console.WriteLine("Detail message = {0}", se.Detail.OuterXml); } catch (Exception e) { // other exceptions Console.WriteLine(e.GetType().ToString()); } }