Tuesday, July 2, 2013

No connection could be made because the target machine actively refused it error in WAS hosted WCF service

 

Recently I have created wcf service which is on NetTCPBinding and hosted in WAS.But when I try to create proxy using WCFtestClient its always failed prompting this error. Sad smile

The reason for this is the host sent a reset signal, instead of an ack when the client tried to connect. It is therefore not a problem in the code. Either there is a firewall blocking the connection or the process that is hosting the service is not listening on that port.

  • There fore we need to marks service port  as allowed port in the server firewall by defining new rule.
  • Need to running NetTcpPort Sharing windows service and Net.Tcp  Distner adapter windows service.

image

After doing above two steps its works Smile Smile Smile

Thursday, March 14, 2013

Doesn’t show windows authentication in IIS 7

Recently when I try to deploy my web application to newly setup windows server, in the IIS it doesn’t listed the windows authentication option  under authentication

image

In order to have listed windows authentication you need to install it by going to the Server Manager and checking Windows Authentication Check box

Server Manager—>web Service--->Add Role Service

image

Note : - In this machine already installed the Windows authentication .other wise check box will be enabled.

Monday, March 11, 2013

404.2 The page you are requesting cannot be served because of the ISAPI and CGI Restriction list settings on the Web server

recently I got this error when I deploy my asp .net application to the IIS.Reason for is that by default iis 7 didn’t allow ISAPI and CGI.There fore you need to allow those properties manually by using actions pane

 

image

Saturday, September 29, 2012

login failed for user ‘rob’ reason the account has expired

 

image

Promoting this error message my application has stopped working.The reason for that is expiration of the user which i have use to connect to sql server.later on i have investigate the user account in sqlserver and identified the root cause for that.

when i was creating the user i have checked the Enforce Password Expiration Check

Untitled

Finally i uncheck the check and changed the password again.now its work fine

Friday, August 10, 2012

In C#, how to check if a TCP port is available?

When hosting wcf service which is use net tcp binding and without port sharing in a windows service , we should make sure the availability of our wcf port number. Other wise service doesn't start.

There fore as a best practice its is better to have code which will check the availability of the port when starting the service.This code should included to the service startup event. 

   1: protected override void OnStart(string[] args)
   2:        {
   3:            try
   4:            {
   5:                if (serviceHost != null)
   6:                {
   7:                    serviceHost.Close();
   8:                }
   9:  
  10:                PortChecker pc = new PortChecker();
  11:  
  12:                if (pc.IsPortAvailable())
  13:                {
  14:                    serviceHost = new ServiceHost(typeof(M3ISPlusService));
  15:                    serviceHost.Open();
  16:                }
  17:            }


ANd this is the port checker class



   1: public bool IsPortAvailable()
   2:         {
   3:             bool isAvailable = false;
   4:             TcpListener tcpListner = new TcpListener(GetServerIp(), GetPort());
   5:             Logger logger = Logger.GetLogger();
   6:  
   7:             try
   8:             {
   9:                 tcpListner.Start();
  10:                 isAvailable = true;
  11:             }
  12:             catch (Exception ex)
  13:             {
  14:                 logger.Log(ex.Message);
  15:             }
  16:  
  17:             finally
  18:             {
  19:                 try
  20:                 {
  21:                     tcpListner.Stop();
  22:                     tcpListner = null;
  23:                 }
  24:                 catch (Exception)
  25:                 {
  26:                     tcpListner = null;
  27:                 }
  28:             }
  29:  
  30:             return isAvailable;
  31:         }

To get port in code please refer my previous post :- Read End point address programmatically


Happy Coding :)

Friday, August 3, 2012

Programmatically reading endpoint address from web.config file?

 

There are some instances where we have to read wcf endpoint url from the code.As following you can accomplish that task.

once we add a service to the code it will get added to web.config under <system.serviceModel> section.

so we can access web config like this.

ServicesSection servicesSection = (ServicesSection)ConfigurationManager.GetSection(BASE_ADDRESS_PATH);

var item = servicesSection.Services[0].Host.BaseAddresses[0].BaseAddress;
Uri baseAddress = new Uri(item);

Friday, June 29, 2012

Linq to data reader

using linq we can easily extract the data reader values without writing more coding.

example for populating anonymous object from datareader

using (SqlDataReader dataReader = command.ExecuteReader())
{
var annonymousObject = from IDataRecord record in dataReader
select new
{
Code = (string)record["Code"],
Description = (string)record["Description"]
};
}
example for populating custom object from datareader
using (SqlDataReader dataReader = command.ExecuteReader())
{
DataRecord dataRecord= (from IDataRecord record in dataReader
select new DataRecord
{
Code = (string) record["Code"],
Description = (string)record["Description"]
}).ToArray();
}