Configuring XML-RPC behavior for IIS-hosted .SVC file?

后端 未结 1 1112
盖世英雄少女心
盖世英雄少女心 2020-12-18 10:20

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 h

相关标签:
1条回答
  • 2020-12-18 11:00

    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.

    0 讨论(0)
提交回复
热议问题