显示 WCF Web 服务操作

发布于 2024-10-15 13:01:05 字数 2220 浏览 5 评论 0原文

因此,我创建了一个 WCF 服务应用程序并将其托管在 IIS7 上。目前它有一些测试“helloworld”方法。当我在浏览器中运行它时,我会看到以下屏幕: 在此处输入图像描述

现在服务本身工作得很好,但是我如何显示这样的操作: 在此处输入图像描述

感谢 marc_s 提供的链接:http://www.dotnetcurry.com/ShowArticle.aspx?ID=399 我已经关注了,所以我的网络配置现在设置如下:

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
  <system.web>
    <compilation debug="true" targetFramework="4.0" />
  </system.web>
  <system.serviceModel>
    <services>
      <service name="WcfServer.Service1">
        <endpoint address="" binding="webHttpBinding" contract="WcfServer.IService1" behaviorConfiguration="HelpBehaviour" />
      </service>
    </services>
    <behaviors>
      <serviceBehaviors>
        <behavior>
          <!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment -->
          <serviceMetadata httpGetEnabled="true" />
          <!-- 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="false" />
        </behavior>
      </serviceBehaviors>
      <endpointBehaviors>
        <behavior name="AjaxBehavior">
          <enableWebScript />
        </behavior>
        <behavior name="HelpBehaviour">
          <webHttp helpEnabled="true"/>
        </behavior>
      </endpointBehaviors>
    </behaviors>
  </system.serviceModel>
 <system.webServer>
    <modules runAllManagedModulesForAllRequests="true" />
        <directoryBrowse enabled="true" showFlags="Date, Time, Size, Extension" />
  </system.webServer>
</configuration>

然而,这仅适用于本地。当我发布到 IIS7 上的服务器时,单击帮助链接时出现 404 错误页面。有谁知道这是为什么,或者以前遇到过吗?

(最后一点通过运行解决:aspnet_regiis.exe -iru

So I've created a WCF service application and hosted it on IIS7. It currently has a few test 'helloworld' methods. When I run it in my browser I get this screen:
enter image description here

Now the service itself works great, but how can I display the operations like this:
enter image description here

Thanks to marc_s for the link: http://www.dotnetcurry.com/ShowArticle.aspx?ID=399 which I've followed so my web config is now setup like:

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
  <system.web>
    <compilation debug="true" targetFramework="4.0" />
  </system.web>
  <system.serviceModel>
    <services>
      <service name="WcfServer.Service1">
        <endpoint address="" binding="webHttpBinding" contract="WcfServer.IService1" behaviorConfiguration="HelpBehaviour" />
      </service>
    </services>
    <behaviors>
      <serviceBehaviors>
        <behavior>
          <!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment -->
          <serviceMetadata httpGetEnabled="true" />
          <!-- 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="false" />
        </behavior>
      </serviceBehaviors>
      <endpointBehaviors>
        <behavior name="AjaxBehavior">
          <enableWebScript />
        </behavior>
        <behavior name="HelpBehaviour">
          <webHttp helpEnabled="true"/>
        </behavior>
      </endpointBehaviors>
    </behaviors>
  </system.serviceModel>
 <system.webServer>
    <modules runAllManagedModulesForAllRequests="true" />
        <directoryBrowse enabled="true" showFlags="Date, Time, Size, Extension" />
  </system.webServer>
</configuration>

However, this only works locally. When I publish to my server on IIS7 I get a 404 error page when I click on the help link. Does anyone know why this is, or has come across it before?

(Last bit was solved by running: aspnet_regiis.exe -iru)

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

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

发布评论

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

评论(1

南风几经秋 2024-10-22 13:01:06

如果您有一个带有 SOAP 绑定的 WCF 服务,那么不幸的是您运气不好:WCF 中没有办法开箱即用地获得类似于 ASMX 的所有服务的列表。

通过 REST 绑定 (webHttpBinding) 和 .NET 4.0,您可以生成一个自动帮助页面,其中列出了 URI 模板、支持的 HTTP 方法等。您还可以将该页面调整到一定程度。

为了生成自动帮助页面,您需要定义(并引用)端点行为:

<behaviors>
   <endpointBehaviors>
       <behavior name="HelpBehavior">
           <webHttp helpEnabled="true" />
       </behavior>
   </endpointBehaviors>
</behaviors>

然后从您的 webHttpBinding 端点引用该行为,就完成了。

阅读全部内容:

If you have a WCF service with a SOAP binding, you're unfortunately out of luck: there's no way in WCF out of the box to get a listing similar to ASMX with all the services.

With REST binding (webHttpBinding) and .NET 4.0, you can have an automatic help page generated which lists the URI templates, the HTTP methods supported and so forth. You can also tweak that page to a certain degree.

In order to have that automatic help page generated, you need to define (and reference) an endpoint behavior:

<behaviors>
   <endpointBehaviors>
       <behavior name="HelpBehavior">
           <webHttp helpEnabled="true" />
       </behavior>
   </endpointBehaviors>
</behaviors>

Then reference that behavior from your webHttpBinding endpoint, and you're done.

Read all about it:

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