2

I need to implement a simple XML-RPC web service for use with the Shopatron API (http://developer.shopatron.com/api) specifically the Ready Order Download part (http://developer.shopatron.com/ReadyOrderDownload)

The third party (Shopatron) will dump some XML package data to a URL. I just need to process it.

I've installed Nuget Package xmlrpcnet (https://www.nuget.org/packages/xmlrpcnet) into my web site project.

My question: What type of web service do I need to add to my VS project website to make this simple and easy?

Do I want a:

  1. Generic Handler (ashx)
  2. Web Service (asmx)
  3. WCF Service (svc)
  4. Other?

Bonus question: Is there a good test tool I can use to "post" XML-RPC sample packages to my local dev website?

Tomas Beblar
  • 468
  • 4
  • 18

1 Answers1

1

I think the better option is use WCF as recommended (today) way to create web services. Creating service with WCF infrastructure allows you to host your service in IIS, WAS (win service), console app without much problems and friction. This project (providing XmlRpcEndpointBehavior) and tutorial can help (already discussed here).

You can even easily parse request body xml and provide required response xml structure - by using WCF support classes/objects:

for ex:

[OperationContract]
[WebInvoke(
BodyStyle = WebMessageBodyStyle.Bare,
Method = "POST",
RequestFormat = WebMessageFormat.Xml,
ResponseFormat = WebMessageFormat.Xml,      
UriTemplate = "/somemethod?param1={param1}&param2={param2}")]       
System.ServiceModel.Channels.Message SomeMethod(Stream stream, string param1, string param2)
{
    string xmlString;

    var inputStream = stream;
    using (var streamReader = new StreamReader(inputStream))
    {
        xmlString = streamReader.ReadToEnd();
    }

    var sourceXml = new XmlDocument();
    sourceXml.LoadXml(xmlString); 
    //...

    var xml = new XDocument(...);
    //...

    var settings = new XmlWriterSettings();
    settings.Indent = true;
    var sb = new StringBuilder();
    using (var writer = XmlWriter.Create(sb, settings))
    {
        xml.WriteTo(writer);
        writer.Flush();
    }

    WebOperationContext.Current.OutgoingResponse.ContentType = "text/xml";
    return WebOperationContext.Current.CreateTextResponse(sb.ToString());
}

By the way asmx, svc - it is only for hosting your service in web app (IIS), asmx - obsolete, ashx - http handler (not WS-standard web service, strictly speaking), not from WCF's world - if you go ashx way you will, probably, need XML-RPC.NET is a library.

Community
  • 1
  • 1
SalientBrain
  • 2,431
  • 16
  • 18