title: ServiceStack [XmlSerializerFormat] compatible SOAP Web-service for a legacy client
body: <p>I would like to replace a WCF Web-service by a new ServiceStack service. WCF service uses basicHttpBinding and it is invoked by a legacy client via SOAP using HTTP POST. The problem I faced to is that the legacy client uses <code>[XmlSerializerFormat]</code> instead of <code>[DataContract]</code>, and it can not be changed. I inspected the SOAP envelopes produced by the client and shown by metadata page of my new ServiceStack service and haven't discovered any crucial mismatches in requests. They look closely the same except of responses. Service Stack's response uses a custom namespace.</p>
  
  <p>Below is the WCF service's API, which works well with the legacy client. It has quite simple API: only two methods.</p>
  
  <pre><code>[ServiceContract(Namespace = WebConstants.SoapNamespace)]
  [XmlSerializerFormat]
  public interface IMicexNewsWcf
  {
      [OperationContract(Action = WebConstants.SoapNamespace + "PostNews")]
      [FaultContract(typeof(ExceptionDetail))]
      [PrincipalPermission(SecurityAction.Demand, Role = WebConstants.UserRole)]
      string PostNews (MarketNewsRaw[] st, string rynok);
  
      [OperationContract(Action = WebConstants.SoapNamespace + "SendMarkerUsingDB")]
      [FaultContract(typeof(ExceptionDetail))]
      [PrincipalPermission(SecurityAction.Demand, Role = WebConstants.UserRole)]
      void SendMarkerUsingDB (string id, string dt, string status, string problem);
  }
  
  [XmlSerializerFormat]
  public sealed class MarketNewsRaw
  {
      [DataMember(Order = 1)]
      public string SysTime {get; set;}
      [DataMember(Order = 2)]
      public string Urgency {get; set;}
      [DataMember(Order = 3)]
      public string FromUser {get; set;}
      [DataMember(Order = 4)]
      public string MsgTime {get; set;}
      [DataMember(Order = 5)]
      public string MsgText {get; set;}
  }
  </code></pre>
  
  <p>Service implementation:</p>
  
  <pre><code>[ServiceBehavior(ConcurrencyMode = ConcurrencyMode.Multiple, InstanceContextMode = InstanceContextMode.Single)]
  public sealed class MicexNewsWcf: WcfServiceBase, IMicexNewsWcf
  {
      public const string SrvName = "NewsListener";
  
      readonly IMicexNewsListenerService _listenerSrv;
      readonly IAbstractLogger _logger;
  
      public MicexNewsWcf (IAbstractLoggerFactory loggerFac, IMicexNewsListenerService listenerSrv): base(loggerFac.GetLogger(SrvName))
      {
          _listenerSrv = listenerSrv;
          _logger = loggerFac.GetLogger(SrvName);
      }
  
      public string PostNews (MarketNewsRaw[] st, string rynok)
      {           
  
        return "Ok";
      }
  
      public void SendMarkerUsingDB (string id, string dt, string status, string problem)
      {                           
      }
  }
  </code></pre>
  
  <p>Example of SOAP XML sent by a legacy client:</p>
  
  <pre><code>&lt;SOAP-ENV:Envelope xmlns:SOAPSDK1="http://www.w3.org/2001/XMLSchema" xmlns:SOAPSDK2="http://www.w3.org/2001/XMLSchema-instance" xmlns:SOAPSDK3="http://schemas.xmlsoap.org/soap/encoding/" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"&gt;
      &lt;SOAP-ENV:Body&gt;
          &lt;PostNews xmlns="http://xxx/"&gt;
              &lt;st&gt;
                  &lt;MarketNewsRaw&gt;
                    &lt;SysTime&gt;17.10.2013 10:35:38&lt;/SysTime&gt;
                    &lt;Urgency&gt;U&lt;/Urgency&gt;
                    &lt;FromUser&gt;MZ000020069A&lt;/FromUser&gt;
                    &lt;MsgTime&gt;10:35:38&lt;/MsgTime&gt;
                    &lt;MsgText&gt;Some text&lt;/MsgText&gt;
                  &lt;/MarketNewsRaw&gt;
                  &lt;MarketNewsRaw&gt;
                    &lt;SysTime&gt;17.10.2013 11:21:26&lt;/SysTime&gt;
                    &lt;Urgency&gt;U&lt;/Urgency&gt;
                    &lt;FromUser&gt;MM0000101281&lt;/FromUser&gt;
                    &lt;MsgTime&gt;11:21:27&lt;/MsgTime&gt;
                    &lt;MsgText&gt;XXX 2&lt;/MsgText&gt;
                  &lt;MarketNewsRaw&gt;
              &lt;/st&gt;
              &lt;rynok&gt;4&lt;/rynok&gt;
          &lt;/PostNews&gt;
      &lt;/SOAP-ENV:Body&gt;
  &lt;/SOAP-ENV:Envelope&gt;
  </code></pre>
  
  <p>Exact SOAP which is accepted by my WCF service with <code>basicHttpBinding</code>.</p>
  
  <p>To replace WCF service I implemented ServiceStack service, shown below.</p>
  
  <pre><code>[XmlSerializerFormat]
  [Route("/MicexNews", "POST")]
  public sealed class PostNews: IReturn&lt;PostNewsResponse&gt;
  {
      [DataMember(Order = 1)]
      public MarketNewsRaw[] st;
  
      [DataMember(Order = 2)]
      public string rynok;
  
  
      public override string ToString ()
      {
          StringBuilder bld = new StringBuilder();
          if (st != null)
              foreach (var s in st)
              {
                  if (bld.Length &gt; 0)
                      bld.Append(", ");
                  bld.AppendFormat("&lt;{0}&gt;", s.ToString());
              }
          return string.Format("st = [{0}], rynok = {1}", bld.ToString(), rynok);
      }
  }
  
  [XmlSerializerFormat]
  public sealed class PostNewsResponse: IHasResponseStatus
  {
      public PostNewsResponse ()
      {
          ResponseStatus = new ResponseStatus();
      }
  
      [DataMember(Order = 1)]
      public ResponseStatus ResponseStatus { get; set; }
  
      [DataMember(Order = 2)]
      public string Result {get; set; }
  }
  
  [XmlSerializerFormat]
  [Route("/MicexNews", "POST")]
  public sealed class SendMarkerUsingDB: IReturn&lt;SendMarkerUsingDBResponse&gt;
  {
      [DataMember(Order = 1)]
      public string id {get; set;}
      [DataMember(Order = 2)]
      public string dt {get; set;}
      [DataMember(Order = 3)]
      public string status {get; set;}
      [DataMember(Order = 4)]
      public string problem {get; set;}
  
      public override string ToString ()
      {
          return string.Format("id = {0}, dt = {1}, status = {2}, problem = {3}", id, dt, status, problem);
      }
  }
  
  [XmlSerializerFormat]
  public sealed class SendMarkerUsingDBResponse: IHasResponseStatus
  {
      [DataMember(Order = 1)]
      public ResponseStatus ResponseStatus { get; set; }
  }
  
  
  public sealed class MicexNewsWebService: Service, IPost&lt;PostNews&gt;, IPost&lt;SendMarkerUsingDB&gt;
  {
      public const string SrvName = "NewsListener";
  
      readonly IMicexNewsListenerService _listenerSrv;
      readonly IAbstractLogger _logger;
  
      public MicexNewsWebService (IAbstractLoggerFactory loggerFac, IMicexNewsListenerService listenerSrv)
      {
          _listenerSrv = listenerSrv;
          _logger = loggerFac.GetLogger(SrvName);
      }
  
      public object Post (PostNews req)
      {
          PostNewsResponse stat = new PostNewsResponse();
          stat.Result = "Ok";
  
          return stat;
      }
  
      public object Post (SendMarkerUsingDB request)
      {
          SendMarkerUsingDBResponse stat = new SendMarkerUsingDBResponse();           
  
          return stat;
      }
  }
  </code></pre>
  
  <p>Metadata page shows the SOAP example:</p>
  
  <pre><code>&lt;soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"&gt;
      &lt;soap:Body&gt;
  
  &lt;PostNews xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://xxx/"&gt;
    &lt;rynok&gt;String&lt;/rynok&gt;
    &lt;st&gt;
      &lt;MarketNewsRaw&gt;
        &lt;FromUser&gt;String&lt;/FromUser&gt;
        &lt;MsgText&gt;String&lt;/MsgText&gt;
        &lt;MsgTime&gt;String&lt;/MsgTime&gt;
        &lt;SysTime&gt;String&lt;/SysTime&gt;
        &lt;Urgency&gt;String&lt;/Urgency&gt;
      &lt;/MarketNewsRaw&gt;
    &lt;/st&gt;
  &lt;/PostNews&gt;
  
      &lt;/soap:Body&gt;
  &lt;/soap:Envelope&gt;
  </code></pre>
  
  <p>The response:</p>
  
  <pre><code>&lt;soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"&gt;
  &lt;soap:Body&gt;
  
  &lt;PostNewsResponse xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://xxx/"&gt;
    &lt;ResponseStatus xmlns:d2p1="http://schemas.servicestack.net/types"&gt;
      &lt;d2p1:ErrorCode&gt;String&lt;/d2p1:ErrorCode&gt;
      &lt;d2p1:Message&gt;String&lt;/d2p1:Message&gt;
      &lt;d2p1:StackTrace&gt;String&lt;/d2p1:StackTrace&gt;
      &lt;d2p1:Errors&gt;
        &lt;d2p1:ResponseError&gt;
          &lt;d2p1:ErrorCode&gt;String&lt;/d2p1:ErrorCode&gt;
          &lt;d2p1:FieldName&gt;String&lt;/d2p1:FieldName&gt;
          &lt;d2p1:Message&gt;String&lt;/d2p1:Message&gt;
        &lt;/d2p1:ResponseError&gt;
      &lt;/d2p1:Errors&gt;
    &lt;/ResponseStatus&gt;
    &lt;Result&gt;String&lt;/Result&gt;
  &lt;/PostNewsResponse&gt;
  
      &lt;/soap:Body&gt;
  &lt;/soap:Envelope&gt;
  </code></pre>
  
  <p>So, I am able to call ServiceStack service by means of a test ServiceStack Json client, for example, but the call originating from my legacy client is failed.</p>
  
  <p>How could I adjust ServiceStack to understand old RPC SOAP, as well as WCF does, along with <code>[XmlSerializerFormat]</code> attribute specified on interface?</p>
  
  <p>Legacy client reports <code>400 Bad Request</code> and my ServiceStack service has not been even get called. I mean, method <code>public object Post (PostNews req)</code> has not been called.</p>