简体   繁体   English

WCF Web.config 错误:“此集合已包含一个带有方案 http 的地址”

[英]WCF Web.config Error : “This collection already contains an address with scheme http”

Firstly, I tried adding the below code in web.config首先,我尝试在 web.config 中添加以下代码

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

But no luck I was still getting the same error.但是没有运气,我仍然遇到同样的错误。

Then, I tried adding below code also in web.config然后,我尝试在 web.config 中添加以下代码

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

But still no luck.但仍然没有运气。 Now I am getting this error:现在我收到此错误:

Parser Error Message: It is an error to use a section registered as allowDefinition='MachineToApplication' beyond application level.解析器错误消息:在应用程序级别之外使用注册为 allowDefinition='MachineToApplication' 的部分是错误的。

Erron on Source File: D:\Site\Website\service\web.config Line:52源文件上的错误:D:\Site\Website\service\web.config 行:52

Complete web.config完成 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>

About the error, please refer to my previous reply, It has nothing with WCF configuration.关于错误,请参考我之前的回复,与WCF配置无关。 Besides, there is something wrong with your current WCF configuration.此外,您当前的 WCF 配置有问题。 I have revised it, please refer to below.我已经修改过了,请看下文。

<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>

It supports both Rest style and SOAP style web service.它同时支持Rest样式和SOAP样式 web 服务。 Besides, you need to configure a certificate to enable custom Username authentication.此外,您需要配置证书以启用自定义用户名身份验证。 I have removed it within the above codes.我已在上述代码中将其删除。 Feel free to let me know if there is anything I can help with.如果有什么我可以帮忙的,请随时告诉我。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM