Kram_Koorbse Kram_Koorbse - 1 month ago 9
reST (reStructuredText) Question

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. However, I need to make the service able to take request without the xmlns attribute.

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
Without Namespace = ""

With Namesspace = ""

Answer

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

Comments