Reputation: 2146
Am using CLR Trigger to pass the values to WCF,everything works fine but when try to pass the constant value its not pass thru WCF even its not throwing any exception.
CLR Trigger
public partial class Triggers
{
public static EndpointAddress endpoint = new EndpointAddress(new Uri("http://localhost:8000/services/myservice"));
public static WSHttpBinding httpBinding = new WSHttpBinding();
public static ServiceClient.ServiceReference1.ServiceContractClient myclient = new ServiceClient.ServiceReference1.ServiceContractClient(httpBinding, endpoint);
public delegate void MyDelagate(String crudType);
[SqlProcedure()]
[Microsoft.SqlServer.Server.SqlTrigger(Name = "WCFTrigger",
Target = "tbCR", Event = "FOR UPDATE, INSERT")]
public static void Trigger1()
{
SqlCommand cmd;
SqlTriggerContext myContext = SqlContext.TriggerContext;
SqlPipe pipe = SqlContext.Pipe;
SqlDataReader reader;
if(myContext.TriggerAction== TriggerAction.Insert)
{
using (SqlConnection conn = new SqlConnection(@"context connection=true"))
{
conn.Open();
cmd = new SqlCommand(@"SELECT * FROM tbCR", conn);
reader = cmd.ExecuteReader();
reader.Read();
//get the insert value's here
string Name;
Name = reader[1].ToString();
reader.Dispose();
myclient.InsertOccured(Name);
}
}
}
}
}
Interface
namespace SampleService
{
[ServiceContract]
interface IServiceContract
{
[OperationContract]
void UpdateOccured();
[OperationContract]
void InsertOccured(String Name);
}
}
Contract
namespace SampleService
{
class MyService : IServiceContract
{
public void InsertOccured(string Name)
{
Console.WriteLine("Insert Occured",Name);
}
}
}
every time i insert record ,WCF shows "Insert Occured" only but i was expecting "Insert Occured, Test".
Can you please guide me what i suppose to do to get the constant value from SLQ Tirgger.
Upvotes: 0
Views: 135
Reputation: 159
In your service operation implementation is looks like you need to add the string parameter to your Console.WriteLine() string template. In other words:
Console.WriteLine("Insert Occured, {0}",Name);
You can find more about Console.WriteLine and composite formatting here: http://msdn.microsoft.com/en-us/library/828t9b9h.aspx
Upvotes: 1