WCF无法使用REST服务找到http的基地址 [英] WCF cannot find base address for http using REST service

查看:130
本文介绍了WCF无法使用REST服务找到http的基地址的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

尝试在IIS 6.0上运行我的REST WCF服务时,我看到WCF发出以下错误:

I'm seeing the following error coming from WCF when trying to hit my REST WCF service on IIS 6.0:

找不到与绑定WebHttpBinding的端点的方案http匹配的基地址.注册的基址方案为[].

Could not find a base address that matches scheme http for the endpoint with binding WebHttpBinding. Registered base address schemes are [].

我的web.config看起来像:

My web.config looks like:

<system.serviceModel>
<serviceHostingEnvironment>
  <baseAddressPrefixFilters>
    <!--LOCAL-->
    <add prefix="http://localhost/CustomTrackingService/CustomTrackingService.svc"/>
    <!--TEST-->
    <!--<add prefix="http://mytestserver/CustomTrackingService/CustomTrackingService.svc"/>-->
  </baseAddressPrefixFilters>
</serviceHostingEnvironment>
<services>
  <service name="MyService.CustomTrackingService">
    <endpoint 
      address="MyAction" 
      binding="webHttpBinding" 
      contract="MyContract.ICustomTrackingService" 
      behaviorConfiguration="RestBehavior" />
  </service>
</services>
<behaviors>
  <endpointBehaviors>
    <behavior name="RestBehavior">
      <webHttp />
    </behavior>
  </endpointBehaviors>
</behaviors>

这在我的测试服务器上运行良好,并且在我让Casini抓取它的情况下在本地运行良好(将基本地址前缀localhost/CustomTrackingService更改为localhost:1234/).我不记得是什么原因导致了这种情况的发生,而且我的Google-fu无法产生有用的结果.有什么想法吗?

This works fine on my test server and works fine locally if I let Casini grab it (change base address prefix localhost/CustomTrackingService to localhost:1234/). I cannot remember what causes this to occur and my Google-fu is not producing useful results. Any ideas?

推荐答案

所以问题似乎是我在本地尝试使用未定义基地址的相对地址.这在我的测试服务器上有效,因为测试服务器错误地定义了多个主机头,这似乎转换为WCF中定义的多个基址,这是禁止的.我最初在测试服务器上使用了,因为我收到有关http的多个基址的错误,并且没有意识到真正的问题,所以我过滤掉了要使用的基址.由于我未定义主机头,因此无法在本地工作,因此过滤器未提供任何内容,并且由于未指定基地址,因此相对寻址尝试失败.

So looks like the problem is that locally i was trying to use a relative address with no base address defined. This worked on my test server because the test server incorrectly had more than one host header defined, which seems to translate into more than one base address defined in WCF, which is a no-no. i originally used the on the test server because i was getting an error about more than one base address for http, and without realizing the real problem, I filtered out the one I wanted using . Thsi won't work locally because I have no host headers defined, so the filter provided nothing and the relative addressing attempt failed because no base address was specified.

我将做更多的实验,以了解最适合我的情况的设置,但是检查IIS中的主机标头肯定会有所帮助.另外,此链接对理解实际情况有很大帮助.

I'm going to do some more experimenting to see what the best set-up for my situation is, but checking the host headers in IIS definitely helped. Also, this link was a huge help in understanding what was really going on.

这篇关于WCF无法使用REST服务找到http的基地址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆