0

我在我的 webMethod 中使用 C# webservice:

[WebMethod]
public SignUpResponse SignUp(string email, string password)
{
        SignUpResponse sr = new SignUpResponse();
        if (string.IsNullOrEmpty(email) || string.IsNullOrEmpty(password))
        {
            sr.ErrorCode = (int)ErrorCodes.RequestParametersUnavailable;
            return sr;
        }

        try
        {
            UserDAO uda = new UserDAO();

            if (uda.isEmailExist(email))
            {
                sr.ErrorCode = (int)ErrorCodes.UserAlreadyExist;
                return sr;
            }

            UserData udata = uda.SignUp(email, password, (int)UserType.MobileUser);

            sr.ErrorCode = (int)ErrorCodes.Successfull;
            sr.Code = udata.CODE;
            sr.Message = "SignUp Successfull";
            sr.UserId = udata.USER_ID;

            return sr;
        }
        catch
        {
            sr.ErrorCode = (int)ErrorCodes.UnexpectedError;
            return sr;
        }
    }

[Serializable]
[XmlRoot("SignUpResponseL")]
public class SignUpResponse
{
    string code;
    string message;
    int userId;
    int errorCode;

    [XmlElement(Type = typeof(string), ElementName = "Code")]
    public string Code
    {
        get { return code; }
        set { code = value; }
    }

    [XmlElement(Type = typeof(string), ElementName = "Message")]
    public string Message
    {
        get { return message; }
        set { message = value; }
    }

    [XmlElement(Type = typeof(int), ElementName = "UserId")]
    public int UserId
    {
        get { return userId; }
        set { userId = value; }
    }

    [XmlElement(Type = typeof(int), ElementName = "ErrorCode")]
    public int ErrorCode
    {
        get { return errorCode; }
        set { errorCode = value; }
    }
}

当我调用它时,它返回响应为:

<SignUpResponseL xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://tempuri.org/">
<Code>29054</Code>
<Message>SignUp Successfull</Message>
<UserId>5</UserId>
<ErrorCode>1</ErrorCode>
</SignUpResponseL>

但我想做到:

<SignUpResponseL>
 <Code>29054</Code>
 <Message>SignUp Successfull</Message>
 <UserId>5</UserId>
 <ErrorCode>1</ErrorCode>
</SignUpResponseL>

请让我知道该怎么做。提前致谢

4

1 回答 1

0

XmlNamespaceManager可用于移除命名空间。可移除命名空间的remove方法

http://msdn.microsoft.com/en-us/library/system.xml.xmlnamespacemanager.removenamespace.aspx

于 2012-10-07T09:33:08.423 回答