为 IIS 托管的 .SVC 文件配置 XML-RPC 行为?

发布于 2024-09-06 19:09:17 字数 2186 浏览 8 评论 0原文

我正在使用 Clemens Vasters XML -RPC 实现来实现 XML-RPC 端点。当我在控制台应用程序中托管该服务时,它工作正常。

我想将其托管在 ASP.NET MVC 应用程序中,因此我使用 .SVC 文件。这是部分有效的。当我浏览到 .SVC 文件时,我会看到常见的“您已创建服务”内容。

但是,当我将 XML-RPC 客户端(Windows Live Writer)指向同一位置时,我收到“400 Bad Request”。我猜测这是因为我的服务没有正确公开为 XML-RPC。

我尝试配置Web.config 中的端点行为,如下所示:

<system.serviceModel>
  <services>
    <service name="AnotherBlogEngine.Web.Api.BlogApi">
      <endpoint address=""
                binding="webHttpBinding"
                contract="AnotherBlogEngine.Web.Api.IBlogApi"
                behaviorConfiguration="xmlRpcBehavior" />
  </service>
  </services>
  <extensions>
    <behaviorExtensions>
      <add name="xmlRpc"
           type="AnotherBlogEngine.XmlRpc.XmlRpcEndpointBehaviorElement, \
                 AnotherBlogEngine.XmlRpc" />
    </behaviorExtensions>
  </extensions>
  <behaviors>
    <endpointBehaviors>
      <behavior name="xmlRpcBehavior">
        <xmlRpc/>
      </behavior>
    </endpointBehaviors>
  </behaviors>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />

...但它不起作用。我做错了什么?我的 Web.config 是否正确,还是完全错误?我是否需要在 .SVC 文件中提供自定义工厂来整理行为?

顺便说一句,.SVC 文件看起来像这样:

<%@ ServiceHost Language="C#" Debug="true"
    Service="AnotherBlogEngine.Publishing.Service.BlogApi, \
             AnotherBlogEngine.Publishing.Service" %>

注意:这些反斜杠实际上并不存在;它们只是用于换行。

另外,目前我只是在 Cassini (VS2010) 中测试它,而不是 IIS,但我将把它瞄准 IIS 7.x。

更新:至少肯定会查看我的扩展:它调用 XmlRpcEndpointBehaviorElement.get_BehaviorType,并且如果 XmlRpcEndpointBehavior 未实现 IEndpointBehavior< /code>,我收到一个错误(显示在“您已创建服务”页面的位置)。

但是,这两个类中其他方法上的断点都不会被命中。

如果我打开 WCF 跟踪,我会在日志文件中看到“无法识别的消息版本”。

I'm using Clemens Vasters' XML-RPC implementation to implement an XML-RPC endpoint. When I host the service in a console application, it works fine.

I'd like to host it in an ASP.NET MVC application, so I'm using a .SVC file. This is partially working. When I browse to the .SVC file, I see the usual "You have created a service" stuff.

However, when I point my XML-RPC client (Windows Live Writer) at the same location, I get a "400 Bad Request". I'm guessing that this is because my service isn't correctly exposed as XML-RPC.

I've attempted to configure an endpoint behavior in Web.config, as follows:

<system.serviceModel>
  <services>
    <service name="AnotherBlogEngine.Web.Api.BlogApi">
      <endpoint address=""
                binding="webHttpBinding"
                contract="AnotherBlogEngine.Web.Api.IBlogApi"
                behaviorConfiguration="xmlRpcBehavior" />
  </service>
  </services>
  <extensions>
    <behaviorExtensions>
      <add name="xmlRpc"
           type="AnotherBlogEngine.XmlRpc.XmlRpcEndpointBehaviorElement, \
                 AnotherBlogEngine.XmlRpc" />
    </behaviorExtensions>
  </extensions>
  <behaviors>
    <endpointBehaviors>
      <behavior name="xmlRpcBehavior">
        <xmlRpc/>
      </behavior>
    </endpointBehaviors>
  </behaviors>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />

...but it's not working. What am I doing wrong? Do I have my Web.config correct, or do I have it all completely wrong? Do I need to provide a custom factory in my .SVC file to sort out the behaviors?

The .SVC file looks like this, by the way:

<%@ ServiceHost Language="C#" Debug="true"
    Service="AnotherBlogEngine.Publishing.Service.BlogApi, \
             AnotherBlogEngine.Publishing.Service" %>

Note: Those backslashes aren't actually there; they're just for line-wrapping.

Also, at the moment, I'm just testing this in Cassini (VS2010), rather than IIS, but I'll be aiming it at IIS 7.x.

Update: It's definitely at least looking at my extension: it calls XmlRpcEndpointBehaviorElement.get_BehaviorType, and if XmlRpcEndpointBehavior doesn't implement IEndpointBehavior, I get an error to that effect (displayed in place of the "You have created a service" page).

However, breakpoints on the other methods in either class don't get hit.

If I turn on WCF tracing, I see "unrecognized message version" in the log file.

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

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

发布评论

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

评论(1

极度宠爱 2024-09-13 19:09:17

以下是实现此功能的步骤:

  1. 下载 XML -RPC for WCF 示例
  2. 该解决方案包含 3 个项目:Microsoft.Samples.XmlRpcTinyBlogEngineTinyBlogEngineClient
  3. 将第四个项目添加到 ASP.NET 类型的解决方案(我将其称为 TinyBlogEngineWeb

在新项目引用 Microsoft.Samples.XmlRpcTinyBlogEngine< /代码>。

将 test.svc 文件添加到此 Web 应用程序,如下所示:

<%@ ServiceHost Language="C#" Debug="true" Service="TinyBlogEngine.BloggerAPI, TinyBlogEngine" %>

XmlRpcEndpointBehaviorExtension 类添加到新项目:

namespace TinyBlogEngineWeb
{
    public class XmlRpcEndpointBehaviorExtension : BehaviorExtensionElement
    {
        protected override object CreateBehavior()
        {
            // this comes from Microsoft.Samples.XmlRpc
            return new XmlRpcEndpointBehavior();
        }

        public override Type BehaviorType
        {
            get { return typeof(XmlRpcEndpointBehavior); }
        }
    }
}

最后是 web.xml 的 system.serviceModel 部分。 config 应如下所示:

<system.serviceModel>
  <services>
    <service name="TinyBlogEngine.BloggerAPI" behaviorConfiguration="returnFaults">
      <endpoint address="/blogger"
                binding="webHttpBinding"
                contract="TinyBlogEngine.IBloggerAPI"
                behaviorConfiguration="xmlRpcBehavior" />
    </service>
  </services>

  <behaviors>
    <serviceBehaviors>
      <behavior name="returnFaults">
        <serviceMetadata httpGetEnabled="true" />
        <serviceDebug includeExceptionDetailInFaults="false" />
      </behavior>
    </serviceBehaviors>

    <endpointBehaviors>
      <behavior name="xmlRpcBehavior">
        <xmlRpc/>
      </behavior>
    </endpointBehaviors>
  </behaviors>

  <extensions>
    <behaviorExtensions>
      <add name="xmlRpc"
           type="TinyBlogEngineWeb.XmlRpcEndpointBehaviorExtension, TinyBlogEngineWeb" />
    </behaviorExtensions>
  </extensions>
</system.serviceModel>

最后修改控制台客户端应用程序以使用 Web 项目的地址并测试:

Uri blogAddress = new UriBuilder(
    Uri.UriSchemeHttp, 
    "localhost", 
    1260, // use the appropriate port here
    "/test.svc/blogger"
).Uri;

使用 Windows Live Writer 和控制台客户端应用程序进行测试。您可以从此处下载我的测试解决方案

Here are the steps to get this working:

  1. Download the XML-RPC for WCF sample
  2. The solution contains 3 projects: Microsoft.Samples.XmlRpc, TinyBlogEngine and TinyBlogEngineClient.
  3. Add a 4th project to the solution of type ASP.NET (I've called it TinyBlogEngineWeb)

In the new project reference Microsoft.Samples.XmlRpc and TinyBlogEngine.

Add a test.svc file to this web application which looks like this:

<%@ ServiceHost Language="C#" Debug="true" Service="TinyBlogEngine.BloggerAPI, TinyBlogEngine" %>

Add a XmlRpcEndpointBehaviorExtension class to the new project:

namespace TinyBlogEngineWeb
{
    public class XmlRpcEndpointBehaviorExtension : BehaviorExtensionElement
    {
        protected override object CreateBehavior()
        {
            // this comes from Microsoft.Samples.XmlRpc
            return new XmlRpcEndpointBehavior();
        }

        public override Type BehaviorType
        {
            get { return typeof(XmlRpcEndpointBehavior); }
        }
    }
}

Finally the system.serviceModel part of web.config should look like this:

<system.serviceModel>
  <services>
    <service name="TinyBlogEngine.BloggerAPI" behaviorConfiguration="returnFaults">
      <endpoint address="/blogger"
                binding="webHttpBinding"
                contract="TinyBlogEngine.IBloggerAPI"
                behaviorConfiguration="xmlRpcBehavior" />
    </service>
  </services>

  <behaviors>
    <serviceBehaviors>
      <behavior name="returnFaults">
        <serviceMetadata httpGetEnabled="true" />
        <serviceDebug includeExceptionDetailInFaults="false" />
      </behavior>
    </serviceBehaviors>

    <endpointBehaviors>
      <behavior name="xmlRpcBehavior">
        <xmlRpc/>
      </behavior>
    </endpointBehaviors>
  </behaviors>

  <extensions>
    <behaviorExtensions>
      <add name="xmlRpc"
           type="TinyBlogEngineWeb.XmlRpcEndpointBehaviorExtension, TinyBlogEngineWeb" />
    </behaviorExtensions>
  </extensions>
</system.serviceModel>

Finally modify the console client application to use the address of the web project and test:

Uri blogAddress = new UriBuilder(
    Uri.UriSchemeHttp, 
    "localhost", 
    1260, // use the appropriate port here
    "/test.svc/blogger"
).Uri;

Tested with Windows Live Writer and the console client application. You can download my test solution from here.

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