0
   [WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.ComponentModel.ToolboxItem(false)]
// To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line. 
// [System.Web.Script.Services.ScriptService]
public class Service1 : System.Web.Services.WebService
{

    [WebMethod]
    public LoginResponse SignUp(string email, string password)
    {
        LoginResponse s = new LoginResponse();
        //s.Code = "123434";
        //s.Message = "Signup succeed";
        //s.UserId = "";
        return s;
    }

    [WebMethod]
    public SendCodeResponse SendCode(string userId, string barCode)
    {
        SendCodeResponse scr = new SendCodeResponse();
        scr.code = "";
        return scr;
    }



[Serializable]
    public class LoginResponse
    {
        string code;
        string message;
        string userId;

        [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(string), ElementName = "UserId")]
        public string UserId
        {
            get { return userId; }
            set { userId = value; }
        }
    }


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

このWebサービスを実行すると、「/」アプリケーションでサーバーエラーが発生します。

名前空間'http://tempuri.org/'のXML要素'SendCodeResponse'は、メソッドとタイプを参照します。WebMethodAttributeを使用してメソッドのメッセージ名を変更するか、XmlRootAttributeを使用してタイプのルート要素を変更します。

説明:現在のWebリクエストの実行中に未処理の例外が発生しました。エラーとエラーがコードのどこで発生したかについての詳細は、スタックトレースを確認してください。

例外の詳細:System.InvalidOperationException:名前空間'http://tempuri.org/'のXML要素'SendCodeResponse'は、メソッドとタイプを参照します。WebMethodAttributeを使用してメソッドのメッセージ名を変更するか、XmlRootAttributeを使用してタイプのルート要素を変更します。

私を助けてください。

4

1 に答える 1

5

次の2つの部品を交換してください。

パート1:

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

パート2:

[WebMethod]
public SendCodeResponse SendCode(string userId, string barCode)
{
    SendCodeResponse scr = new SendCodeResponse();
    scr.code = "";
    return scr;
}

と:

新しいパート1:

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

新しいパート2:

[WebMethod]
public SendCodeResult SendCode(string userId, string barCode)
{
    SendCodeResult scr = new SendCodeResult();
    scr.code = "";
    return scr;
}

WebMethodはSendCodeと呼ばれるため、タイプSendCodeResponseが自動的に作成されるため、その名前でクラスを作成することはできません。

于 2012-11-07T15:40:21.583 に答える