I'm still learning, and I have a problem connecting to another connected computer in the same network to my simple WCF service using BasicHttpBinding.
A. Common.dll
[ServiceContract]
public interface ISampleService
{
[OperationContract]
System.DateTime GetServerTime();
}
B. Server.dll
public class SampleService : ISampleService
{
public DateTime GetServerTime()
{
return DateTime.Now;
}
}
C. Console host app
static void Main(string[] args)
{
string endPointAddress = "http://localhost:9942/ServiceTest";
Uri baseAddress = new Uri(endPointAddress);
var host = new ServiceHost(typeof(SampleService), baseAddress);
BasicHttpBinding httpBinding = new BasicHttpBinding(BasicHttpSecurityMode.None);
host.AddServiceEndpoint(typeof(ISampleService), httpBinding, "ISampleService");
ServiceMetadataBehavior smb = new ServiceMetadataBehavior();
smb.HttpGetEnabled = true;
smb.HttpGetUrl = new Uri(endPointAddress);
host.Description.Behaviors.Add(smb);
host.Open();
Console.WriteLine("Service up and running at:");
foreach (var ea in host.Description.Endpoints)
{
Console.WriteLine(ea.Address);
}
Console.ReadLine();
host.Close();
}
D. Client Proxy
public class ProxyTestService : ClientBase<ISampleService>, ISampleService
{
public ProxyTestService(string address)
:base (new BasicHttpBinding(BasicHttpSecurityMode.None),new EndpointAddress($"http://{address}:9942/ServiceTest/ISampleService"))
{
}
public DateTime GetServerTime()
{
return base.Channel.GetServerTime();
}
}
When I check on the computer where is the host running it is fine (address = localhost).
However, when I connect from another computer in the network (address = IPCompuerHost) there are various problems:
There was no endpoint listening at http://192.168.1.111:9942/ServiceTest/ISampleService that could accept the message. This is often caused by an incorrect address or SOAP action. See InnerException, if present, for more details.
InnerException: Unable to connect to the remote server
You have tried to create a channel to a service that does not support .Net Framing. It is possible that you are encountering an HTTP endpoint.
When I use NetTcpBinding, everything is correct. What is different in BasicHttpBinding??
What I have tried:
netsh http add urlacl url=http:
netsh advfirewall firewall add rule name="ServiceTest9942" dir=in protocol=tcp localport=9942 profile=private remoteip=localsubnet action=allow
netsh interface portproxy add v4tov4 listenport=9942 listenaddress=192.168.1.111 connectport=9942 connectaddress=192.168.1.1 protocol=tcp