[英]WCF RESTful service - How do I make my service not need the xmlns attribute in a request?
我正在构建一个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; }
}
您可以明确定义数据协定,使其不属于任何名称空间-
[DataContract(Namespace = "")]
public class ITEM_SEND
{
[DataMember]
public string TRAN_ID { get; set; }
[DataMember]
public string VENDOR_PART { get; set; }
}
希望这可以帮助
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.