Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / XML / June 2007

Tip: Looking for answers? Try searching our database.

XML getting the namespace

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
maflatoun@gmail.com - 28 Jun 2007 02:14 GMT
Hi,

I'm working on a ASP.NET component with one requirement being to catch
Web Service exceptions. I've managed to get it working using the
following code

XmlDocument doc = new XmlDocument();
doc.LoadXml(se.Detail.OuterXml);
XmlNamespaceManager nsManager = new
XmlNamespaceManager(doc.NameTable);

nsManager.AddNamespace("prefix", "http://localhost/site/test/
webservice.asmx");

string errorMessage = doc.DocumentElement.SelectSingleNode("//
prefix:ErrorMessage", nsManager).InnerText;
Response.Write("Error message:" + errorMessage);

The issue is that the namespace changes depending on where the web
service resides (ex. staging, production, local computer). How can I
get the http://localhost/site/test/webservice.asmx dynamically (parse
it from XmlDocument?)

Thanks
Maz
Martin Honnen - 28 Jun 2007 12:47 GMT
> The issue is that the namespace changes depending on where the web
> service resides (ex. staging, production, local computer). How can I
> get the http://localhost/site/test/webservice.asmx dynamically (parse
> it from XmlDocument?)

I would suggest to configure your web service in a way that the
namespace does not change. That is possible as a namespace does not have
to refer to an existing resource.

If you want to read out namespaces from an XmlDocument then how you do
that depends on the structure of the XML. If there is just one default
namespace declaration on the root element e.g.
  <root xmlns="http://example.com/2007/ns1">
then you can simply access
  doc.DocumentElement.namespaceURI
(where doc is your XmlDocument instance).

Using SelectSingleNode or SelectNodes you are also able to access the
namespace nodes the XPath data model knows. If you need help with that
then show us a relevant sample of the XML.

Signature

    Martin Honnen --- MVP XML
    http://JavaScript.FAQTs.com/

maflatoun@gmail.com - 28 Jun 2007 14:19 GMT
> maflat...@gmail.com wrote:
> > The issue is that the namespace changes depending on where the web
[quoted text clipped - 22 lines]
>         Martin Honnen --- MVP XML
>        http://JavaScript.FAQTs.com/

Thank you for your reply. Can you please show me or point me to an
article for configuring web services in a way that the namespace does
not change?

Thanks
Maz.
maflatoun@gmail.com - 28 Jun 2007 14:23 GMT
On Jun 28, 9:19 am, maflat...@gmail.com wrote:

> > maflat...@gmail.com wrote:
> > > The issue is that the namespace changes depending on where the web
[quoted text clipped - 31 lines]
>
> - Show quoted text -

Never mind. Dumb question. I got it.

Thx
Maz
Martin Honnen - 28 Jun 2007 14:27 GMT
> Can you please show me or point me to an
> article for configuring web services in a way that the namespace does
> not change?

The namespace URI is simply a name so you can set up your namespaces
with an attribute as follows:

[WebService(Description="My Service", Namespace="http://example.com/ws1/")]

Choose a name that you own/control like a domain name you control.

Signature

    Martin Honnen --- MVP XML
    http://JavaScript.FAQTs.com/


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.