为 IIS 托管的 .SVC 文件配置 XML-RPC 行为?
我正在使用 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
以下是实现此功能的步骤:
Microsoft.Samples.XmlRpc
、TinyBlogEngine
和TinyBlogEngineClient
。TinyBlogEngineWeb
)在新项目引用
Microsoft.Samples.XmlRpc
和TinyBlogEngine< /代码>。
将 test.svc 文件添加到此 Web 应用程序,如下所示:
将
XmlRpcEndpointBehaviorExtension
类添加到新项目:最后是
web.xml 的
应如下所示:system.serviceModel
部分。 config最后修改控制台客户端应用程序以使用 Web 项目的地址并测试:
使用 Windows Live Writer 和控制台客户端应用程序进行测试。您可以从此处下载我的测试解决方案。
Here are the steps to get this working:
Microsoft.Samples.XmlRpc
,TinyBlogEngine
andTinyBlogEngineClient
.TinyBlogEngineWeb
)In the new project reference
Microsoft.Samples.XmlRpc
andTinyBlogEngine
.Add a test.svc file to this web application which looks like this:
Add a
XmlRpcEndpointBehaviorExtension
class to the new project:Finally the
system.serviceModel
part ofweb.config
should look like this:Finally modify the console client application to use the address of the web project and test:
Tested with Windows Live Writer and the console client application. You can download my test solution from here.