Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7670717
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T15:53:11+00:00 2026-05-31T15:53:11+00:00

I have a CLR SQL Trigger, that tries to communicate with a WCF service

  • 0

I have a CLR SQL Trigger, that tries to communicate with a WCF service on the basis of the following article

When I try to update/insert a record, I get the following exception:

No row was updated.    
The data in row 1 was not committed.    
Error Source: .Net SqlClient Data Provider.    
Error Message: A .NET Framework error occured during execution of a user-defined routine or aggregate "WCFTrigger": System.Security.HostProtectionException: Attempt to perform an operation that was forbidden by the CLR host.    
The protected resource (only available with full trust) where: All    
The demanded resources were: Synchronization, ExternalThreading    
System.Security.HostProtectionException:    
  at System.ServiceModel.Description.TypeLoader.LoadContractDescriptionHelper(Type ContactType, Type ServiceType, Object serviceImplementation)    
  at System.ServiceModel.ChannelFactory '1.CreateDescription()    
  at System.ServiceModel.ChannelFactory.InitializeEndpoint(Binding binding, 
EndpointAddress address)    
  at System.ServiceModel.ChannelFactory '1..ctor(Binding binding, EndpointAddress address)    
  at System.ServiceModel.ClientBase '1..ctor(Binding binding, EndpointAddress address)    
  at ServiceClient.WCFServiceReference.ServiceContractClient..ctor(Binding binding, 
EndpointAddress address)

The host is just like in the article, the client’s app.config:

<?xml version="1.0"?>
<configuration>
    <system.serviceModel>
        <bindings>
            <wsHttpBinding>
                <binding name="WSHttpBinding_IServiceContract" closeTimeout="00:01:00" openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00" bypassProxyOnLocal="false" transactionFlow="false" hostNameComparisonMode="StrongWildcard" maxBufferPoolSize="524288" maxReceivedMessageSize="65536" messageEncoding="Text" textEncoding="utf-8" useDefaultWebProxy="true" allowCookies="false">
                    <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384" maxBytesPerRead="4096" maxNameTableCharCount="16384"/>
                    <reliableSession ordered="true" inactivityTimeout="00:10:00" enabled="false"/>
                    <security mode="Message">
                        <transport clientCredentialType="Windows" proxyCredentialType="None" realm=""/>
                        <message clientCredentialType="Windows" negotiateServiceCredential="true" algorithmSuite="Default"/>
                    </security>
                </binding>
            </wsHttpBinding>
        </bindings>
        <client>
            <endpoint address="http://localhost:8000/services/MyService" binding="wsHttpBinding" bindingConfiguration="WSHttpBinding_IServiceContract" contract="WCFServiceReference.IServiceContract" name="WSHttpBinding_IServiceContract">
                <identity>
                    <userPrincipalName value="xxx@yyy.zzzt"/>
                </identity>
            </endpoint>
        </client>
    </system.serviceModel>
<startup><supportedRuntime version="v2.0.50727"/></startup></configuration>

Has anybody any idea, what is that and why?


The code of the trigger:

public partial class Triggers {
    [SqlProcedure()]
    public static void SendData( String crudType ) {
        EndpointAddress endpoint = new EndpointAddress( new Uri( "http://localhost:8000/services/myservice" ) );
        WSHttpBinding httpBinding = new WSHttpBinding();
        ServiceClient.WCFServiceReference.ServiceContractClient  myClient = new ServiceClient.WCFServiceReference.ServiceContractClient( httpBinding, endpoint );

            switch( crudType ) {
                case "Update":
                    myClient.UpdateOccured();
                    break;
                case "Insert":
                    myClient.InsertOccured();
                    break;
        }
    }

    [Microsoft.SqlServer.Server.SqlTrigger( Name = "WCFTrigger",
       Target = "tbCR", Event = "FOR UPDATE, INSERT" )]
    public static void Trigger1() {
        SqlTriggerContext myContext = SqlContext.TriggerContext;

        switch( myContext.TriggerAction ) {
            case TriggerAction.Update:
                SendData( "Update" );
                break;
            case TriggerAction.Insert:
                SendData( "Insert" );
                break;
        }
    }
}

The proxy:

namespace ServiceClient.WCFServiceReference {
    [System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "4.0.0.0")]
    [System.ServiceModel.ServiceContractAttribute(ConfigurationName="WCFServiceReference.IServiceContract")]
    public interface IServiceContract {

        [System.ServiceModel.OperationContractAttribute(Action="http://tempuri.org/IServiceContract/UpdateOccured", ReplyAction="http://tempuri.org/IServiceContract/UpdateOccuredResponse")]
        void UpdateOccured();

        [System.ServiceModel.OperationContractAttribute(Action="http://tempuri.org/IServiceContract/InsertOccured", ReplyAction="http://tempuri.org/IServiceContract/InsertOccuredResponse")]
        void InsertOccured();
    }

    [System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "4.0.0.0")]
    public interface IServiceContractChannel : ServiceClient.WCFServiceReference.IServiceContract, System.ServiceModel.IClientChannel {
    }

    [System.Diagnostics.DebuggerStepThroughAttribute()]
    [System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "4.0.0.0")]
    public partial class ServiceContractClient : System.ServiceModel.ClientBase<ServiceClient.WCFServiceReference.IServiceContract>, ServiceClient.WCFServiceReference.IServiceContract {

        public ServiceContractClient() {
        }

        public ServiceContractClient(string endpointConfigurationName) : 
                base(endpointConfigurationName) {
        }

        public ServiceContractClient(string endpointConfigurationName, string remoteAddress) : 
                base(endpointConfigurationName, remoteAddress) {
        }

        public ServiceContractClient(string endpointConfigurationName, System.ServiceModel.EndpointAddress remoteAddress) : 
                base(endpointConfigurationName, remoteAddress) {
        }

        public ServiceContractClient(System.ServiceModel.Channels.Binding binding, System.ServiceModel.EndpointAddress remoteAddress) : 
                base(binding, remoteAddress) {
        }

        public void UpdateOccured() {
            base.Channel.UpdateOccured();
        }

        public void InsertOccured() {
            base.Channel.InsertOccured();
        }
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T15:53:12+00:00Added an answer on May 31, 2026 at 3:53 pm

    The issue is caused running .NET code (WCF client calling service) in SQL Server under a partial trust code access security (CAS) setting. Look at the this MSDN article on configuring CAS for SQL Server.

    EDIT:

    As an alternative to enabling full trust, configure a webHttpBinding endpoint on the WCF service. Call the service using the System.Net HttpWebRequest & HttpWebResponse classes to avoid using the WCF ChannelFactory based plumbing.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a SQL-CLR trigger in SQL Server 2008 that sends out message to
I have a SQL CLR function that receives a SQLString, and I am converting
I have a code library that works in ASP.NET, the SQL CLR, and stand-alone
I'm new to SQL CLR programmability. I have a CLR stored procedure that writes
I have written the following piece of code ( sql clr stored procedure )
I have a basic doubt that, How can we have both CLR's on a
We have a MFC 8 application compiled with /CLR that contains a larger amount
I have written the following IronPython code: import clr clr.AddReference(System.Drawing) from System import *
I have created an Excel 2003 add-in that uses the CLR 2.0 and this
From a previous question I have seen that the CLR has workstation and server

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.