1

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.

The structure of the request message is as follows:

public class DtoRequest<T> : IDtoRequest where T : class
{
    public InteractionContext Context { get; set; }
    public T Request { get; set; }
}

where the type is a class of the following

public class SendRfqRequest : DtoRequest<ImportRfqDataDto>
{
}

[DataContract]
public class ImportRfqDataDto
{
    [DataMember]
    public string RfqXmlData { get; set; }
}

The InteractionContext takes the following fields:

public class InteractionContext
{
    public string Application { get; set; }
    public string License { get; set; }
    public DateTime TimeStamp { get; set; }
    public Guid Id { get; set; }
}

I deployed this on a webservicesdev server, generated code to use it with wsdl.exe and tested it with a simple console application:

// 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);

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:

<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">
   <soapenv:Header/>
   <soapenv:Body>
      <tem:ProcessRfq>
         <!--Optional:-->
         <tem:request>
            <!--Optional:-->
            <cit:Context>
               <!--Optional:-->
               <cit:Application>SAPClient</cit:Application>
               <!--Optional:-->
               <cit:Id>1a975cab-bc7c-47e3-aa77-ac9dc407721d</cit:Id>
               <!--Optional:-->
               <cit:License>1a975cab-bc7c-47e3-aa77-ac9dc407721d</cit:License>
               <!--Optional:-->
               <cit:TimeStamp>2014-01-01</cit:TimeStamp>
            </cit:Context>
            <!--Optional:-->
            <cit:Request>
               <!--Optional:-->
               <proc:RfqXmlData>
                xmldata
               </proc:RfqXmlData>
            </cit:Request>
         </tem:request>
      </tem:ProcessRfq>
   </soapenv:Body>
</soapenv:Envelope>

This works in SOAP UI when passing some random string in the tag:

<proc:RfqXmlData>
    random string
</proc:RfqXmlData>

but gives an error when passing the required XML data:

<proc:RfqXmlData>
    <Rfq><IsAbove30k>true</IsAbove30k><ReferenceNumber>ReferenceNumber1</ReferenceNumber><ContactPersonName>ContactPersonName1</ContactPersonName><ContactPersonTelephoneNumber>ContactPersonTe1</ContactPersonTelephoneNumber><ContactPersonCellPhone>ContactPersonCe1</ContactPersonCellPhone><BuyerName>BuyerName1</BuyerName><BuyerTelephoneNumber>BuyerTelephoneN111111111111111111111</BuyerTelephoneNumber><BuyerEmailAddress>BuyerEmailAddress1</BuyerEmailAddress><ProcurementItem><Title>Title111111111111111111111111</Title><ClosingDate>1900-01-01T01:01:01+02:00</ClosingDate><Description>Description11111111111111111</Description><CaptureDate>1900-01-01T01:01:01+02:00</CaptureDate></ProcurementItem><RfqGood><DeliveryTo>DeliveryTo1</DeliveryTo><DeliveryAddress>DeliveryAddress1</DeliveryAddress><DeliverySuburb>DeliverySuburb1</DeliverySuburb><DeliveryPostalCode>1</DeliveryPostalCode><SubmissionFax>SubmissionFax1</SubmissionFax><Specification>Specification1</Specification><SubmissionFax2>SubmissionFax21</SubmissionFax2><DeliveryDate>1900-01-01T01:01:01+02:00</DeliveryDate><Good>Tools &amp; Machinery</Good></RfqGood></Rfq>
</proc:RfqXmlData>

Error:

<faultstring xml:lang="en-ZA">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.</faultstring>

It looks like its trying to deserialize <Rfq>...</Rfq>. 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.

2
  • Can you try <![CDATA[]]> to wrap xml content Commented Nov 21, 2014 at 11:32
  • @Anand: Yeah. <![CDATA[]]> was exactly what I was looking for. Commented Nov 21, 2014 at 11:46

1 Answer 1

3

Wrap the piece of XML in a <![CDATA[]]> tag.

CDATA stands for Character Data and it means that the data in between these tags includes data that could be interpreted as XML markup, but should not be.”

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.