无法创建相对 URI,因为“uriString”参数表示绝对 URI
本文关键字:URI 参数 表示 uriString 因为 创建 相对 | 更新日期: 2023-09-27 18:35:10
我创建了一个简单的 WCF 服务,该服务承载在 Web 场上。现在,当我有时使用 http://www.example.com/somefolder/file.svc 在浏览器中加载服务时,我会收到以下错误。如果我多次按 F5,那么页面最终会再次出现。
更新 1:我注意到,即使我使用单个Web服务器的IP在浏览器中加载svc,有时也会收到相同的错误消息,有时它可以工作。
无法创建相对 URI,因为"uriString"参数 表示绝对 URI.http://www.example.com/somefolder/file.svc
[UriFormatException: a 无法创建相对 URI,因为"uriString"参数 表示绝对值 URI.http://www.example.com/somefolder/file.svc]
System.ServiceModel.Activation.ApplyHostConfigurationBehavior.ThrowIfAbsolute(Uri URI) +154
System.ServiceModel.Activation.ApplyHostConfigurationBehavior.FailActivationIfEndpointsHaveAbsoluteAddress(ServiceHostBase 服务) +128
System.ServiceModel.Activation.ApplyHostConfigurationBehavior.System.ServiceModel.Description.IServiceBehavior.Validate(ServiceDescription 描述, 服务主机基础服务) +65
System.ServiceModel.Description.DispatcherBuilder.ValidateDescription(ServiceDescription 描述, 服务主机基本服务主机) +161
System.ServiceModel.Description.DispatcherBuilder.InitializeServiceHost(ServiceDescription 描述, 服务主机基本服务主机) +84
System.ServiceModel.ServiceHostBase.InitializeRuntime() +37
System.ServiceModel.ServiceHostBase.OnBeginOpen() +27
System.ServiceModel.ServiceHostBase.OnOpen(TimeSpan timeout) +49
System.ServiceModel.Channels.CommunicationObject.Open(TimeSpan 超时) +261
System.ServiceModel.HostingManager.ActivateService(String 规范化虚拟路径) +121
System.ServiceModel.HostingManager.EnsureServiceAvailable(String 规范化虚拟路径) +479[服务激活异常: 服务 '/somefolder/file.svc' 不能 由于编译期间出现异常而被激活。 例外 消息是:无法创建相对 URI,因为"uriString" 参数表示绝对值 URI.http://www.example.com/somefolder/file.svc.]
System.ServiceModel.AsyncResult.End(IAsyncResult result) +11653822
System.ServiceModel.Activation.HostedHttpRequestAsyncResult.End(IAsyncResult 结果) +194
System.ServiceModel.Activation.HostedHttpRequestAsyncResult.ExecuteSync(HttpApplication 上下文,布尔流上下文)+176
System.ServiceModel.Activation.HttpHandler.ProcessRequest(HttpContext 上下文) +23
System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +181 System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completeSyncally) +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调用的路径中,因此空地址不是问题。
我也没有使用标识节点,但我确实将多个站点绑定启用设置为 true。