Software & Finance

Visual Studio.NET - WCF Exception in Partial Trust Environment


Here is the information on how to fix WCF exception with partial trust environment.


It is quite common to see the error when you host your WCF service in partial trust environment with wsHttpBinding. If you do so, the web browser will display the following error message:


 [InvalidOperationException: The WSHttpBinding with name WSHttpBinding failed validation because it contains a BindingElement with type System.ServiceModel.Channels.SymmetricSecurityBindingElement which is not supported in partial trust. Consider disabling the message security and reliable session options, using BasicHttpBinding, or hosting your application in a full-trust environment.]


To fix the error, you can change the binding type in your web.config file to basicHttpsBinding as shown below:



      <service name="Wcf_Test_Service.TestService" behaviorConfiguration="MyServiceTypeBehaviors">

        <endpoint address=""




                 contract="Wcf_Test_Service.ITestService" >


        <endpoint address="mex"


                  contract="IMetadataExchange" />





Also note that if you want to see the errors on the client side, you need to have the following settings customError mode = off in your web.config file



      <customErrors mode="Off"/> 

      <!-- customErrors mode="RemoteOnly" -->