c# - 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>
解决方案
关于错误,请参考我之前的回复,与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>
推荐阅读
- openedge - 如何通过减少以下代码来提高流程性能?
- apache-spark - 使用 Jackson 2.8 版的 Spark 应用程序与 Apache Spark 1.6 不兼容
- reactjs - 将输入数据保存在异步存储上
- image - tf.image.convert_image_dtype(image, dtype=tf.uint8) 之后的混淆图像
- php - 在 unix cron 中从 php 调用函数
- python - pandas-分类变量的百分比计数
- azure-api-management - APIM 组合节流策略方法
- javascript - TypeError:无法解构“未定义”或“空”的属性“编译”
- c# - 读取 JSON 时意外结束。路径'',第 1 行,位置 1
- ios - 带有儿童语音的 iOS 文本到语音框架