title: Send 'XML data as string' in Soap XML envelope
body: <p>I have WCF Soap webservice that needs to receive an XML string. I've attemted this despite the fact that I have very little experience with webservices. This webservice is supposed to be called from SAP PI.</p>
  
  <p>The structure of the request message is as follows:</p>
  
  <pre><code>public class DtoRequest&lt;T&gt; : IDtoRequest where T : class
  {
      public InteractionContext Context { get; set; }
      public T Request { get; set; }
  }
  </code></pre>
  
  <p>where the type is a class of the following</p>
  
  <pre><code>public class SendRfqRequest : DtoRequest&lt;ImportRfqDataDto&gt;
  {
  }
  
  [DataContract]
  public class ImportRfqDataDto
  {
      [DataMember]
      public string RfqXmlData { get; set; }
  }
  </code></pre>
  
  <p>The InteractionContext takes the following fields:</p>
  
  <pre><code>public class InteractionContext
  {
      public string Application { get; set; }
      public string License { get; set; }
      public DateTime TimeStamp { get; set; }
      public Guid Id { get; set; }
  }
  </code></pre>
  
  <p>I deployed this on a webservicesdev server, generated code to use it with wsdl.exe and tested it with a simple console application:</p>
  
  <pre><code>// Generated from wsdl.exe tool
  RfqImportServiceClient client = new RfqImportServiceClient();
  // Xml Document
  XDocument rfqXml = XDocument.Load("..\\..\\RfqValidGood.xml");
  
  SendRfqRequest request = new SendRfqRequest
  {
      Context = new CityOfCapeTown.Services.Common.InteractionContext
      {
          Id = Guid.NewGuid(),
          Application = "TestApplication",
          License = "TestLicenseKey",
          TimeStamp = DateTime.Now,
      },
      Request = new DataTransferObjects.ImportRfqDataDto
      {
          RfqXmlData = rfqXml.ToString()
      }
  };
  
  Console.WriteLine("\n\n- Attempting connection to web-service");
  SendRfqResponse response = client.ProcessRfq(request);
  Console.WriteLine("- Successfully connected to web-service");
  Console.WriteLine("- Status of response: " + (ResponseType)response.Result);
  </code></pre>
  
  <p>This all works perfectly. The problem comes when testing the webservice from SAP PI. It's having issues when XML data is passed in the RfqXmlData tag. I tried testing it in SOAP UI. It generated the following SOAP envelope from the wsdl:</p>
  
  <pre><code>&lt;soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:tem="http://tempuri.org/" xmlns:cit="http://schemas.datacontract.org/2004/07/CityOfCapeTown.Services.Common" xmlns:proc="http://schemas.datacontract.org/2004/07/ProcurementAdministrationPortal.WebService.DataTransferObjects"&gt;
     &lt;soapenv:Header/&gt;
     &lt;soapenv:Body&gt;
        &lt;tem:ProcessRfq&gt;
           &lt;!--Optional:--&gt;
           &lt;tem:request&gt;
              &lt;!--Optional:--&gt;
              &lt;cit:Context&gt;
                 &lt;!--Optional:--&gt;
                 &lt;cit:Application&gt;SAPClient&lt;/cit:Application&gt;
                 &lt;!--Optional:--&gt;
                 &lt;cit:Id&gt;1a975cab-bc7c-47e3-aa77-ac9dc407721d&lt;/cit:Id&gt;
                 &lt;!--Optional:--&gt;
                 &lt;cit:License&gt;1a975cab-bc7c-47e3-aa77-ac9dc407721d&lt;/cit:License&gt;
                 &lt;!--Optional:--&gt;
                 &lt;cit:TimeStamp&gt;2014-01-01&lt;/cit:TimeStamp&gt;
              &lt;/cit:Context&gt;
              &lt;!--Optional:--&gt;
              &lt;cit:Request&gt;
                 &lt;!--Optional:--&gt;
                 &lt;proc:RfqXmlData&gt;
                  xmldata
                 &lt;/proc:RfqXmlData&gt;
              &lt;/cit:Request&gt;
           &lt;/tem:request&gt;
        &lt;/tem:ProcessRfq&gt;
     &lt;/soapenv:Body&gt;
  &lt;/soapenv:Envelope&gt;
  </code></pre>
  
  <p>This works in SOAP UI when passing some random string in the  tag:</p>
  
  <pre><code>&lt;proc:RfqXmlData&gt;
      random string
  &lt;/proc:RfqXmlData&gt;
  </code></pre>
  
  <p>but gives an error when passing the required XML data:</p>
  
  <pre><code>&lt;proc:RfqXmlData&gt;
      &lt;Rfq&gt;&lt;IsAbove30k&gt;true&lt;/IsAbove30k&gt;&lt;ReferenceNumber&gt;ReferenceNumber1&lt;/ReferenceNumber&gt;&lt;ContactPersonName&gt;ContactPersonName1&lt;/ContactPersonName&gt;&lt;ContactPersonTelephoneNumber&gt;ContactPersonTe1&lt;/ContactPersonTelephoneNumber&gt;&lt;ContactPersonCellPhone&gt;ContactPersonCe1&lt;/ContactPersonCellPhone&gt;&lt;BuyerName&gt;BuyerName1&lt;/BuyerName&gt;&lt;BuyerTelephoneNumber&gt;BuyerTelephoneN111111111111111111111&lt;/BuyerTelephoneNumber&gt;&lt;BuyerEmailAddress&gt;BuyerEmailAddress1&lt;/BuyerEmailAddress&gt;&lt;ProcurementItem&gt;&lt;Title&gt;Title111111111111111111111111&lt;/Title&gt;&lt;ClosingDate&gt;1900-01-01T01:01:01+02:00&lt;/ClosingDate&gt;&lt;Description&gt;Description11111111111111111&lt;/Description&gt;&lt;CaptureDate&gt;1900-01-01T01:01:01+02:00&lt;/CaptureDate&gt;&lt;/ProcurementItem&gt;&lt;RfqGood&gt;&lt;DeliveryTo&gt;DeliveryTo1&lt;/DeliveryTo&gt;&lt;DeliveryAddress&gt;DeliveryAddress1&lt;/DeliveryAddress&gt;&lt;DeliverySuburb&gt;DeliverySuburb1&lt;/DeliverySuburb&gt;&lt;DeliveryPostalCode&gt;1&lt;/DeliveryPostalCode&gt;&lt;SubmissionFax&gt;SubmissionFax1&lt;/SubmissionFax&gt;&lt;Specification&gt;Specification1&lt;/Specification&gt;&lt;SubmissionFax2&gt;SubmissionFax21&lt;/SubmissionFax2&gt;&lt;DeliveryDate&gt;1900-01-01T01:01:01+02:00&lt;/DeliveryDate&gt;&lt;Good&gt;Tools &amp;amp; Machinery&lt;/Good&gt;&lt;/RfqGood&gt;&lt;/Rfq&gt;
  &lt;/proc:RfqXmlData&gt;
  </code></pre>
  
  <p>Error:</p>
  
  <pre><code>&lt;faultstring xml:lang="en-ZA"&gt;The formatter threw an exception while trying to deserialize the message: There was an error while trying to deserialize parameter http://tempuri.org/:request. The InnerException message was 'There was an error deserializing the object of type ProcurementAdministrationPortal.WebService.Messages.SendRfqRequest. End element 'RfqXmlData' from namespace 'http://schemas.datacontract.org/2004/07/ProcurementAdministrationPortal.WebService.DataTransferObjects' expected. Found element 'Rfq' from namespace ''. Line 22, position 10.'.  Please see InnerException for more details.&lt;/faultstring&gt;
  </code></pre>
  
  <p>It looks like its trying to deserialize <code>&lt;Rfq&gt;...&lt;/Rfq&gt;</code>. It seems to me that what I must do is get the service to see the XML data as a string and not as XML. I do still need it to be XML on the other side, though.</p>