none
How to set default namespace xmlns RRS feed

  • Question

  • Hello. I've made WCF servce with next attributes:

    using System.ServiceModel;
    using System.Xml.Serialization;
    
    namespace try_ns
    {
        [ServiceContract(Namespace = "urn:myns")]
        [ServiceBehavior(Namespace = "urn:myns")]
        [XmlSerializerFormat]
    
        public class tears
        {
            [OperationContract(Action = "urn:checkAction")]
            public ResponseX check(RequestX request)
            {
                ResponseX r = new ResponseX();
                r.SS = request.S + request.S;
                return r;
            }
    
            public class RequestX
            {
                [XmlElement]
                public string S;
            }
    
            public class ResponseX
            {
                [XmlElement]
                public string SS;
            }
        }
    }
    

    When I try to make a request, I get next soap envelope, generated by SoapUI:

    <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:urn="urn:myns">
       <soapenv:Header/>
       <soapenv:Body>
          <urn:check>
             <urn:request>
                <urn:S>10</urn:S>
             </urn:request>
          </urn:check>
       </soapenv:Body>
    </soapenv:Envelope>

    How can I specified the default namespace xmlns with no prefix :urn to be able to use elements as my users prefer? Please? help! Please look at valid envelope:

    <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns="urn:myns" xmlns:urn="urn:myns">
       <soapenv:Header/>
       <soapenv:Body>
          <urn:check>
             <request>
                <S>10</S>
             </request>
          </urn:check>
       </soapenv:Body>
    </soapenv:Envelope>

    Wednesday, September 21, 2016 4:15 PM

Answers

  • Hello K.Lopez,

    I have run into similar issues in the past when dealing with some clients that used a bespoke method of parsing the response.  Your example appears to deal with the request so I am not sure exactly what you mean.  Both document are equivalent XML just ones uses explicit namespaces and the second is a document namespace.  if you are the service, it should not matter.

    If you are talking about the response then it is a bit of a pain so if the client(s) is not flexible and insists on requiring ugly looking xml then you will need to implement some form message encoding.  Here is a great example:

    https://blogs.msdn.microsoft.com/carlosfigueira/2010/06/12/changing-prefixes-in-xml-responses-for-wcf-services/



    Cheers, Jeff

    Wednesday, September 21, 2016 10:51 PM