相对 URI 无法创建,因为 'uriString' 参数表示绝对 URI。

3
我创建了一个简单的WCF服务,并托管在Web农场上。现在,当我使用http://www.example.com/somefolder/file.svc在浏览器中加载服务时,有时候会出现以下错误。如果我多次按F5,页面最终会重新加载。

更新1: 我注意到即使我使用单个Web服务器的IP在浏览器中加载svc,我有时候也会收到相同的错误消息,有时候可以正常工作。

由于'uriString'参数表示的是绝对URI,因此无法创建相对URI。 http://www.example.com/somefolder/file.svc
[UriFormatException: 由于'uriString'参数表示为绝对URI,因此无法创建相对URI。http://www.example.com/somefolder/file.svc]
System.ServiceModel.Activation.ApplyHostConfigurationBehavior.ThrowIfAbsolute(Uri uri) +154
System.ServiceModel.Activation.ApplyHostConfigurationBehavior.FailActivationIfEndpointsHaveAbsoluteAddress(ServiceHostBase service) +128
System.ServiceModel.Activation.ApplyHostConfigurationBehavior.System.ServiceModel.Description.IServiceBehavior.Validate(ServiceDescription description, ServiceHostBase service) +65
System.ServiceModel.Description.DispatcherBuilder.ValidateDescription(ServiceDescription description, ServiceHostBase serviceHost) +161
System.ServiceModel.Description.DispatcherBuilder.InitializeServiceHost(ServiceDescription description, ServiceHostBase serviceHost) +84
System.ServiceModel.ServiceHostBase.InitializeRuntime() +37
System.ServiceModel.ServiceHostBase.OnBeginOpen() +27
System.ServiceModel.ServiceHostBase.OnOpen(TimeSpan timeout) +49
System.ServiceModel.Channels.CommunicationObject.Open(TimeSpan timeout) +261
System.ServiceModel.HostingManager.ActivateService(String normalizedVirtualPath) +121
System.ServiceModel.HostingManager.EnsureServiceAvailable(String normalizedVirtualPath) +479
[ServiceActivationException: 由于编译过程中发生异常,无法激活服务'/somefolder/file.svc'。异常信息为:由于'uriString'参数表示为绝对URI,因此无法创建相对URI。http://www.example.com/somefolder/file.svc.]
System.ServiceModel.AsyncResult.End(IAsyncResult result) +11653822
System.ServiceModel.Activation.HostedHttpRequestAsyncResult.End(IAsyncResult result) +194
System.ServiceModel.Activation.HostedHttpRequestAsyncResult.ExecuteSynchronous(HttpApplication context, Boolean flowContext) +176
System.ServiceModel.Activation.HttpHandler.ProcessRequest(HttpContext context) +23
System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +181 System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +75
我不确定是什么原因导致这种情况。就像我说的那样,我只是在加载服务。我在代码中也没有使用任何URI。该Web服务在三个服务器上使用IIS7.5托管,并将所有内容指向包含WCF文件的共享驱动器。
这是web.config中的部分内容:
<!-- Configuration For File.svc -->
    <system.serviceModel>
        <serviceHostingEnvironment aspNetCompatibilityEnabled="true" />

        <services>
            <service behaviorConfiguration="WebFileService.FileBehavior" name="WebFileService.File">
                <endpoint address="http://www.example.com/somefolder/file.svc" binding="wsHttpBinding" contract="WebFileService.IFile" bindingConfiguration="WSHttpBinding_IFile">
                    <identity>
                        <dns value="localhost" />
                    </identity>
                </endpoint>
                <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
            </service>
        </services>
        <behaviors>
            <serviceBehaviors>
                <behavior name="WebFileService.FileBehavior">
                    <serviceMetadata httpGetEnabled="true" />
                    <serviceDebug includeExceptionDetailInFaults="true" />
                </behavior>
            </serviceBehaviors>
        </behaviors>
        <bindings>
            <wsHttpBinding>
                <binding name="WSHttpBinding_IFile" closeTimeout="00:01:00" openTimeout="00:01:00"
                    receiveTimeout="00:10:00" sendTimeout="00:01:00" bypassProxyOnLocal="false"
                    transactionFlow="false" hostNameComparisonMode="StrongWildcard"
                    maxBufferPoolSize="524288" maxReceivedMessageSize="1000000"
                    messageEncoding="Text" textEncoding="utf-8" useDefaultWebProxy="true"
                    allowCookies="false">
                    <readerQuotas maxDepth="32" maxStringContentLength="99999" maxArrayLength="999999"
                        maxBytesPerRead="4096" maxNameTableCharCount="16384" />
                    <reliableSession ordered="true" inactivityTimeout="00:10:00"
                        enabled="false" />
                    <security mode="None">
                        <transport clientCredentialType="None" proxyCredentialType="None" realm=""/>
                        <message clientCredentialType="None" negotiateServiceCredential="true" algorithmSuite="Default" establishSecurityContext="true"/>
                    </security>
                </binding>
            </wsHttpBinding>
        </bindings>
    </system.serviceModel>

你有检查过你的 web.config 文件吗? - Icepickle
我不知道该如何检查这个。有什么想法吗? - vikasde
@tim 我尝试使用IP,但是出现了相同的行为。有时它可以工作,有时它不能。 - vikasde
有人有什么建议吗? - vikasde
1
很抱歉我没有任何建议,但想分享一下我也在WCF数据服务上看到了这种行为。该服务在共享Web主机上已经运行多年,并且一直正常工作。但是为了进行一些网站更新的准备工作,我已经将该网站迁移到Azure Web应用程序上。当我在本地运行服务时,在IIS Express(VS 2015 RC,只需打开一个网站)中的localhost上,服务可以正常工作,但在Azure Web应用程序中则会出现您所看到的错误消息。 - devhammer
显示剩余2条评论
1个回答

0

我刚遇到了同样的问题,并通过将端点设置为相对地址(我删除了地址属性值,使其成为空字符串 - address =“”)来解决它。我的.svc位于从URL调用的路径中,因此空地址不是问题。

我也没有使用identity节点,但我确实将multipleSiteBindingsEnabled设置为true。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接