none
i cant figure out why return null value when i use the channelfactory?plz help RRS feed

  • Question

  • hi all,i create the proxy by channelfactory,but the return value is null,i cant figure out why,on the other hand,i used the proxy generate by "add service reference...",it's become normal. i have debuged and tracked code of service side,it  have  about 3000 records before return. 

    PLZ help,

    my client code:

        EndpointAddress objAddress = new EndpointAddress(wcfaddr + "/Service1.svc");

                  WSHttpBinding wshttpbind = new WSHttpBinding();
               
                          
                  ChannelFactory<IService1> factory = new ChannelFactory<IService1>(wshttpbind, objAddress);
                 
                
                  try
                  {
                      IService1 m_proxy = factory.CreateChannel();
                       MyProdfulllist prodfullist=new MyProdfulllist();

                        prodfullist = m_proxy.GetMyProdfull();
                          
                          int recordcount = prodfullist.Count;
                          int i = 0;
                          MyProdfullStruct[] prodfullstruct = new MyProdfullStruct[recordcount];
                          foreach (MyProdfullDatacontract prodfulldc in prodfullist)
                          {
                              prodfullstruct[i].prodno = prodfulldc.yprodno;
                              prodfullstruct[i].prodname = prodfulldc.prodname;
                              prodfullstruct[i].prodsize = prodfulldc.prodsize;
                            
                        
                              i++;
                          }

                         
                          ICommunicationObject channel = m_proxy as ICommunicationObject;
                          Debug.Assert(channel != null);
                          channel.Close();
                          factory.Close();
                          return prodfullstruct;

                  }
                  catch
                  {
                      factory.Abort();
                      throw;
                  }
    ken thanks you,plz help

    best regards





    • Edited by ken yup Monday, March 11, 2013 2:20 PM
    Monday, March 11, 2013 10:30 AM

Answers

  • hello, i still have no idea why  this problem occur,but i have another way to get the data,so far,it works well  through the method of following link

    http://stackoverflow.com/questions/6283037/set-maxitemsinobjectgraph-in-client-config

    i use the auto-generate proxy and add the code of below

                  foreach (var operationDescription in m_proxy.Endpoint.Contract.Operations)
                  {
                      DataContractSerializerOperationBehavior dcsob =
                          operationDescription.Behaviors.Find<DataContractSerializerOperationBehavior>();
                      if (dcsob != null)
                      {
                          dcsob.MaxItemsInObjectGraph = 65536000;
                      }
                  }

    but i really want to know why it return null value by channelfactory .


    • Edited by ken yup Tuesday, March 12, 2013 1:38 PM
    • Marked as answer by ken yup Wednesday, March 13, 2013 5:20 AM
    Tuesday, March 12, 2013 1:37 PM

All replies

  • this is the sevice side code

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Runtime.Serialization;
    using System.ServiceModel;
    using System.Text;

    namespace mybh
    {
       
        [ServiceContract]
        public interface IService1
        {

            [OperationContract]
            [FaultContract(typeof(ProdfullFault))]
            MyProdfulllist GetMyProdfull();

        }

        [DataContract]
        public class MyProdfullDatacontract
        {
            [DataMember]
            public string Myprodno
            {
                get;
                set;
            }

            [DataMember]
            public string prodname
            {
                get;
                set;
            }

            [DataMember]
            public string prodsize
            {
                get;
                set;
            }
           

        }

        [CollectionDataContract]
        public class MyProdfulllist : List<MyProdfullDatacontract>
        {

        }

        public MyProdfulllist GetMyProdfull()
            {

     

                string connstring1 = @"server =192.168.0.2;database=db1;uid=sa;pwd=''";
                string sqlquery1 = @"  SELECT prod_no,prod_name,prod_size FROM product ";
                SqlConnection conn1 = null;
                SqlDataReader reader1 = null;
                MyProdfulllist prodfullist = new MyProdfulllist();

                int i = 0;

                try
                {
                    conn1 = new SqlConnection(connstring1);
                    conn1.Open();
                    SqlCommand cmd1 = new SqlCommand(sqlquery1, conn1);
                    reader1 = cmd1.ExecuteReader();

                    if (reader1.Read())
                    {
                        while (reader1.Read())
                        {
                            MyProdfullDatacontract prodfuldc = new MyProdfullDatacontract
                            {
                                prodno = reader1[0].ToString(),
                                prodname = reader1[1].ToString(),
                                prodsize = reader1[2].ToString(),
                             
                          
                            
                            };

                            prodfullist.Add(prodfuldc);
                            i++;

                        }
                    }
                }
                catch (Exception ex)
                {
                    ProdfullFault pff = new ProdfullFault();
                    pff.Operation = "exception occur when get prodfull list";
                    pff.ProblemType = ex.ToString();
                    string expmessag = ex.ToString();
                    if (expmessag.Length > 900)
                        expmessag = ex.ToString().Substring(0, 900);
                    logtheexp(ip, myusername, pff.Operation + expmessag);
                    throw new FaultException<ProdfullFault>(pff, expmessag);

                }
                finally
                {
                    if (reader1 != null)
                        reader1.Close();
                    if (conn1 != null)
                        conn1.Close();
                }

    }

    }




    • Edited by ken yup Monday, March 11, 2013 10:53 AM
    Monday, March 11, 2013 10:46 AM
  • hello, i still have no idea why  this problem occur,but i have another way to get the data,so far,it works well  through the method of following link

    http://stackoverflow.com/questions/6283037/set-maxitemsinobjectgraph-in-client-config

    i use the auto-generate proxy and add the code of below

                  foreach (var operationDescription in m_proxy.Endpoint.Contract.Operations)
                  {
                      DataContractSerializerOperationBehavior dcsob =
                          operationDescription.Behaviors.Find<DataContractSerializerOperationBehavior>();
                      if (dcsob != null)
                      {
                          dcsob.MaxItemsInObjectGraph = 65536000;
                      }
                  }

    but i really want to know why it return null value by channelfactory .


    • Edited by ken yup Tuesday, March 12, 2013 1:38 PM
    • Marked as answer by ken yup Wednesday, March 13, 2013 5:20 AM
    Tuesday, March 12, 2013 1:37 PM