【发布时间】:2016-10-04 19:22:55
【问题描述】:
我正在构建一个 RESTful 服务,该服务在请求中包含 xmlns 属性时工作。但是,我需要让服务能够在没有 xmlns 属性的情况下接受请求。
这就是我现在的工作:
<ITEM_SEND xmlns="http://schemas.datacontract.org/2004/07/WCFInventoryService">
<TRAN_ID>9483564</TRAN_ID>
<VENDOR_PART>D336</VENDOR_PART>
</ITEM_SEND>
这是我需要接受的请求:
<ITEM_SEND>
<TRAN_ID>9483564</TRAN_ID>
<VENDOR_PART>D336</VENDOR_PART>
</ITEM_SEND>
这是我的界面:
namespace WCFInventoryService
{
// NOTE: You can use the "Rename" command on the "Refactor" menu to change the interface name "IService1" in both code and config file together.
[ServiceContract(Namespace = "")]
public interface IInvService
{
[OperationContract]
//[WebGet(UriTemplate="/Employees",ResponseFormat=WebMessageFormat.Xml )]
//Employee[] GetEmployees();
[WebInvoke(Method = "POST",
RequestFormat = WebMessageFormat.Xml,
ResponseFormat = WebMessageFormat.Xml,
BodyStyle = WebMessageBodyStyle.Bare,
UriTemplate = "")]
ITEM_REPLY GetInventory(ITEM_SEND query);
}
public class ITEM_SEND
{
public string TRAN_ID { get; set; }
public string VENDOR_PART { get; set; }
}
}
我已尝试通过将数据协定设置为“”来更改我的请求的数据协定的命名空间。
[DataContract(Namespace = "")]
public class ITEM_SEND
{
public string TRAN_ID { get; set; }
public string VENDOR_PART { get; set; }
}
【问题讨论】:
-
如果您仍然可以选择我会切换到 JSON。没有命名空间。