Tuesday, April 26, 2011

WCF Service debuging technique from client

While implementing any WCF service in any client application, you may find lots of issue, here i share some experience how you can get to know whats going wrong at service end!




You just need to turn on Tracing and Messging on WCF server





As a result you see the following set of tags has been added in your web config file.

< system.diagnostics >
< sources >
< source name="System.ServiceModel" switchValue="Warning, ActivityTracing"
propagateActivity="true" >
< listeners >
< add type="System.Diagnostics.DefaultTraceListener" name="Default" >
< filter type="" / >
< /add >
< add name="ServiceModelTraceListener" >
< filter type="" / >
< /add >
< /listeners >
< /source >
< source name="System.ServiceModel.MessageLogging" switchValue="Warning, ActivityTracing" >
< listeners >
< add type="System.Diagnostics.DefaultTraceListener" name="Default" >
< filter type="" / >
< /add >
< add name="ServiceModelMessageLoggingListener" >
< filter type="" / >
< /add >
< /listeners >
< /source >
< /sources >
< sharedListeners >
< add initializeData="F:\MyWCFFolder\Web_tracelog.svclog"
type="System.Diagnostics.XmlWriterTraceListener, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
name="ServiceModelTraceListener" traceOutputOptions="Timestamp" >
< filter type="" / >
< /add >
< add initializeData="F:\MyWCFFolder\Web_messages.svclog"
type="System.Diagnostics.XmlWriterTraceListener, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
name="ServiceModelMessageLoggingListener" traceOutputOptions="Timestamp" >
< filter type="" / >
< /add >
< /sharedListeners >
< /system.diagnostics >

Stop subsequent submit button clicks when a earlier request is being processed in ASP.NET

How we can stop the subsequent click when a earlier request is still been processed.

here is the javascript code you need to place above your update panel.
< script type="text/javascript" language="javascript" >
var requestManager = Sys.WebForms.PageRequestManager.getInstance();
requestManager.add_initializeRequest(StopPostbackOnSubsequentSubmitClicks);

function StopPostbackOnSubsequentSubmitClicks(sender, args) {
if (requestManager.get_isInAsyncPostBack() &
args.get_postBackElement().id == '<%=btnSubmit.ClientID %>')
{
args.set_cancel(true);
alert('Please wait, earlier request is still being processed');
}
}
< /script >

Now write your update panel code
< asp:UpdatePanel runat="server" ID="upnlLogin" UpdateMode="Conditional" >
< ContentTemplate >

// do whatever you need

< asp:Button ID="btnSubmit" runat="server" Text="Sign in" CssClass="button" OnClick="btnSubmit_Click" />

< /ContentTemplate>

< /asp:UpdatePanel>
< asp:UpdateProgress AssociatedUpdatePanelID="upnlLogin" runat="server" >
< ProgressTemplate>
< img src="../Images/spinner.gif" / >
< /ProgressTemplate >
< /asp:UpdateProgress >

// Now see the code behind implementation

protected void btnSubmit_Click(object sender, EventArgs e)
{

Thread.Sleep(1000);
}

Monday, April 25, 2011

Sql paging example, paging in sql 2000

Create PROCEDURE spPaggingExample
(
@ProductInfo varchar(100)=null,
@SearchBy varchar(50)=null,
@startRowIndex int,
@maximumRows int,
@totalRows int OUTPUT
)
AS

-- sample spPaggingExample '',null,1,10,0

DECLARE @first_id int, @startRow int

SET @startRowIndex = @startRowIndex * @maximumRows

IF @startRowIndex = 0 SET @startRowIndex = 1

SET ROWCOUNT @startRowIndex

SELECT @first_id = UniqueTableId FROM myProductTable where (Isnull(IsApproved,0)=1 and ProductName like '%'+@ProductInfo+'%' or ProductDescription like '%'+@ProductInfo+'%' ) ORDER BY UniqueTableId

--PRINT @first_id
SET ROWCOUNT @maximumRows
SELECT * FROM myProductTable WHERE Isnull(IsApproved,0)=1 and UniqueTableId >= @first_id and (ProductName like '%'+@ProductInfo+'%' or ProductDescription like '%'+@ProductInfo+'%' ) ORDER BY UniqueTableId

SET ROWCOUNT 0
-- GEt the total rows
SELECT @totalRows = COUNT(UniqueTableId) FROM myProductTable where (Isnull(IsApproved,0)=1 and ltrim(rtrim(ProductName)) like '%'+@ProductInfo+'%' or ProductDescription like '%'+@ProductInfo+'%' )

RETURN @totalRows

Sunday, April 3, 2011

NHibernate configuration ProxyFactoryFactory exception

This is how my configuration file look like.

< configSections >
< section name="hibernate-configuration"
type="NHibernate.Cfg.ConfigurationSectionHandler, NHibernate" / >
< /configSections >

< hibernate-configuration xmlns="urn:nhibernate-configuration-2.2" >
< session-factory name="EClinic" >
< property name="connection.provider" >NHibernate.Connection.DriverConnectionProvider< /property >
< property name="connection.driver_class" >NHibernate.Driver.SqlClientDriver< /property >
< property name="connection.connection_string" >Server=(arindam123);initial catalog=mydatabasename;userid=username;password=mypass;Integrated Security=SSPI; < /property >
< property name="dialect" >NHibernate.Dialect.MsSql2005Dialect< /property >
< property name="proxyfactory.factory_class" >NHibernate.ByteCode.Castle.ProxyFactoryFactory, NHibernate.ByteCode.Castle< /property >
< property name="show_sql" >true< /property >
< /session-factory >
< /hibernate-configuration >
< /configSections >


I am getting following error
The ProxyFactoryFactory was not configured.
Initialize 'proxyfactory.factory_class' property of the session-factory configuration section with one of the available NHibernate.ByteCode providers.
Example:
NHibernate.ByteCode.LinFu.ProxyFactoryFactory, NHibernate.ByteCode.LinFu
Example:
NHibernate.ByteCode.Castle.ProxyFactoryFactory, NHibernate.ByteCode.Castle
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: NHibernate.Bytecode.ProxyFactoryFactoryNotConfiguredException: The ProxyFactoryFactory was not configured.
Initialize 'proxyfactory.factory_class' property of the session-factory configuration section with one of the available NHibernate.ByteCode providers.
Example:
NHibernate.ByteCode.LinFu.ProxyFactoryFactory, NHibernate.ByteCode.LinFu
Example:
NHibernate.ByteCode.Castle.ProxyFactoryFactory, NHibernate.ByteCode.Castle

Source Error:


Line 20: log4net.Config.XmlConfigurator.Configure();
Line 21: Configuration cfg = new Configuration();
Line 22: m_sessionFactory = cfg.BuildSessionFactory();
Line 23:
Line 24: }

ETG Consultancy

Web Designing Development Analysis & Promotion
Asp.Net 2.0 SQL WWF WCF SEO Marketing Ajax JQuery NHibernate MVC