Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/backbone.js/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 将值从SQL传递到WCF_C# - Fatal编程技术网

C# 将值从SQL传递到WCF

C# 将值从SQL传递到WCF,c#,C#,我使用CLR触发器将值传递给WCF,一切正常,但当尝试传递常量值时,它不会传递给WCF,甚至不会引发任何异常 CLR触发器 public partial class Triggers { public static EndpointAddress endpoint = new EndpointAddress(new Uri("http://localhost:8000/services/myservice")); public static WSHttpBinding http

我使用CLR触发器将值传递给WCF,一切正常,但当尝试传递常量值时,它不会传递给WCF,甚至不会引发任何异常

CLR触发器

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);
                }
            }
        }

    }
}
接口

namespace SampleService
{
    [ServiceContract]
    interface IServiceContract
    {
        [OperationContract]
        void UpdateOccured();
        [OperationContract]
        void InsertOccured(String Name);
    }
}
合同

namespace SampleService
{
    class MyService : IServiceContract
    {
         public void InsertOccured(string Name)
        {
            Console.WriteLine("Insert Occured",Name);
        }

    }
}
每次我插入记录时,WCF仅显示“插入发生”,但我预期的是“插入发生,测试”


请您指导我如何从SLQ TIRGER获取常量值。

在您的服务操作实现中,似乎需要将字符串参数添加到控制台。WriteLine()字符串模板。换言之:

Console.WriteLine("Insert Occured, {0}",Name);
您可以在此处找到有关Console.WriteLine和复合格式的更多信息: