What is the namespace used for in a SOAP web service?
SOAP defines two namespaces: The SOAP envelope, the root element of a SOAP message, has the following namespace identifier: "http://schemas.xmlsoap.org/soap/envelope" The SOAP serialization, the URI defining SOAP's serialization rules, has the following namespace identifier: "http://schemas.xmlsoap.org/soap/encoding"
The SOAP header contains header entries defined in a namespace. The header is encoded as the first immediate child element of the SOAP envelope. When multiple headers are defined, all immediate child elements of the SOAP header are interpreted as SOAP header blocks.
SOAP is a messaging protocol for exchanging information between two computers based on XML over the internet. SOAP messages are purely written in XML which is why they are platform and language independent. A SOAP message contains: An Envelope that indicates the start and end of the message.
An XML namespace is a collection of names that can be used as element or attribute names in an XML document. The namespace qualifies element names uniquely on the Web in order to avoid conflicts between elements with the same name.
From http://tempuri.org/:
Each XML Web Service needs a unique namespace in order for client applications to distinguish it from other services on the Web. By default, ASP.Net Web Services use http://tempuri.org/ for this purpose. While this suitable for XML Web Services under development, published services should use a unique, permanent namespace.
Your XML Web Service should be identified by a namespace that you control. For example, you can use your company's Internet domain name as part of the namespace. Although many namespaces look like URLs, they need not point to actual resources on the Web.
Say company A and B both create a service with methods of the same signature. In order to differentiate between them you can add a namespace. That would make them different from a client's perspective, meaning you couldn't use the wsdl(proxy classes) from one on the other and vice verse.
It's considered good practice to use a unique namespace for your services. Typically your company name/domain or similar, instead of the default tempuri.org
.
Namespace is an XML concept. Suppose you have an XML document about books which have an element <title>
, and a document about persons which have an element <title>
. Both <title>
elements have a different conceptual meaning, even though they have the same name. If you would merge the documents, you would not see the difference between the two.
That is where the namespace comes in. The full name of an element consists of the namespace and the element name, but the namespace is often abbreviated or omitted.
XML lets you use define shorter words for namespaces. For example, you can define that b=http://www.books.info/my_books
and after that you can use <b:title>
if you mean the title from that namespace.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With