在访问本地IIS托管的WCF服务时出现错误:“此操作不支持相对URI。”

4

我在从Web浏览器访问WCF服务时遇到了“此操作不支持相对URI。”的错误。该服务托管在本地IIS上,以下是其配置:

<system.serviceModel>
    <!-- change -->
    <bindings>
      <customBinding>
        <binding name="Wrabind" closeTimeout="00:05:00" openTimeout="00:05:00" sendTimeout="00:25:00">
          <textMessageEncoding/>
          <security authenticationMode="SecureConversation" includeTimestamp="true" messageSecurityVersion="WSSecurity11WSTrustFebruary2005WSSecureConversationFebruary2005WSSecurityPolicy11BasicSecurityProfile10">
            <localClientSettings maxClockSkew="00:30:00" />
            <localServiceSettings maxClockSkew="00:30:00" />
            <secureConversationBootstrap messageSecurityVersion="WSSecurity11WSTrustFebruary2005WSSecureConversationFebruary2005WSSecurityPolicy11BasicSecurityProfile10">
              <localClientSettings maxClockSkew="00:30:00" />
              <localServiceSettings maxClockSkew="00:30:00" />
            </secureConversationBootstrap>
          </security>
          <httpTransport maxBufferPoolSize="20000000" maxReceivedMessageSize="20000000" allowCookies="true" maxBufferSize="20000000" keepAliveEnabled="false" />
        </binding>
      </customBinding>
    </bindings>
<services>
      <service behaviorConfiguration="wrCoreService.Service1Behavior" name="wrCoreService.Service1">
        <endpoint address="http://localhost/service1.svc" binding="customBinding" bindingConfiguration="Wrabind" contract="wrCoreService.IService1" />
        <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
      </service>
    </services>
    <behaviors>
      <serviceBehaviors>
        <behavior name="wrCoreService.Service1Behavior">
          <serviceThrottling
maxConcurrentCalls="200"
maxConcurrentSessions="200"
maxConcurrentInstances="200" />
          <!-- To avoid disclosing metadata information, set the value below to false before deployment -->
          <serviceMetadata httpGetEnabled="false" />
          <!-- change -->
          <!--<serviceCredentials>
            <userNameAuthentication userNamePasswordValidationMode="Custom" customUserNamePasswordValidatorType="wrCoreService.Authentication.DistributorValidator, wrCoreService"/>
            <serviceCertificate findValue="wrCoreService" storeLocation="LocalMachine" storeName="TrustedPeople" x509FindType="FindBySubjectName"/>
          </serviceCredentials>-->
          <!-- change -->
          <!-- To receive exception details in faults for debugging purposes, set the value below to true.  Set to false before deployment to avoid disclosing exception information -->
          <serviceDebug includeExceptionDetailInFaults="true" />

        </behavior>
      </serviceBehaviors>
    </behaviors>
    <serviceHostingEnvironment>
      <baseAddressPrefixFilters>
        <add prefix="localhost/" />
      </baseAddressPrefixFilters>
    </serviceHostingEnvironment>
    <!--<standardEndpoints>
      <webHttpEndpoint>
        <standardEndpoint name="" helpEnabled="true"
          automaticFormatSelectionEnabled="true"/>
      </webHttpEndpoint>
    </standardEndpoints>-->

  </system.serviceModel>
4个回答

0

错误提示说明您只能使用绝对URI而不是相对URI。尝试使用绝对URI而不是localhost/

<baseAddressPrefixFilters>
  <add prefix="localhost/" />
</baseAddressPrefixFilters>

那么本地主机的绝对URI是什么?因为我尝试过localhostlocalhost:80\,但都不起作用。 - Aishwarya Shiva

0
试试这个:

<serviceHostingEnvironment> <baseAddressPrefixFilters>
<add prefix="http://localhost/" />
</baseAddressPrefixFilters>
</serviceHostingEnvironment>


不行,我已经尝试过了,它不起作用。它显示“无法找到与绑定MetadataExchangeHttpBinding的端点匹配的基地址方案http。注册的基地址方案为[]。”异常。 - Aishwarya Shiva
@AishwaryaShiva 在您提到的端点中,将bindingconfiguration命名为“Wrabind”,但在您的配置中,我没有看到任何与“Wrabind”相关的绑定配置。请完整发布您的配置信息。 - Abhinay
@AishwaryaShiva:你是通过代码还是配置文件来创建自定义绑定的?请提供完整信息,否则没有人能够通过不完整的信息回答你的问题。 - Abhinay
好的,我想现在清楚了,我正在使用配置文件来创建绑定。那么在这种情况下,我该如何解决我的问题呢? - Aishwarya Shiva
如果您正在使用配置文件创建自定义绑定,则配置文件中应该有<extensions> <bindingExtensions>条目,但我在您的配置文件中没有看到任何条目。这些条目是必需的,否则它将无法识别您的自定义绑定。 - Abhinay
我认为缺少这个元素不会产生任何影响。但是我尝试添加了以下元素,如下所示: 但是没有效果。仍然出现相同的错误。 - Aishwarya Shiva

0

正如Abhinay所说,你需要在前缀中加上http://才能使其成为一个完全合格的URI(这需要一个方案)。所以我建议尝试:

http://localhost(没有尾随斜杠)

或者

http://127.0.0.1

或者

http://your-machine-name.domain.whatever

如果你使用的是非标准端口,还可以尝试包含端口号(例如:http://localhost:8080)。

最后,你的终点标签可能实际上需要一个相对路径来指定地址(我之前见过这种情况),所以:

<service behaviorConfiguration="wrCoreService.Service1Behavior" name="wrCoreService.Service1">
    <endpoint address="service1.svc" binding="customBinding" bindingConfiguration="Wrabind" contract="wrCoreService.IService1" />
    <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
</service>

无法工作。它显示相同的错误或“找不到与绑定MetadataExchangeHttpBinding的端点匹配的基地址方案http。注册的基地址方案为[]。” - Aishwarya Shiva

0

baseAddressPrefixFilters 不识别“localhost”,请使用完全限定的机器名。

这是源代码


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