報錯信息以下: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 不匹配的問題。」