首页 > 解决方案 > WCF Web.config 错误:“此集合已包含带有方案 http 的地址”

问题描述

首先,我尝试在 web.config 中添加以下代码

 <system.serviceModel> 
         <serviceHostingEnvironment multipleSiteBindingsEnabled="true" /> 
    </system.serviceModel>

但是没有运气,我仍然遇到同样的错误。

然后,我尝试在 web.config 中添加以下代码

 <system.serviceModel> 
         <serviceHostingEnvironment> 
              <baseAddressPrefixFilters> 
                   <add prefix="http://www.YourHostedDomainName.com"/> 
              </baseAddressPrefixFilters> 
         </serviceHostingEnvironment> 
    </system.serviceModel>

但仍然没有运气。现在我收到此错误:

解析器错误消息:在应用程序级别之外使用注册为 allowDefinition='MachineToApplication' 的部分是错误的。

源文件上的错误:D:\Site\Website\service\web.config 行:52

完成 web.config

<?xml version="1.0"?>
<configuration>
  <system.serviceModel>
    <services>
      <service name="DESKNET.Public.TEServices.TEAPI" behaviorConfiguration="DESKNET.Public.TEServices.TEAPIBehaviour" >
        <endpoint address="SOAP" binding="basicHttpBinding" bindingConfiguration="ServiceBindingSOAP" contract="DESKNET.Public.TEServices.ITEAPI" ></endpoint>
        <endpoint address="REST" binding="webHttpBinding" bindingConfiguration="ServiceBindingREST" behaviorConfiguration="webHttpBehaviour" contract="DESKNET.Public.TEServices.ITEAPI" ></endpoint>
      </service>
    </services>
    <behaviors>

      <serviceBehaviors>
        <behavior name="DESKNET.Public.TEServices.TEAPIBehaviour">
          <serviceMetadata httpGetEnabled="true" httpsGetEnabled="false" />
          <serviceDebug includeExceptionDetailInFaults="true"/>
          <serviceCredentials>
            <userNameAuthentication userNamePasswordValidationMode="Custom" customUserNamePasswordValidatorType="DESKNET.Public.TEServices.UserAuthentication, DESKNET"/>
          </serviceCredentials>
        </behavior>
      </serviceBehaviors>
      <endpointBehaviors>
        <behavior name="webHttpBehaviour">
          <webHttp/>
        </behavior>
      </endpointBehaviors>
    </behaviors>
    <bindings>
      <wsHttpBinding>
        <binding name="ServiceBindingSOAP">
          <security mode="Message">
            <transport clientCredentialType="None"/>
            <message clientCredentialType="UserName" />
          </security>
        </binding>
      </wsHttpBinding>
      <basicHttpBinding>
        <binding name="ServiceBindingSOAP"></binding>
      </basicHttpBinding>
      <webHttpBinding>
        <binding name="ServiceBindingREST">
          <security mode="None"></security>
        <!-- </binding> -->
        <!-- </binding> -->
      </webHttpBinding>
    </bindings>
    <serviceHostingEnvironment>
     <baseAddressPrefixFilters> 
         <add prefix="http://YourHostedDomainName.com"/> 
     </baseAddressPrefixFilters> 
  </serviceHostingEnvironment>
  </system.serviceModel>
  <system.webServer>
    <modules runAllManagedModulesForAllRequests="true"/>
  </system.webServer>
</configuration>

标签: c#asp.netwcfiis-7web-config

解决方案


关于错误,请参考我之前的回复,与WCF配置无关。此外,您当前的 WCF 配置有问题。我已经修改过了,请看下文。

<system.serviceModel>
<services>
      <!--replace the name attribute with your service implemented class-->
      <service name="WcfService3.Service1" >
        <!--replace the contract attribute with your service contract-->
        <endpoint address="SOAP" binding="basicHttpBinding" contract="WcfService3.IService1" ></endpoint>
        <endpoint address="REST" binding="webHttpBinding" behaviorConfiguration="webHttpBehaviour" contract="WcfService3.IService1" ></endpoint>
      </service>
    </services>
    <behaviors>
      <serviceBehaviors>
        <behavior>
          <serviceMetadata httpGetEnabled="true" httpsGetEnabled="false" />
          <serviceDebug includeExceptionDetailInFaults="true"/>
        </behavior>
      </serviceBehaviors>
      <endpointBehaviors>
        <behavior name="webHttpBehaviour">
          <webHttp/>
        </behavior>
      </endpointBehaviors>
    </behaviors>
  </system.serviceModel>

它支持Rest样式和SOAP样式 Web 服务。此外,您需要配置证书以启用自定义用户名身份验证。我已在上述代码中将其删除。如果有什么我可以帮忙的,请随时告诉我。</p>


推荐阅读