WCF and Firewalls
Posted
by Amitd
on Stack Overflow
See other posts from Stack Overflow
or by Amitd
Published on 2010-05-21T11:27:05Z
Indexed on
2010/05/21
11:30 UTC
Read the original article
Hit count: 462
Hi guys,
As a part of learning WCF, I was trying to use a simple WCF client-server code .
http://weblogs.asp.net/ralfw/archive/2007/04/14/a-truely-simple-example-to-get-started-with-wcf.aspx
but I'm facing strange issues.I was trying out the following.
Client(My) IP address is : 192.168.2.5 (internal behind firewall) Server IP address is : 192.168.50.30 port : 9050 (internal behind firewall) Servers LIVE/External IP (on internet ) : 121.225.xx.xx (accessible from internet)
When I specify the above I.P address of server(192.168.50.30), the client connects successfully and can call servers methods.
Now suppose if I want to give my friend (outside network/on internet) the client with server's live I.P, i get an ENDPOINTNOTFOUND exceptions.
Surprisingly if I run the above client specifying LIVE IP(121.225.xx.xx) of server i also get the same exception.
I tried to debug the problem but haven't found anything.
Is it a problem with the company firewall not forwarding my request? or is it a problem with the server or client .
Is something needed to be added to the server/client to overcome the same problem? Or are there any settings on the firewall that need to be changed like port forwarding? (our network admin has configured the port to be accessible from the internet.) is it a authentication issue?
Code is available at .
http://www.ralfw.de/weblog/wcfsimple.txt
http://weblogs.asp.net/ralfw/archive/2007/04/14/a-truely-simple-example-to-get-started-with-wcf.aspx
i have just separated the client and server part in separate assemblies.rest is same.
using System;
using System.Collections.Generic;
using System.Text;
using System.ServiceModel;
namespace WCFSimple.Contract
{
[ServiceContract]
public interface IService
{
[OperationContract]
string Ping(string name);
}
}
namespace WCFSimple.Server
{
[ServiceBehavior(InstanceContextMode = InstanceContextMode.PerCall)]
class ServiceImplementation : WCFSimple.Contract.IService
{
#region IService Members
public string Ping(string name)
{
Console.WriteLine("SERVER - Processing Ping('{0}')", name);
return "Hello, " + name;
}
#endregion
}
public class Program
{
private static System.Threading.AutoResetEvent stopFlag = new System.Threading.AutoResetEvent(false);
public static void Main()
{
ServiceHost svh = new ServiceHost(typeof(ServiceImplementation));
svh.AddServiceEndpoint(
typeof(WCFSimple.Contract.IService),
new NetTcpBinding(),
"net.tcp://localhost:8000");
svh.Open();
Console.WriteLine("SERVER - Running...");
stopFlag.WaitOne();
Console.WriteLine("SERVER - Shutting down...");
svh.Close();
Console.WriteLine("SERVER - Shut down!");
}
public static void Stop()
{
stopFlag.Set();
}
}
}
namespace WCFSimple
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("WCF Simple Demo");
// start server
System.Threading.Thread thServer = new System.Threading.Thread(WCFSimple.Server.Program.Main);
thServer.IsBackground = true;
thServer.Start();
System.Threading.Thread.Sleep(1000); // wait for server to start up
// run client
ChannelFactory<WCFSimple.Contract.IService> scf;
scf = new ChannelFactory<WCFSimple.Contract.IService>(
new NetTcpBinding(),
"net.tcp://localhost:8000");
WCFSimple.Contract.IService s;
s = scf.CreateChannel();
while (true)
{
Console.Write("CLIENT - Name: ");
string name = Console.ReadLine();
if (name == "") break;
string response = s.Ping(name);
Console.WriteLine("CLIENT - Response from service: " + response);
}
(s as ICommunicationObject).Close();
// shutdown server
WCFSimple.Server.Program.Stop();
thServer.Join();
}
}
}
Any help?
© Stack Overflow or respective owner