.NET Framework Bookmark and Share   
 index > .NET Framework Networking and Communication > No connection could be made because the target machine actively refused it
 

No connection could be made because the target machine actively refused it

Dear Sir,
I know its very common problem which has been asked by many people but i did not get any of the persons way of immplementing Remoting as i did so please go through with my steps of my project and provide me solution...
The steps which i used in my program ....
Server Side Code...
my app.config code

<?

xml version="1.0" encoding="utf-8" ?>

<

configuration>

<

connectionStrings>

<

add name="VitalDataBaseCon" connectionString ="initial Catalog=pubs ;uid=sa;pwd=success; server=VITAL-17\\VITAL17;integrated security=true"></add>

</

connectionStrings>

<

appSettings>

<

add key ="serverIp" value="192.168.1.17"/>

<

add key ="ServerPort" value="8080"/>

</

appSettings>

<

system.runtime.remoting>

<

customError Mode="on"/>

<

application>

<

service>

<

wellknown mode="SingleCall" type="Vital.DotNet.Server.LogIn,Server" objectUri="LogIn" />

</

service>

<

channels>

<

channel ref="tcp" secure="true" port="8080" impersonate="true" protectionLevel="EncryptAndSign"/>

</

channels>

</

application>

</

system.runtime.remoting>

</

configuration>

Server.cs

using

System;

using

System.Collections.Generic;

using

System.Text;

using

System.Data;

using

System.Data.SqlClient;

using

System.Configuration;

using

System.Runtime.Remoting.Lifetime;

using

System.Runtime.Remoting.Channels;

using

System.Runtime.Remoting.Channels.Tcp;

namespace

Vital.DotNet.Server

{

class LogIn:MarshalByRefObject,Vital.DotNet.Server.IvitalServerInterfaces

{

SqlDataAdapter adap;

SqlCommand cmd;

SqlConnection con;

public DataSet retriveData(string authorFirstName,string authorLastName,out bool isSuccess)

{

con =

new SqlConnection("initial Catalog=pubs ;uid=sa;pwd=success; server=VITAL-17\\VITAL17;integrated security=true");

con.Open();

SqlCommand cmd = new SqlCommand("Demoinput", con);

cmd.CommandType=

CommandType.StoredProcedure;

cmd.Parameters.Add(

new SqlParameter("@au_fname",authorFirstName));

cmd.Parameters.Add(

new SqlParameter("@au_lname",authorLastName));

DataSet ds = new DataSet();

SqlDataAdapter adap = new SqlDataAdapter(cmd);

adap.Fill(ds);

if (ds.Tables[0].Rows.Count == 0)

{

isSuccess =

false;

}

else

{

isSuccess =

true;

}

return ds;

}

static void Main(string[] args)

{

Console.ReadLine();

}

}

}

My procedure in pubs data base

create procedure [dbo].[Demoinput]( @au_lname varchar(50),@au_fname varchar(50))
as
begin
select * from authors
where au_lname=@au_lname
end

Interface on server side which has been added on client side as a DLL.

namespace

Vital.DotNet.Server

{

public interface IvitalServerInterfaces

{

DataSet retriveData(string authorFirstName, string authorLastName, out bool isSuccess);

}

}



CLIENT Side Code

client side app.config file

<?

xml version="1.0" encoding="utf-8" ?>

<

configuration>

<

appSettings>

<

add key ="serverIp" value="192.168.1.7"/>

<

add key ="ServerPort" value="9002"/>

</

appSettings>

<

system.runtime.remoting>

<

application>

<

channels>

<

channel ref="tcp" secure="true" tokenImpersonationLevel="Identification" username="" password=""/>

</

channels>

</

application>

</

system.runtime.remoting>

</

configuration>

client.cs

using

System;

using

System.Collections.Generic;

using

System.ComponentModel;

using

System.Data;

using

System.Drawing;

using

System.Text;

using

System.Windows.Forms;

using

Vital.DotNet.Server;

using

System.Configuration;

using

System.Runtime.Remoting.Lifetime;

using

System.Runtime.Remoting.Channels;

using

System.Runtime.Remoting.Channels.Tcp;

namespace

Vital.DotNet.client

{

public partial class Form1 : Form

{

Vital.DotNet.Server.

IvitalServerInterfaces ObjServerSide = null;

bool isSuccess = false;

public Form1()

{

InitializeComponent();

}

private void btnShow_Click(object sender, EventArgs e)

{

try

{

ObjServerSide = (

IvitalServerInterfaces)Activator.GetObject(typeof(IvitalServerInterfaces), @"tcp://192.168.1.17" + ":8080" + "/pop");

ObjServerSide.retriveData(txtAuthorFirstName.Text, txtAuthorLastName.Text,

out isSuccess);

}

catch (System.Runtime.Remoting.RemotingException ex)

{

MessageBox.Show(ex.Message);

}

}

}

}

please help me out from this problem ,i checked this codeon remote computer(On LAN) as well as same computer but it doesnot work....

Thanks and regards
AMRITA VISHNOI

















































Amrita Vishnoi
I am not good with remoting, but the error suggests that the server endpoint is not listening. Looking at your code, I cannot see where you are registering the remoting endpoint?
feroze
--
My blog
Feroze Daud
Thanks For ur keen reply. I am registering in app.config file on both server and client side as a chanels,ports and server ip.

Client side-App.config


<

configuration><connectionStrings>

<

add name="DbCon" connectionString ="initial Catalog=pubs ;uid=sa;pwd=success; server=VITAL-17\\VITAL17;integrated security=true"></add> </connectionStrings>

<

appSettings>

<

add key ="serverIp" value="192.168.1.7"/>
<
add key ="ServerPort" value="9002"/>
</
appSettings>
<
system.runtime.remoting>
<
application>
<
channels>
<
channel ref="tcp" secure="true" tokenImpersonationLevel="Identification" username="" password=""/>
</
channels>
</
application>
</
system.runtime.remoting>
</
configuration>

Server Side App.config

<

Amrita Vishnoi
IpAddress and Port in server and client must be same. Looking at your code I think ipaddress and port are different in client and server.

Also check whether firewall is not blocking the port.
Gaurav Khanna
Khanna Gaurav

Get a log of both client and server, by following the instructions here.

http://ferozedaud.blogspot.com/2009/08/tracing-with-systemnet.html
feroze
--
My blog
Feroze Daud

You can use google to search for other answers

Custom Search

More Threads

• SmtpClient sending but not receiving
• Selecting NIC card in dual home/NIC machine programatically
• BeginAccept problem
• Exception - "The HTTP request was forbidden with client authentication scheme 'Anonymous'."
• Reboot a router using HTTP Web requests
• How To: Display Rating information fetched from remote database
• SmartNav.js displayed in HttpWatch Basic as Text/Html instead of Application/x-javasacript
• Group Policy windows 2000
• UDP Speed problem ... with small packets
• get ip address of remote pc