0
我有一个WCF Rest服务,当前返回一个xml响应,如下所示。RESTful服务没有返回预期的XML
但是,应该按以下格式返回,我无法得到它的输出这样。任何帮助获得正确的输出将不胜感激。
<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>
生成当前xml的代码如下所示。是因为我返回一个XmlElement?我试过返回XmlDocument并更改界面中的代码来完成此操作,但这并不能解决此问题。
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;
}
接口:
[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:
使得该的Pankaj以下所建议的修改后,则输出如它应该是在IE中。然而,测试这对一个测试工具包的时候,我得到一个错误信息,说“找不到元素的声明‘应用程序:获取订单的详细信息响应’。这是什么意思
谢谢。顶部的修改似乎看在IE中输出时的工作。但是,测试这种对一个测试工具包的时候,我得到一个错误信息,说“无法找到声明元素'app:get-order-details-response'。这是什么意思? – Bhav
这意味着它无法找到命名空间“应用程序”的定义。我不知道你使用的是什么工具包,或者它是如何配置的。可能重新配置你的测试工具应该可以解决这个问题。 –