以下是实现此功能的步骤:
-
下载
XML-RPC for WCF sample
-
该解决方案包含3个项目:
Microsoft.Samples.XmlRpc
,
TinyBlogEngine
和
TinyBlogEngineClient
.
-
在ASP.NET类型的解决方案中添加第四个项目(我称之为
TinyBlogEngineWeb
)
在新项目参考中
Microsoft.samples.xmlrpc(Microsoft.samples.xmlrpc)
和
TyyByb引擎
.
将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); }
}
}
}
最后
system.serviceModel
部分
web.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和控制台客户端应用程序进行测试。你可以
download my test solution from here
.