簡體   English   中英

WCF RESTful服務-如何使我的服務在請求中不需要xmlns屬性?

[英]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; }
    } 

但這不起作用,因為當我在瀏覽器中查看我的svc時,我的請求從 沒有命名空間=“”

With Namesspace =“”

您可以明確定義數據協定,使其不屬於任何名稱空間-

[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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM