0

I have the code below.

namespace IrancellSmsServer
{

          [WebService(Namespace = "http://www.csapi.org/schema/parlayx/data/sync/v1_0/local")]

    public class SoapServer : System.Web.Services.WebService
    {

         [SoapDocumentMethod(Action = "",ParameterStyle = SoapParameterStyle.Bare)]


        [WebMethod]
        public syncOrderRelationResponse syncOrderRelation(
            Sync.UserID userID,
            string spID,
            string productID,
            string serviceID,
            string serviceList,
            int updateType,
            string updateTime,
            string updateDesc,
            string effectiveTime,
            string expiryTime,
            item[] extensionInfo
            )
        {


            syncOrderRelationResponse a = new syncOrderRelationResponse();
            a.result = 0;
            a.resultDescription = "OK";

            return a;
        }

which generates this for me :

<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
  <soap:Body>
    <userID xmlns="http://www.csapi.org/schema/parlayx/data/sync/v1_0/local">
      <ID xmlns="">string</ID>
      <type xmlns="">int</type>
    </userID>
    <spID xmlns="http://www.csapi.org/schema/parlayx/data/sync/v1_0/local">string</spID>
    <productID xmlns="http://www.csapi.org/schema/parlayx/data/sync/v1_0/local">string</productID>
    <serviceID xmlns="http://www.csapi.org/schema/parlayx/data/sync/v1_0/local">string</serviceID>
    <serviceList xmlns="http://www.csapi.org/schema/parlayx/data/sync/v1_0/local">string</serviceList>
    <updateType xmlns="http://www.csapi.org/schema/parlayx/data/sync/v1_0/local">int</updateType>
    <updateTime xmlns="http://www.csapi.org/schema/parlayx/data/sync/v1_0/local">string</updateTime>
    <updateDesc xmlns="http://www.csapi.org/schema/parlayx/data/sync/v1_0/local">string</updateDesc>
    <effectiveTime xmlns="http://www.csapi.org/schema/parlayx/data/sync/v1_0/local">string</effectiveTime>
    <expiryTime xmlns="http://www.csapi.org/schema/parlayx/data/sync/v1_0/local">string</expiryTime>
    <extensionInfo xmlns="http://www.csapi.org/schema/parlayx/data/sync/v1_0/local">
      <item>
        <key xmlns="">string</key>
        <value xmlns="">string</value>
      </item>
      <item>
        <key xmlns="">string</key>
        <value xmlns="">string</value>
      </item>
    </extensionInfo>
  </soap:Body>
</soap:Envelope>

I want those xmlns="http://www.csapi.org/schema/parlayx/data/sync/v1_0/local to be removed . I was OK before until I added this line

 [SoapDocumentMethod(Action = "",ParameterStyle = SoapParameterStyle.Bare)]

after I added the line I started getting this extra namespaces;

what I want to be generate is like this :

<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
  <soap:Body>
    <userID>
      <ID xmlns="">string</ID>
      <type xmlns="">int</type>
    </userID>
    <spID>string</spID>
    <productID>string</productID>
    <serviceID>string</serviceID>
    <serviceList>string</serviceList>
    <updateType>int</updateType>
    <updateTime>string</updateTime>
    <updateDesc>string</updateDesc>
    <effectiveTime>string</effectiveTime>
    <expiryTime>string</expiryTime>
    <extensionInfo>
      <item>
        <key xmlns="">string</key>
        <value xmlns="">string</value>
      </item>
      <item>
        <key xmlns="">string</key>
        <value xmlns="">string</value>
      </item>
    </extensionInfo>
  </soap:Body>
</soap:Envelope>

what should I do . thanks.

Ghasem
  • 14,455
  • 21
  • 138
  • 171
  • Possible duplicate of [How to remove all namespaces from XML with C#?](http://stackoverflow.com/questions/987135/how-to-remove-all-namespaces-from-xml-with-c) – Orel Eraki Feb 06 '16 at 10:12

1 Answers1

0

Check this answer and try the recursive function:

//Implemented based on interface, not part of algorithm
public static string RemoveAllNamespaces(string xmlDocument)
{
    XElement xmlDocumentWithoutNs = RemoveAllNamespaces(XElement.Parse(xmlDocument));

    return xmlDocumentWithoutNs.ToString();
}

//Core recursion function
 private static XElement RemoveAllNamespaces(XElement xmlDocument)
    {
        if (!xmlDocument.HasElements)
        {
            XElement xElement = new XElement(xmlDocument.Name.LocalName);
            xElement.Value = xmlDocument.Value;

            foreach (XAttribute attribute in xmlDocument.Attributes())
                xElement.Add(attribute);

            return xElement;
        }
        return new XElement(xmlDocument.Name.LocalName, xmlDocument.Elements().Select(el => RemoveAllNamespaces(el)));
    }
Community
  • 1
  • 1
Ghasem
  • 14,455
  • 21
  • 138
  • 171