Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SOAP - namespace, what is this used for?

Tags:

c#

asp.net

What is the namespace used for in a SOAP web service?

like image 581
001 Avatar asked Jun 19 '10 12:06

001


People also ask

What is a SOAP namespace?

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"

What is SOAP header namespace?

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.

What is the purpose of SOAP in a web service?

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.

What is the purpose of namespace in XML?

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.


2 Answers

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.

like image 109
Mikael Svenson Avatar answered Sep 25 '22 17:09

Mikael Svenson


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.

like image 40
Sjoerd Avatar answered Sep 23 '22 17:09

Sjoerd