I have following classes , DBConn for database connection , UserBL class for handle external user functionality , SpeakerVO class for handle the entity properties, SpeakerBL class for handle the business layer methods, ICustomerService for service layer interface, CustServiceManager class for handle the service layer methods
the issue is when you call the service layer method passing User class appropriately , but still CustServiceManager class, ViewAll method the _user parameter becomes null
client calling code in windows application is below
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
UserBL _user = new UserBL();
string ConStrng = ConfigurationSettings.AppSettings["ConnectionString1"];
_user.SetConnection(ConStrng);
SpeakerReference.CustomerServiceClient x = new SpeakerReference.CustomerServiceClient();
x.ViewAll(_user);
}
}
namespace CodeCamper.DataLayer
{
[DataContract]
public class DBConn
{
private string mstr_username;
private string mstr_password;
private string mstr_server;
private string mstr_database;
private string mstr_connectionString;
private IDbConnection mcon_thisConnection;
[DataMember]
public IDbConnection MyConnection
{
get { return mcon_thisConnection; }
}
public DBConn(string connectionstr)
{
mcon_thisConnection = new SqlConnection(connectionstr);
}
}
}
namespace CodeCamper.BusinessLayer
{
[DataContract]
public class UserBL
{
private DBConn _DB;
//[DataMember]
public DBConn db
{
get { return _DB; }
set { _DB = value; }
}
public void SetConnection(string connectionstr)
{
_DB = new DBConn(connectionstr);
}
}
}
namespace CodeCamper.EntityLayer.Transaction
{
[DataContract]
public class SpeakerVO
{
private string _SpeakerID;
private string _SpeakerName;
private string _SpeakerSurname;
private string _Email;
private string _Twitter;
private string _Blog;
private string _Bio; //list like entry
private string _ImagePath;
[DataMember]
public string SpeakerID
{
get { return _SpeakerID; }
set { _SpeakerID = value; }
}
[DataMember]
public string SpeakerName
{
get { return _SpeakerName; }
set { _SpeakerName = value; }
}
[DataMember]
public string SpeakerSurname
{
get { return _SpeakerSurname; }
set { _SpeakerSurname = value; }
}
[DataMember]
public string Email
{
get { return _Email; }
set { _Email = value; }
}
[DataMember]
public string Twitter
{
get { return _Twitter; }
set { _Twitter = value; }
}
[DataMember]
public string Blog
{
get { return _Blog; }
set { _Blog = value; }
}
[DataMember]
public string Bio
{
get { return _Bio; }
set { _Bio = value; }
}
[DataMember]
public string ImagePath
{
get { return _ImagePath; }
set { _ImagePath = value; }
}
}
}
namespace CodeCamper.BusinessLayer.Transaction
{
[ServiceContract]
public class SpeakerBL : SpeakerVO
{
private UserBL _user;
#region -Constructor-
public SpeakerBL(UserBL user)
{
//ID = null;
//Code = string.Empty;
//Name = string.Empty;
_user = user;
}
#endregion
#region -Methods-
[OperationContract]
public static List<SpeakerVO> ViewAll(UserBL _user)
{
List<SpeakerVO> _tmpresult = null;
try
{
SpeakerDL ContainerTable = new SpeakerDL(_user.db, null);
_tmpresult = ContainerTable.ViewAll();
}
catch (Exception er)
{
throw er;
}
return _tmpresult;
}
#endregion
}
}
namespace CodeCamper.ServiceLayer
{
[ServiceContract]
public interface ICustomerService
{
[OperationContract]
List<SpeakerVO> ViewAll(UserBL _user);
}
}
namespace CodeCamper.ServiceLayer
{
public class CustServiceManager : ICustomerService
{
public List<SpeakerVO> ViewAll(UserBL _user)
{
List<SpeakerVO> _tmpresult = null;
try
{
_tmpresult = SpeakerBL.ViewAll(_user);
}
catch (Exception ex)
{
throw ex;
}
return _tmpresult;
}
}
}
the client config file is below
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.1"/>
</startup>
<appSettings>
<add key="ConnectionString1" value="Data Source=C008;Initial Catalog=sample;Persist Security Info=True;User ID=sa;password=ssa@123"/>
</appSettings>
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="BasicHttpBinding_ICustomerService" />
</basicHttpBinding>
</bindings>
<client>
<endpoint address="http://localhost:8733/Design_Time_Addresses/CodeCamper.ServiceLayer/CustomerService/"
binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_ICustomerService"
contract="SpeakerReference.ICustomerService" name="BasicHttpBinding_ICustomerService" />
</client>
</system.serviceModel>
</configuration>
the service layer config file is below
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<appSettings>
<add key="aspnet:UseTaskFriendlySynchronizationContext" value="true"/>
</appSettings>
<system.web>
<compilation debug="true"/>
</system.web>
<!-- When deploying the service library project, the content of the config file must be added to the host's
app.config file. System.Configuration does not support config files for libraries. -->
<system.serviceModel>
<services>
<service name="CodeCamper.ServiceLayer.CustServiceManager">
<endpoint address="" binding="basicHttpBinding" contract="CodeCamper.ServiceLayer.ICustomerService">
<identity>
<dns value="localhost" />
</identity>
</endpoint>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
<host>
<baseAddresses>
<add baseAddress="http://localhost:8733/Design_Time_Addresses/CodeCamper.ServiceLayer/CustomerService/" />
</baseAddresses>
</host>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior>
<!-- To avoid disclosing metadata information,
set the values below to false before deployment -->
<serviceMetadata httpGetEnabled="True" httpsGetEnabled="True"/>
<!-- To receive exception details in faults for debugging purposes,
set the value below to true. Set to false before deployment
to avoid disclosing exception information -->
<serviceDebug includeExceptionDetailInFaults="False"/>
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.1"/></startup></configuration>