Search code examples
wcfwcf-binding

Unrecognized element 'security'


I have written a RESTful WCF service which in turn calls a third party SOAP webservice.

I am getting following error: Unrecognized element 'security'

My config file looks like this:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
<appSettings>
    <add key="DbServer" value=""/>
    <add key="DbName" value=""/>
    <add key="DbUser" value=""/>
    <add key="DbPassword" value=""/>
</appSettings>
<system.serviceModel>
<bindings>
  <basicHttpBinding>
    <binding name="VoicePortalSupportServicesSoap" />
    <security mode="TransportCredentialOnly">
      <transport clientCredentialType="Basic" realm="ctagsd1"/>
    </security>
  </basicHttpBinding>
</bindings>
<client>
  <endpoint address="http://ctagsd1/abc.asmx"
    binding="basicHttpBinding" bindingConfiguration="VoicePortalSupportServicesSoap"
    contract="VoicePortalSupportServices.VoicePortalSupportServicesSoap"
    name="VoicePortalSupportServicesSoapEndpoint" />
</client>
<services>
  <service name="abc">
    <host>
      <baseAddresses>
        <add baseAddress="http://localhost:8787/abc"/>
      </baseAddresses>
    </host>
  </service>
</services>

Host code is minimal. I am getting error on: host.Open();

Stacktrace looks like:

   at System.Configuration.BaseConfigurationRecord.EvaluateOne(String[] keys, SectionInput input, Boolean isTrusted, FactoryRecord factoryRecord, SectionRecord sectionRecord, Object parentResult)
   at System.Configuration.BaseConfigurationRecord.Evaluate(FactoryRecord factoryRecord, SectionRecord sectionRecord, Object parentResult, Boolean getLkg, Boolean getRuntimeObject, Object& result, Object& resultRuntimeObject)
   at System.Configuration.BaseConfigurationRecord.GetSectionRecursive(String configKey, Boolean getLkg, Boolean checkPermission, Boolean getRuntimeObject, Boolean requestIsHere, Object& result, Object& resultRuntimeObject)
   at System.Configuration.BaseConfigurationRecord.GetSectionRecursive(String configKey, Boolean getLkg, Boolean checkPermission, Boolean getRuntimeObject, Boolean requestIsHere, Object& result, Object& resultRuntimeObject)
   at System.Configuration.BaseConfigurationRecord.GetSectionRecursive(String configKey, Boolean getLkg, Boolean checkPermission, Boolean getRuntimeObject, Boolean requestIsHere, Object& result, Object& resultRuntimeObject)
   at System.Configuration.BaseConfigurationRecord.GetSection(String configKey)
   at System.Configuration.ClientConfigurationSystem.System.Configuration.Internal.IInternalConfigSystem.GetSection(String sectionName)
   at System.Configuration.ConfigurationManager.GetSection(String sectionName)
   at System.ServiceModel.Activation.AspNetEnvironment.UnsafeGetSectionFromConfigurationManager(String sectionPath)
   at System.ServiceModel.Activation.AspNetEnvironment.UnsafeGetConfigurationSection(String sectionPath)
   at System.ServiceModel.Configuration.ConfigurationHelpers.UnsafeGetAssociatedSection(ContextInformation evalContext, String sectionPath)
   at System.ServiceModel.Configuration.ConfigurationHelpers.UnsafeGetAssociatedBindingCollectionElement(ContextInformation evaluationContext, String bindingCollectionName)
   at System.ServiceModel.Configuration.ConfigurationHelpers.UnsafeGetBindingCollectionElement(String bindingCollectionName)
   at System.ServiceModel.Description.ConfigLoader.GetBindingCollectionElement(String bindingSectionName, ContextInformation context)
   at System.ServiceModel.Description.ConfigLoader.LookupBinding(String bindingSectionName, String configurationName, ContextInformation context)
   at System.ServiceModel.Description.ConfigLoader.ConfigureEndpoint(StandardEndpointElement standardEndpointElement, ServiceEndpointElement serviceEndpointElement, ContextInformation context, ServiceHostBase host, ServiceDescription description, ServiceEndpoint& endpoint, Boolean omitSettingEndpointAddress)
   at System.ServiceModel.Description.ConfigLoader.LookupEndpoint(ServiceEndpointElement serviceEndpointElement, ContextInformation context, ServiceHostBase host, ServiceDescription description, Boolean omitSettingEndpointAddress)
   at System.ServiceModel.Web.WebServiceHost.AddAutomaticWebHttpBindingEndpoints(ServiceHost host, IDictionary`2 implementedContracts, String multipleContractsErrorMessage, String noContractErrorMessage, String standardEndpointKind)
   at System.ServiceModel.Web.WebServiceHost.OnOpening()
   at System.ServiceModel.Channels.CommunicationObject.Open(TimeSpan timeout)
   at System.ServiceModel.Channels.CommunicationObject.Open()
   at ConsoleHost.Program.Main(String[] args) in c:\code\ConsoleHost\Program.cs:line 20

Solution

  • Binding declaration should be as follows

    <bindings>
      <basicHttpBinding>
        <binding name="VoicePortalSupportServicesSoap">
          <security mode="TransportCredentialOnly">
            <transport clientCredentialType="Basic" realm="ctagsd1"/>
          </security>
        </binding>
      </basicHttpBinding>
    </bindings>