B
B
Botalov_Nikita2015-09-25 07:49:06
SOAP
Botalov_Nikita, 2015-09-25 07:49:06

How to correctly specify namespacs in WCF services?

When developing SOAP services, such a problem arose. All messages (XML), incoming or outgoing, have the following structure
0323b04c9c604331a3727626e83891e2.png
For example:

<?xml version="1.0" encoding="UTF-8"?><SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"><SOAP-ENV:Header/><SOAP-ENV:Body><ns5:cancelBookingResponse xmlns:ns2="http://epgu.rtlabs.ru/equeue/ws/types/" xmlns:ns3="http://smev.gosuslugi.ru/rev120315" xmlns:ns4="http://www.w3.org/2004/08/xop/include" xmlns:ns5="http://epgu.rtlabs.ru/equeue/ws/"><ns3:Message><ns3:Status>RESULT</ns3:Status></ns3:Message><ns3:MessageData><ns3:AppData><ns5:bookId>710019_2</ns5:bookId><ns5:status><ns2:statusCode>201</ns2:statusCode><ns2:statusMessage>Отозвано</ns2:statusMessage></ns5:status></ns3:AppData></ns3:MessageData></ns5:cancelBookingResponse></SOAP-ENV:Body></SOAP-ENV:Envelope>

Thus, the underlying contracts (AppDada, Message, etc.) always have a constant namespace. When developing, I wanted to implement base classes from which I would already inherit contracts for certain cases.
/// <summary>
    /// 
    /// </summary>
    [DataContract(Namespace = "http://epgu.rtlabs.ru/equeue/ws/")]
    public class AppDataBase
    {
    }
    [DataContract]
    public class AppDataInCancelBooking : AppDataBase
    {
        /// <summary>
        /// 
        /// </summary>
        [DataMember]
        public string BookId { get; set; }

        /// <summary>
        /// 
        /// </summary>
        [DataMember]
        public string EsiaId { get; set; }

        /// <summary>
        /// 
        /// </summary>
        [DataMember]
        public string Password { get; set; }
    }

But in this case, it is not clear how to specify namespace for DataMembers.
If instead of DataContract we use MessageContract, then when we use an instance of this MessageContract as a MessageBodyMember, then for some reason the namespace of this MessageBodyMember is not inherited.
In general, something like this. If anyone knows the best way to implement this, please help.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Artur Nurullin, 2015-10-31
@Splo1ter

Not an option to simply add a link to the WCF service to Visual Studio, will it generate classes for you?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question