Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Problem with c# webservice, referencing a method and a type

I have run into a bit of a problem, well not sure if it is a problem, but would like some advice.

I have developed a c# webservice in vs2010 and when I debug the service i get this error in my browser

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

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.InvalidOperationException: The XML element 'VoucherResponse' from namespace 'test.org' references a method and a type. Change the method's message name using WebMethodAttribute or change the type's root element using the XmlRootAttribute.

Source Error:

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

Now looking at my code in at the actual class "VoucherResponse" i have,

public class VoucherResponse : AResponse
{
    public Voucher Voucher { get; set; }
}

And the Voucher object looks like this

public class Voucher
{
    public string PIN { get; set; }
    public string Serial { get; set; }
    public string Batch { get; set; }
}

Now in one of my web methods I return the VoucherResponse and I am assuming that this error occurs when it is reflected through and checked.

Has anyone had a similar problem with this before, or can anyone give me some advice on this?

Thanks

like image 545
Brendon Randall Avatar asked Dec 09 '10 11:12

Brendon Randall


1 Answers

I found another case that raises the error! Here's my code:

[WebMethod]
public CheckUpdateResponse CheckUpdate()
{
...
}

Ok, let me explain: CheckUpdateResponse is a structure I defined in my code, CheckUpdate() is a method. So, in the WSDL .NET add automatically a Response suffix to the method name CheckUpdate.

Et voilà: it finds a duplicate element and gives the error "Change the method's message name using WebMethodAttribute..."

Solution? I renamed the returned type from CheckUpdateResponse to CheckUpdateResult and now everything works fine!

I hope this will help someone! I lost a lot of time on this...

like image 61
Seraphim's Avatar answered Sep 29 '22 03:09

Seraphim's