报错信息以下:web
Server Error in '/MyWcfService' Application.ide
When 'system.serviceModel/serviceHostingEnvironment/multipleSiteBindingsEnabled' is set to true in configuration, the endpoints are required to specify a relative address. If you are specifying a relative listen URI on the endpoint, then the address can be absolute. To fix this problem, specify a relative uri for endpoint 'http://127.0.0.1/MyWcfService/Calculatorservice.svc'.ui
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.this
Exception Details: System.InvalidOperationException: When 'system.serviceModel/serviceHostingEnvironment/multipleSiteBindingsEnabled' is set to true in configuration, the endpoints are required to specify a relative address. If you are specifying a relative listen URI on the endpoint, then the address can be absolute. To fix this problem, specify a relative uri for endpoint 'http://127.0.0.1/MyWcfService/Calculatorservice.svc'.spa
Source Error:code
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.orm
Stack Trace:blog
[InvalidOperationException: When 'system.serviceModel/serviceHostingEnvironment/multipleSiteBindingsEnabled' is set to true in configuration, the endpoints are required to specify a relative address. If you are specifying a relative listen URI on the endpoint, then the address can be absolute. To fix this problem, specify a relative uri for endpoint 'http://127.0.0.1/MyWcfService/Calculatorservice.svc'.]
System.ServiceModel.Activation.ApplyHostConfigurationBehavior.ThrowIfAbsolute(Uri uri) +143946
System.ServiceModel.Activation.ApplyHostConfigurationBehavior.FailActivationIfEndpointsHaveAbsoluteAddress(ServiceHostBase service) +153
System.ServiceModel.Description.DispatcherBuilder.ValidateDescription(ServiceDescription description, ServiceHostBase serviceHost) +391
System.ServiceModel.Description.DispatcherBuilder.InitializeServiceHost(ServiceDescription description, ServiceHostBase serviceHost) +334
System.ServiceModel.ServiceHostBase.InitializeRuntime() +82
System.ServiceModel.ServiceHostBase.OnOpen(TimeSpan timeout) +64
System.ServiceModel.Channels.CommunicationObject.Open(TimeSpan timeout) +789
System.ServiceModel.HostingManager.ActivateService(String normalizedVirtualPath) +255
System.ServiceModel.HostingManager.EnsureServiceAvailable(String normalizedVirtualPath) +1172ip
[ServiceActivationException: The service '/MyWcfService/Calculatorservice.svc' cannot be activated due to an exception during compilation. The exception message is: When 'system.serviceModel/serviceHostingEnvironment/multipleSiteBindingsEnabled' is set to true in configuration, the endpoints are required to specify a relative address. If you are specifying a relative listen URI on the endpoint, then the address can be absolute. To fix this problem, specify a relative uri for endpoint 'http://127.0.0.1/MyWcfService/Calculatorservice.svc'..]
System.Runtime.AsyncResult.End(IAsyncResult result) +900576
System.ServiceModel.Activation.HostedHttpRequestAsyncResult.End(IAsyncResult result) +193150
System.Web.AsyncEventExecutionStep.OnAsyncEventCompletion(IAsyncResult ar) +107ci
配置文件:
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" /> <behaviors> <serviceBehaviors> <behavior name="metadataBehavior"> <serviceMetadata httpGetEnabled="true" /> </behavior> <behavior name=""> <serviceMetadata httpGetEnabled="true" /> <serviceDebug includeExceptionDetailInFaults="false" /> </behavior> </serviceBehaviors> </behaviors> <services> <service behaviorConfiguration="metadataBehavior" name="MyWcf.MyWcfService.CalculatorService"> <endpoint address="http://localhost:2821/Calculatorservice.svc" binding="wsHttpBinding" contract="MyWcf.MyWcfContracts.ICalculator"/> </service> <service behaviorConfiguration="metadataBehavior" name="MyWcf.MyWcfService.DealWithFault"> <endpoint address="http://localhost:2821/DealWithFault.svc" binding="wsHttpBinding" contract="MyWcf.MyWcfContracts.IDealWithFault"/> </service> </services>
根据报错提示,在启用multipleSiteBindingsEnabled="true"的状况下,须要为终结点指定相对uri。
给定终结点地址一个base address:
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" /> <behaviors> <serviceBehaviors> <behavior name="metadataBehavior"> <serviceMetadata httpGetEnabled="true" /> </behavior> <behavior name=""> <serviceMetadata httpGetEnabled="true" /> <serviceDebug includeExceptionDetailInFaults="false" /> </behavior> </serviceBehaviors> </behaviors> <services> <service behaviorConfiguration="metadataBehavior" name="MyWcf.MyWcfService.CalculatorService"> <endpoint binding="wsHttpBinding" contract="MyWcf.MyWcfContracts.ICalculator"/> <host> <baseAddresses> <!--将service发布到IIS上的配置,需配置IIS虚拟目录,例如:MyWcfService--> <!--<add baseAddress="http://localhost/MyWcfService/Calculatorservice.svc"/>--> <!--将service发布到VS web deployment上的配置,项目-Property设置了虚拟目录“/”,若是发布在http://localhost/MyWcfService下,须要设置虚拟目录为“/MyWcfService”--> <add baseAddress="http://localhost:2821/Calculatorservice.svc"/> </baseAddresses> </host> </service> <service behaviorConfiguration="metadataBehavior" name="MyWcf.MyWcfService.DealWithFault"> <endpoint binding="wsHttpBinding" contract="MyWcf.MyWcfContracts.IDealWithFault"/> <host> <baseAddresses> <!--将service发布到VS web deployment上的配置--> <add baseAddress="http://localhost:2821/DealWithFault.svc"/> </baseAddresses> </host> </service> </services>
具体WCF的地址拼接方法相关缘由可参照:http://social.msdn.microsoft.com/Forums/en-US/ef113ca3-4636-4031-b9de-f651dce07b76/wcfiis
以下:
“address在终结点里,简单理解就是地址,终结点地址。
你能够配置address为相对,也能够是所有完整格式的地址。当你有基地址时,这里能够使用相对地址,终结点的地址就是 基地址+相对地址。
当你使用完整的地址格式,那终结点地址就不会使用 基地址+相对地址。
IIS部署的时候,默认会有一个基地址Baseaddress,这个是根据你WCF服务程序的配置生成的。
若是你打算提供完成的地址格式,可是这个完成的地址格式 和Baseaddress 不匹配,好比端口不同,就会出错。
address换成“”,目的就是使用默认的Baseaddress+“”。避免了你本身设置的和Baseaddress 不匹配的问题。”