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

标签 c# wcf

我创建了一个简单的 WCF 服务,它托管在一个网络场上。现在,当我使用 http://www.example.com/somefolder/file.svc 在浏览器中加载服务时,有时我收到以下错误。如果我多次点击 F5,该页面最终会再次出现。

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

A relative URI cannot be created because the 'uriString' parameter represents an absolute URI.http://www.example.com/somefolder/file.svc

[UriFormatException: A relative URI cannot be created because the 'uriString' parameter represents an absolute 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: The service '/somefolder/file.svc' cannot be activated due to an exception during compilation. The exception message is: A relative URI cannot be created because the 'uriString' parameter represents an absolute 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>

最佳答案

我刚刚遇到了同样的问题并修复了它,使端点成为相对地址(我删除了端点节点上的地址属性值,使其成为空字符串 - address="")。我的 .svc 位于从 URL 调用的路径中,因此空地址不是问题。

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

关于c# - 无法创建相对 URI,因为 'uriString' 参数表示绝对 URI,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27640103/

相关文章:

wcf - WCF 如何根据请求决定何时返回 SOAP 还是 JSON?

c# - System.Xml.dll 中发生了类型 'System.Xml.XmlException' 的第一次机会异常

wpf - 有没有一种方法可以在客户端的一个地方处理 WCF 服务器故障?

c# - 在不使用接口(interface)的情况下删除冗余的 C# 代码

c# - 为什么我不能在我的 global.asax 文件夹中添加我的自定义模型联编程序?

c# - 为什么 Windows Phone 7 不完全支持 C# 规范?

c# - 如何使用javascript重定向页面

c# - WCF 自定义验证器 : How to initialize a "User" object from custom validator

c# - iCal 从 API GET AirBnb 返回 "The remote server returned an error: (403) Forbidden"ASP.NET

具有动态表名的 C# 查询