能贴出你客户端赋值代码吗?注意:
  private A a= new A(); 
AA类型为subA,
如果给a的AA赋值,只能赋subA 类型的
也就是这样:
private subA  b= new subA();
b.B = "B";
然后是
a.AA = b;你说的问题我写代码测试过了,所以我认为你错就错在赋值的时候了吧。
是不是给AA赋的不是subA类型的了!

解决方案 »

  1.   


    测试代码:
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;namespace WebA
    {
        public class WebB
        {
            private string strB;        public string StrB
            {
                get { return strB; }
                set { strB = value; }
            }        private string strValueB;        public string StrValueB
            {
                get { return strValueB; }
                set { strValueB = value; }
            }
        }
    }
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;namespace WebA
    {
        public class WebA
        {
            private WebB _WebB;        public WebB WebB
            {
                get { return _WebB; }
                set { _WebB = value; }
            }
        }
    }
    using System;
    using System.Collections;
    using System.ComponentModel;
    using System.Data;
    using System.Linq;
    using System.Web;
    using System.Web.Services;
    using System.Web.Services.Protocols;
    using System.Xml.Linq;namespace WebServiceTest
    {
        /// <summary>
        /// Service1 の概要の説明です
        /// </summary>
        [WebService(Namespace = "http://tempuri.org/")]
        [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
        [ToolboxItem(false)]
        // この Web サービスを、スクリプトから ASP.NET AJAX を使用して呼び出せるようにするには、次の行のコメントを解除します。
        // [System.Web.Script.Services.ScriptService]
        public class Service1 : System.Web.Services.WebService
        {        [WebMethod]
            public string HelloWorld()
            {
                return "Hello World";
            }        [WebMethod]
            public WebA.WebA GetValue()
            {
                WebA.WebA webA = new WebA.WebA();
                WebA.WebB webB = new WebA.WebB();
                webB.StrB = "StrB";
                webB.StrValueB = "StrValueB";
                webA.WebB = webB;            return webA;
            }
        }
    }
    客户端:        private void btnTest_Click(object sender, EventArgs e)
            {
                Service1 service = new Service1();
                WebA webA = new WebA();
                webA.WebB = new WebB();            webA = service.GetValue();
            }
      

  2.   

    客户端:privatevoid btnTest_Click(object sender, EventArgs e)
            {
                Service1 service=new Service1();
                WebA webA=new WebA();
                webA.WebB=new WebB();            webA= service.GetValue();
            }
    这个改为:
            private void btnTest_Click(object sender, EventArgs e)
            {
                Service1 service = new Service1();
                WebA webA = new WebA();
                webA = service.GetValue();
            }