Bhav
Bhav

Reputation: 2185

RESTful service not returning expected XML

I have a WCF Rest Service that currently returns an xml response as shown below.

xml response

However, it should be returned in the following format and I can't get it to output as such. Any help to get the correct output would be appreciated.

<app:get-order-details-response xmlns:apps="http://app.com/123/abc/">
    <organisation-id>123</organisation-id>
    <app2app-id>Mer001</app2app-id>
    <order-id>100</order-id>
    <order-price>0</order-price>
    <response-handler>yourapp://response/parameter1</response-handler>
    <failure-response-handler>yourapp://response/parameter2</failure-response-handler>        
</app:get-order-details-response>

The code that generates the current xml is shown below. Is it because I'm returning an XmlElement? I've tried returning the XmlDocument and changing the code in the interface to do this, but that doesn't resolve this.

public XmlElement GetOrderDetails(string organisationID, string paymentReference, int paymentType, string deviceType)
    {
        .....
        .....
        .....
        XmlDocument doc = new XmlDocument();

        XmlElement root = doc.CreateElement("app:get-order-details-response", "http://app.com/123/abc/");
        doc.AppendChild(root);
        CreateElement(doc, root, "organisation-id", organisationID);
        CreateElement(doc, root, "app2app-id", app2appID);
        CreateElement(doc, root, "order-id", paymentReference;
        CreateElement(doc, root, "order-price", paymentAmount);
        CreateElement(doc, root, "response-handler", responseHandler);
        CreateElement(doc, root, "failure-response-handler", failureResponseHandler);

        return root;
    }

Interface:

[ServiceContract]
public interface IPaymentService
{
    [OperationContract]
    [WebInvoke(RequestFormat = WebMessageFormat.Xml, 
        ResponseFormat = WebMessageFormat.Xml, 
        BodyStyle = WebMessageBodyStyle.Wrapped, 
        Method = "GET",
        UriTemplate = "/getorderdetails/v1/aa/order/{organisationID}/{paymentReference}?paymentType={paymentType}&deviceType={deviceType}")]
    XmlElement GetOrderDetails(string organisationID, string paymentReference, int paymentType, string deviceType);
}

UPDATE:

After making the modification that Pankaj suggested below, the output appears as it should be in IE. However, when testing this against a test toolkit, I get an error message, saying "Cannot find the declaration of element 'app:get-order-details-response'. What does this mean?

Upvotes: 0

Views: 144

Answers (1)

Pankaj Kapare
Pankaj Kapare

Reputation: 7792

Try changing

BodyStyle = WebMessageBodyStyle.Wrapped

to

BodyStyle = WebMessageBodyStyle.WrappedRequest

OR

BodyStyle = WebMessageBodyStyle.Bare

Upvotes: 1

Related Questions