Problem with C # webservice, method and type reference

I ran into some problem, but not sure if this is a problem, but I would like some advice.

I developed C # webservice in vs2010, and when I debug the service, I get this error in my browser

The XML element "VoucherResponse" from the namespace "http://test.org/" refers to the method and type. Change the name of the method message using WebMethodAttribute or change the root element of the type using XmlRootAttribute.

Description: An unhandled exception occurred during the execution of the current web request. View the stack trace for more information about the error and its occurrence in the code.

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

Source Error:

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

Now, looking at my code in the actual "VoucherResponse" class, 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 VoucherResponse, and I assume that this error occurs when it is reflected and verified.

- , - ?

+5
3

-, SOAP , . , :

public class VoucherResponse
{
    [WebMethod(MessageName="TheVoucher")]
    public Voucher Voucher{get; set;}
}
+7

, ! :

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

, : CheckUpdateResponse - , , CheckUpdate() - . , WSDL .NET Response CheckUpdate.

Et voilà: " WebMethodAttribute..."

? CheckUpdateResponse CheckUpdateResult, !

, -! ...

+34

, ; , , -, WSDL\Schema.

, - 17 , , - , .Net , :

The XML element 'XYZ' from namespace 'ABC' references a method and a type. Change the method message name using WebMethodAttribute or change the type root element using the XmlRootAttribute.

Solution: I opened the Reference.cs file, deleted all the wappered returned types of the generated classes and saved only one, and then changed the name of my class to a common one, not related to the operation, it worked for me.

0
source

All Articles