06 March 2006

Issues Migrating from .NET 1.0 to .NET 1.1

Mainstream support for .NET 1.0 ends 30 June 2007. For organisations migrating from .NET 1.0 to .NET 1.1, the following changes are for  consideration:
In addition to the changes listed above, the following issues were encountered during a recent migration activity.

Web Service WSDL Generation Issue

After upgrading websites from ASP.NET 1.0 to 1.1, the following error message may be encountered:

    The XML element named 'HelloWorldMethodResponse' from namespace 'http://www.test.com' references a method and a type. Change the method's message name using WebMethodAttribute or change the type's root element using the XmlRootAttribute.

This error occurs when the WSDL for a web service is being generated. Note that the error message includes two possible solutions. The first of these solutions which recommends changing the web methods message name using the WebMethodAttribute is undesirable as this will alter the WSDL contract and break existing consumers. The second of the two solutions, applying the XmlRoot attribute to the web methods return type, will resolve the error, however, this requires recompilation of existing web service assemblies.

Properties of web methods that cause this error include:

  • The return type is a class or structure;
  • The return type is named [WebMethodName]Response;
  • The web method accepts no parameters (or has parameters that do not serialise to a complex type in the WSDL, for example, strings, integers).

This error does not affect the invocation of existing client proxies as they do not consume the WSDL at runtime.  This issue will affect development activities when the WSDL is requested, for example, when re-generating client-side proxies using the Visual Studio Add/Update Web Reference feature.

To resolve this issue, apply the XmlRoot attribute to the return type of the WebMethod, noting the following:

  • The ElementName should be of the form [ResponseType]Dummy. Note that no element named HelloWorldMethodResponseDummy will appear in the WSDL;
  • The DataType property should be set to the response type.

An example application of the XmlRoot attribute is as follows:

[WebMethod(Description = "Test Method")]
[return: XmlRoot(Namespace = "http://www.test.com/",
        ElementName = "HelloWorldMethodResponseDummy",
        DataType = "HelloWorldMethodResponse",
        IsNullable = false)]
public HelloWorldMethodResponse HelloWorldMethod()
{
    return new HelloWorldMethodResponse();
}

Activator.CreateInstance() raises a System.MissingMethodException exception when creating instances of Arrays

In order for the Activator.CreateInstance() method to create instances of a given type, the type must define a public default constructor. In .NET 1.0, the Activator does not raise an exception when creating instances of Arrays (which has a private default constructor), however, this issue has been fixed for .NET 1.1 and now raises a System.MissingMethodException ("No parameterless constructor defined for this object") exception as expected.

To resolve this issue, the Array.CreateInstance() method can be used instead of Activator.CreateInstance(), as follows:
...

if (typeToInstantiate.IsArray)
{
    Type elementType = typeToInstantiate.GetElementType();
    newInstance = Array.CreateInstance(elementType, arraySize);
}
else
{
    newInstance = Activator.CreateInstance(typeToInstantiate);
}

Filed under:
 

Comment Notification

If you would like to receive an email when updates are made to this post, please register here

Subscribe to this post's comments using RSS

Comments

# elena said:
I have simmilar problem like:

The XML element named 'HelloWorldMethodResponse' from namespace 'http://www.test.com' references a method and a type. Change the method's message name using WebMethodAttribute or change the type's root element using the XmlRootAttribute.

I added
[return: XmlRoot(Namespace = "http://www.test.com/",
       ElementName = "HelloWorldMethodResponseDummy",
       DataType = "HelloWorldMethodResponse",
       IsNullable = false)]

but it does not compile, I have error:
The type or namespace name 'XmlRoot' could not be found (are you missing a using directive or an assembly reference?)

do I miss some reference?


14 December 06 at 8:20 PM
# matt said:
Hi Elena,

The XmlRootAttribute class is defined in the System.Xml assembly, in the System.Xml.Serialization namespace, can you check if you have a reference + using declaration for these?

Cheers,
Matt
03 January 07 at 9:10 PM
# Roland Kübert said:

Hi Matt,

thanks a million for the hint for "Web Service WSDL Generation Issue", I have struggled with that quite some time before I found your page.

Kind Regards,

Roland

07 October 08 at 9:29 AM

Leave a Comment

Comment Policy: No HTML allowed. URIs and line breaks are converted automatically. Your e–mail address will not show up on any public page.

(required) 
(optional)
(required) 
(required)
captcha Image