无法识别的元素'安全性'

时间:2015-01-19 18:34:01

标签: wcf wcf-binding

我编写了一个RESTful WCF服务,该服务又调用第三方SOAP Web服务。

我收到以下错误:无法识别的元素'security'

我的配置文件如下所示:

<?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.Open();

Stacktrace看起来像:

   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

1 个答案:

答案 0 :(得分:3)

绑定声明应如下

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