Wim's .NET blog

October 2005 - Posts

I've launched the very first stage of my Photography Critiques community website, PhotoCritters.com.

People that are interested can reserve their spot in the initial beta program, which is limited to 1,000 beta users.

If you're interested in photography, please have a look.


Posted: Oct 14 2005, 05:50 PM by Wim | with 3 comment(s)
Filed under: ,
Possible Bug : HttpPost and class name conflicts
A colleague and friend of mine run into some very odd web service behaviour on ASP.NET 1.1. Anyone who can shed some light on this, please leave a comment. I have pasted his exact text describing the problem below.

Included below is a minimal web-service implementation to recreate a problem
I've encountered in a web service that has methods returning classes with the
same local name (but in different namespaces).

If only the SoapHttp protocol is enabled in the web.config, everything works
as expected - with the different "Something" classes being serialized in to
different XML namespaces as defined by the ResponseNamespace property of the
SoapDocumentMethod attributes.

However - if HttpPost or HttpPostLocalhost are enabled (the latter being
enabled by default), and I browse to the asmx file in IE, I get this error :

Types NsProblem.B.Something and NsProblem.A.Something both use the XML type
name, Something, from namespace http://example/NsProblem/. Use XML attributes
to specify a unique XML name and/or namespace for the type.

If I un-comment both of the "XmlRoot" elements I get this error

The XML element named 'Something' from namespace 'http://example/NsProblem/'
references distinct types NsProblem.A.Something and NsProblem.B.Something.
Use XML attributes to specify another XML name or namespace for the element
or types.

Now for the really strange bit : leave one XmlRoot attribute commented, and
the other not, and it works!

When it is working, the example responses (on whatever.asmx?op=GetArrayA)
don't appear to tbe any difference!

(aside: I also tried setting the responses to be different using Xml
Serialization attributes, i.e. putting [return: XmlElement(... )] on the
methods, but like the SoapDocumentMethod attribute this only seemed to change
the response for the Soap method - making no difference to the HTTP POST

Various workarounds are available
 - disable (remove) "HttpPost" and "HttpPostLocalhost" in web.config
 - Rename the classes (making the namespaces redundant)
but I would prefer to be able to keep the class names as they are, and keep
the HttpPostLocalhost enabled for testing / debugging purposes - and I
anticipate needing to support 3 or more classes with the same local-name
across different namespaces.

---- Minimal test case ----

<%@ WebService Language="c#" Class="NsProblem.XmlTestSvc" %>
using System;
using System.Web.Services;
using System.Web.Services.Protocols;
using System.Xml.Serialization;

namespace NsProblem.A
//    [XmlRoot(Namespace="AAAA")]
    public class Something { }

namespace NsProblem.B
//    [XmlRoot(Namespace="BBBB")]
    public class Something { }

namespace NsProblem
    [WebService(Description="Conflicting name problem example",
    public class XmlTestSvc : System.Web.Services.WebService
        public NsProblem.A.Something[] GetArrayA() { return null; }
        public NsProblem.B.Something[] GetArrayB() { return null; }

Posted: Oct 02 2005, 11:33 PM by Wim | with no comments
Filed under: ,
More Posts