为什么我的 WCF 服务不响应 web.config 中的 baseAddress 设置?

发布于 2024-07-13 17:48:31 字数 1794 浏览 5 评论 0原文

我正在尝试通过在 这篇博文,作者:Anthony Steele。 他在配置中使用以下 XML 来设置服务的端点。

    <host>
      <baseAddresses>
        <add baseAddress="http://localhost:8080/greeter"/>
      </baseAddresses>
    </host>

但是,当我尝试在 ASP.NET 3.5 网站的 web.config 中执行相同的操作时,我无法导航到我的服务。 这是我正在使用的 XML:

<system.serviceModel>
  <behaviors>
    <serviceBehaviors>
      <behavior name="GreeterBehavior">
        <serviceMetadata httpGetEnabled="true"/>
        <serviceDebug includeExceptionDetailInFaults="false"/>
      </behavior>
    </serviceBehaviors>
  </behaviors>
  <services>
    <service behaviorConfiguration="GreeterBehavior" name="Greeter">
      <host>
        <baseAddresses>
          <add baseAddress="http://localhost:49268/TestREST/webapi/services/greeter"/>
        </baseAddresses>
      </host>
      <endpoint address="" binding="wsHttpBinding" contract="IGreeter">
        <identity>
          <dns value="localhost"/>
        </identity>
      </endpoint>
      <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
    </service>
  </services>
</system.serviceModel>

我想我的配置将允许我导航到 http: //localhost:49268/TestREST/webapi/services/greeter 并查看我的服务。 我收到的只是一条找不到资源的消息 - 我错过了什么吗?

编辑:我的部分问题是我的绑定是 wsHttpBinding。 使用 webHttpBinding 允许我正确使用该服务 - 除了 baseAddress 配置部分仍然没有效果。

I'm trying to learn how to build RESTful services with WCF by recreating the project on this blog post by Anthony Steele. He uses the following XML in his config to setup the endpoint for the service.

    <host>
      <baseAddresses>
        <add baseAddress="http://localhost:8080/greeter"/>
      </baseAddresses>
    </host>

However, when I try to do the same thing in my ASP.NET 3.5 web site's web.config, I am unable to navigate to my service. Here is the XML I'm using:

<system.serviceModel>
  <behaviors>
    <serviceBehaviors>
      <behavior name="GreeterBehavior">
        <serviceMetadata httpGetEnabled="true"/>
        <serviceDebug includeExceptionDetailInFaults="false"/>
      </behavior>
    </serviceBehaviors>
  </behaviors>
  <services>
    <service behaviorConfiguration="GreeterBehavior" name="Greeter">
      <host>
        <baseAddresses>
          <add baseAddress="http://localhost:49268/TestREST/webapi/services/greeter"/>
        </baseAddresses>
      </host>
      <endpoint address="" binding="wsHttpBinding" contract="IGreeter">
        <identity>
          <dns value="localhost"/>
        </identity>
      </endpoint>
      <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
    </service>
  </services>
</system.serviceModel>

I would imagine my configuration would allow me to navigate to http://localhost:49268/TestREST/webapi/services/greeter and see my service. All I get is a resource not found message - am I missing something?

Edit: Part of my problem was my binding was wsHttpBinding. Using webHttpBinding allowed me to use the service correctly - except, the baseAddress config section still has no effect.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

梦过后 2024-07-20 17:48:32

我的预感是服务端点没有成功创建。

在服务“名称”属性中,不包括服务类型的 FQN(完全限定名称)。 其次,在端点“合同”属性中,您也不会将 FQN 包含到合同类型中。

另一方面,这可能是端口问题。 为了确定这一点,请尝试运行 Visual Studio 2008 发行版中包含的 WcfTestClient.exe。 如果您可以连接到 http://localhost:49268/TestREST/webapi/services/greeter /mex,那么你就知道这不是端口问题。

假设您可以通过 MEX 连接,然后尝试执行一些方法,这些方法可能会映射到 http://localhost:49268/TestREST/webapi/services/greeter

如果您在服务器上操作,请在此处查看有关 HttpCfg.exe 的一些有价值的详细信息:
WCF ServiceHost basicHttpBinding 503 错误

如果您需要有关 WcfTestClient 的更多详细信息,请查看对于他们来说:
是否可以使 WcfTestClient 工作自定义传输通道?

以防万一:逐字复制示例并验证其是否按定义工作,包括配置文件,然后再做出最轻微的偏差。

My hunch is that the service endpoint is not being created successfully.

In the service "name" attribute you are not including the FQN (Fully Qualified Name) of the service type. Secondarily, in the endpoint "contract" attribute you are also not including the FQN to the contract type.

On the other hand, this MAY be a port issue. In order to be sure, try running the WcfTestClient.exe that is included in the Visual Studio 2008 distribution. If you can connect to http://localhost:49268/TestREST/webapi/services/greeter/mex, then you know it is not a port issue.

Supposing that you can connect via MEX, then try exercising some of the methods, which would presumably be mapped to http://localhost:49268/TestREST/webapi/services/greeter.

If you are operating on server, see some valuable details about HttpCfg.exe here:
WCF ServiceHost basicHttpBinding 503 error

If you need more details on WcfTestClient, look for them here:
Is it possible to make the WcfTestClient work for custom transport channels?

Just In Case: copy the sample verbatim and verify that it works as defined, including the config file, before making the slightest deviation from it.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文