简体   繁体   English

WCF RESTful服务-如何使我的服务在请求中不需要xmlns属性?

[英]WCF RESTful service - How do I make my service not need the xmlns attribute in a request?

I am building a RESTful service that works when a request has the xmlns attribute in it. 我正在构建一个RESTful服务,当请求中具有xmlns属性时,该服务即可使用。 However, I need to make the service able to take request without the xmlns attribute. 但是,我需要使服务能够在没有xmlns属性的情况下接受请求。

This is what I have working now: 这是我现在正在工作的内容:

<ITEM_SEND xmlns="http://schemas.datacontract.org/2004/07/WCFInventoryService">
  <TRAN_ID>9483564</TRAN_ID>
  <VENDOR_PART>D336</VENDOR_PART>
</ITEM_SEND>

This is what I need to accept as a request: 这是我需要接受的请求:

<ITEM_SEND>
  <TRAN_ID>9483564</TRAN_ID>
  <VENDOR_PART>D336</VENDOR_PART>
</ITEM_SEND>

Here is my interface: 这是我的界面:

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; }
    }
}

I've tried altering the namespace for the Data contract that I have for my request by setting it to "". 我尝试通过将其设置为“”来更改请求所具有的数据协定的名称空间。

[DataContract(Namespace = "")]
    public class ITEM_SEND
    {
        public string TRAN_ID { get; set; }
        public string VENDOR_PART { get; set; }
    } 

But that didn't work as when I view my svc in the browser my request changes from 但这不起作用,因为当我在浏览器中查看我的svc时,我的请求从 没有命名空间=“”

With Namesspace =“”

You can explicitly define your data contracts to not belong to any namespace- 您可以明确定义数据协定,使其不属于任何名称空间-

[DataContract(Namespace = "")]
public class ITEM_SEND
{
    [DataMember]
    public string TRAN_ID { get; set; }
    [DataMember]
    public string VENDOR_PART { get; set; }
}

Hope this helps 希望这可以帮助

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM