C# – WCF in Partial trust environment

cwcf

I have deployed by WCF to a host and my ASP.NET site is trying to consume the same service.

I get this error:

The Binding with name BasicHttpBinding
failed validation because it contains
a BindingElement with type
System.ServiceModel.Channels.MtomMessageEncodingBindingElement
which is not supported in partial
trust. Consider using
BasicHttpBinding or WSHttpBinding, or
hosting your application in a
full-trust environment. Description:
An unhandled exception occurred during
the execution of the current web
request. Please review the stack trace
for more information about the error
and where it originated in the code.

Exception Details:
System.InvalidOperationException: The
Binding with name BasicHttpBinding
failed valiadation because it contains
a BindingElement with type
System.ServiceModel.Channels.MtomMessageEncodingBindingElement
which is not supported in partial
trust. Consider using BasicHttpBinding
or WSHttpBinding, or hosting your
application in a full-trust
environment.

How do I get around this?

Best Answer

Exactly what it says: do not use MTOM, or host in a full trust environment.

Text message encoding:

<system.serviceModel>
    <bindings>
      <basicHttpBinding>
          <binding name="myBinding" messageEncoding="Text">
          </binding>
      </basicHttpBinding>
    </bindings>
</system.serviceModel>

Most shared hosting providers will only provide partial trust .NET hosting. You will need a (semi-)dedicated machine for full trust, or look around on the internet for a shared hosting provider that wants to risk it.

Related Topic