我有一个WCF Rest Service,它当前返回一个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);
}
更新
在进行Pankaj下面建议的修改后,输出显示为应该在IE中。但是,在对测试工具包进行测试时,我收到一条错误消息,说“#34;无法找到元素声明&app:get-order-details-response&#39;。这是什么意思?
答案 0 :(得分:1)
尝试更改
BodyStyle = WebMessageBodyStyle.Wrapped
到
BodyStyle = WebMessageBodyStyle.WrappedRequest
OR
BodyStyle = WebMessageBodyStyle.Bare