Sunday, August 28, 2011

Working hard....

I could not write blog since last 4 months because in new organization i am not getting time at all :-(. We all (i and team) working too hard to acheive project milestones with timefrawork. In project execution ,too many unexpected things croped up but management and client did not change target date. I had to fight with my managers (yes not single manager ...here i have to report multiple managers)with respect to timeline and unexpected items...but managers are manager -:)...

Sunday, April 17, 2011

Joined New Organization

After working almost 5 years in small size software company in Pune, i decided to work with one of the biggest IT company in India. I joined new company on 11th April 2011. Probably i am going to work on Sharepooint 2010 and Commerce Server 2009 ( CS 2009). I have experience of Commerce Server 2007 already and this can be helpful for me to implement CS 2009.

Sharepoint is completely new for me though it should not be tough for me to learn it.

I would definitly try to write my expereince on Sharepoint and CS 2009 on my blog (At least twice a week).

Tuesday, April 05, 2011

Backup Script

If you want to create backup script of data that you want to take backup on daily basis using some batch process and windows scheduler then below is the right option to go with. Copy below stuff in notepad and save it as .bat file and add to scheduler.

@ECHO OFF
CLS
SET DD=%DATE:~7,2%
SET MM=%DATE:~4,2%
SET YYYY=%DATE:~10,4%
SET HH=%TIME:~0,2%
SET MN=%TIME:~3,2%
SET SS=%TIME:~6,2%
SET FOLDER="%YYYY%-%MM%-%DD%-%HH%-%MN%-%SS%"
::START COPY WSSERVICE
xcopy "\\sharedlocation\website\wsService" d:\buildbackup\%FOLDER%\wsService /i /S /E /H /R /Y
::END COPY WSSERVICE

Wednesday, March 23, 2011

Silverlight - WCF Exception Handling

We cannot handle WCF exception handling(using Fault Exception) in Silverlight in routine way. I mean when you pass fault exception to client silverlight applcation it does not get exception details through fault contract. For this we have to change HttpStatusCode from 500 to 200[OK].

Follow below stuff to get it done

<DataContract()> _
Public Class MYFaultException

Private _reason As String
Private _code As String

<DataMember()> _
Public Property Reason() As String
Get
Return _reason
End Get
Set(ByVal value As String)
_reason = value
End Set
End Property
<DataMember()> _
Public Property Code() As String
Get
Return _code
End Get
Set(ByVal value As String)
_code = value
End Set
End Property

End Class


Public Class SilverlightFaultBehavior
Inherits BehaviorExtensionElement
Implements IEndpointBehavior


'Public Sub ApplyDispatchBehavior(ByVal endpoint As ServiceEndpoint, ByVal endpointDispatcher As EndpointDispatcher)
' Dim inspector As New SilverlightFaultMessageInspector()
' endpointDispatcher.DispatchRuntime.MessageInspectors.Add(inspector)
'End Sub

Public Class SilverlightFaultMessageInspector
Implements IDispatchMessageInspector


Public Sub BeforeSendReply(ByRef reply As Message, ByVal correlationState As Object) Implements System.ServiceModel.Dispatcher.IDispatchMessageInspector.BeforeSendReply
If reply.IsFault Then
Dim [property] As New HttpResponseMessageProperty()

' Here the response code is changed to 200.
[property].StatusCode = System.Net.HttpStatusCode.OK


reply.Properties(HttpResponseMessageProperty.Name) = [property]
End If
End Sub




Public Function AfterReceiveRequest(ByRef request As System.ServiceModel.Channels.Message, ByVal channel As System.ServiceModel.IClientChannel, ByVal instanceContext As System.ServiceModel.InstanceContext) As Object Implements System.ServiceModel.Dispatcher.IDispatchMessageInspector.AfterReceiveRequest
Return Nothing
End Function


End Class

' The following methods are stubs and not relevant.

Public Overrides ReadOnly Property BehaviorType() As System.Type
Get
Return GetType(SilverlightFaultBehavior)
End Get
End Property

Protected Overrides Function CreateBehavior() As Object
Return New SilverlightFaultBehavior()
End Function

Public Sub AddBindingParameters(ByVal endpoint As System.ServiceModel.Description.ServiceEndpoint, ByVal bindingParameters As System.ServiceModel.Channels.BindingParameterCollection) Implements System.ServiceModel.Description.IEndpointBehavior.AddBindingParameters

End Sub

Public Sub ApplyClientBehavior(ByVal endpoint As System.ServiceModel.Description.ServiceEndpoint, ByVal clientRuntime As System.ServiceModel.Dispatcher.ClientRuntime) Implements System.ServiceModel.Description.IEndpointBehavior.ApplyClientBehavior

End Sub

Public Sub ApplyDispatchBehavior(ByVal endpoint As System.ServiceModel.Description.ServiceEndpoint, ByVal endpointDispatcher As System.ServiceModel.Dispatcher.EndpointDispatcher) Implements System.ServiceModel.Description.IEndpointBehavior.ApplyDispatchBehavior
Dim inspector As New SilverlightFaultMessageInspector()
endpointDispatcher.DispatchRuntime.MessageInspectors.Add(inspector)
End Sub

Public Sub Validate(ByVal endpoint As System.ServiceModel.Description.ServiceEndpoint) Implements System.ServiceModel.Description.IEndpointBehavior.Validate

End Sub
End Class

-----------------------------START SERVICE CONTRACT---------------------------

<ServiceContract()> _
Public Interface IService1

<OperationContract()> _
<FaultContract(GetType(MYFaultException))> _
Function GetData(ByVal value As Integer) As String

<OperationContract()> _
Function GetDataUsingDataContract(ByVal composite As CompositeType) As CompositeType

' TODO: Add your service operations here

End Interface

-----------------------------END SERVICE CONTRACT---------------------------

-----------------------------WEB CONFIG SETTINGS ---------------------------
<system.serviceModel>
<extensions>
<behaviorExtensions>
<add name="silverlightFaults"
type="WcfService1.SilverlightFaultBehavior, WcfService1, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null"/>
</behaviorExtensions>
</extensions>
<behaviors>
<endpointBehaviors>
<behavior name="SilverlightFaultBehavior">
<silverlightFaults/>
</behavior>
</endpointBehaviors>
<serviceBehaviors>

<behavior name="SilverlightFaultBehavior">

<serviceDebug includeExceptionDetailInFaults="true"/>

<serviceMetadata httpGetEnabled="true"/>

</behavior>
</serviceBehaviors>
</behaviors>
<services>
<service name="WcfService1.Service1" behaviorConfiguration="SilverlightFaultBehavior">
<endpoint address=""
binding="basicHttpBinding"
contract="WcfService1.IService1"
behaviorConfiguration="SilverlightFaultBehavior" />
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
</service>
</services>
</system.serviceModel>

-----------------------------END WEB CONFIG SETTINGS ---------------------------

-----------------------------IN SILVERLIGHT APP ---------------------------

Private Sub serProxy_GetData(ByVal sender As Object, ByVal e As ServiceReference1.GetDataCompletedEventArgs)
If e.Error Is Nothing Then
txtErrorMessage.Text = e.Result
Else
txtErrorMessage.Text = e.Error.Message
End If
End Sub
-----------------------------END IN SILVERLIGHT APP ---------------------------

Wednesday, March 02, 2011

Enable Tracing for Console Application

For enabling Tracing you need to put following settings in app.config.

<configuration>
<system.diagnostics>
<trace autoflush="false" indentsize="4">
<listeners>
<add name="myListener" type="System.Diagnostics.EventLogTraceListener" initializeData="Solstice" />
<remove name="Default" />
</listeners>
</trace>
</system.diagnostics>
</configuration>

NOTE - "ApplicationName" should be available in registry. We can use following lines to create Registry for "ApplicationName" (copy below text in notepad and save it with extension .reg and run it)

Windows Registry Editor Version 5.00

[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Eventlog\Application\ApplicationName]
"EventMessageFile"=hex(2):63,00,3a,00,5c,00,57,00,49,00,4e,00,44,00,4f,00,57,\
00,53,00,5c,00,4d,00,69,00,63,00,72,00,6f,00,73,00,6f,00,66,00,74,00,2e,00,\
4e,00,45,00,54,00,5c,00,46,00,72,00,61,00,6d,00,65,00,77,00,6f,00,72,00,6b,\
00,5c,00,76,00,32,00,2e,00,30,00,2e,00,35,00,30,00,37,00,32,00,37,00,5c,00,\
45,00,76,00,65,00,6e,00,74,00,4c,00,6f,00,67,00,4d,00,65,00,73,00,73,00,61,\
00,67,00,65,00,73,00,2e,00,64,00,6c,00,6c,00,00,00


Codebehind ---- You can write Trace info as below

System.Diagnostics.Trace.TraceInformation("Writing Trace Information");