配置XML-RPC行为IIS托管.SVC文件? [英] Configuring XML-RPC behavior for IIS-hosted .SVC file?
问题描述
我使用克莱门斯Vasters XML-RPC实现来实现一个XML-RPC端点。当我在主持一个控制台应用程序的服务,它工作正常。
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.
我想承载它在ASP.NET MVC应用程序,所以我使用的是.svc文件。这部分的工作。当我浏览到.svc文件,我看到常用的你已经创建了一个服务的东西。
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.
然而,当我在相同的位置指向我的XML-RPC客户端(的Windows Live作家),我得到一个400错误的请求。我猜,这是因为我的服务没有正确地公开为XML-RPC。
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.
我已经尝试的配置在Web.config中的终结点行为,如下所示:
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" />
...但它不工作。我究竟做错了什么?我有我的web.config正确的,还是我拥有这一切完全错了吗?我需要在我的.SVC文件中提供的自定义工厂理清行为?
...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?
.svc文件看起来是这样的,顺便说一句:
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.
此外,在那一刻,我只是在卡西尼(VS2010),而不是IIS测试这一点,但我会在IIS 7.x的目光瞄准它。
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.
更新:这肯定至少在看我的扩展:它调用 XmlRpcEndpointBehaviorElement.get_BehaviorType
,如果 XmlRpcEndpointBehavior
不执行 IEndpointBehavior
,我得到一个错误,该效应(代替了你已经创建了一个服务页面的显示)。
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.
如果我打开WCF的跟踪,我在日志文件中看到无法识别的消息版本。
If I turn on WCF tracing, I see "unrecognized message version" in the log file.
推荐答案
下面是得到这个工作的步骤:
Here are the steps to get this working:
- 下载 XML-RPC为WCF样品一>
- 该解决方案包含3个项目:
Microsoft.Samples.XmlRpc
,TinyBlogEngine
和TinyBlogEngineClient
。 - 第4个项目添加到ASP.NET类型的解决方案(我把它叫做
TinyBlogEngineWeb
)
- Download the XML-RPC for WCF sample
- The solution contains 3 projects:
Microsoft.Samples.XmlRpc
,TinyBlogEngine
andTinyBlogEngineClient
. - Add a 4th project to the solution of type ASP.NET (I've called it
TinyBlogEngineWeb
)
在新的项目引用 Microsoft.Samples.XmlRpc
和 TinyBlogEngine
。
一个test.svc文件添加到这个Web应用程序看起来像这样:
Add a test.svc file to this web application which looks like this:
<%@ 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.config中的最后
应该是这样的: system.serviceModel
部分
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;
与Windows Live作家和控制台客户端应用程序进行测试。您可以从这里下载我的测试解决方案。
Tested with Windows Live Writer and the console client application. You can download my test solution from here.
这篇关于配置XML-RPC行为IIS托管.SVC文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!