Adding web reference on client when using Net.TCP
Posted
by Marko
on Stack Overflow
See other posts from Stack Overflow
or by Marko
Published on 2009-06-30T08:55:36Z
Indexed on
2010/03/28
16:53 UTC
Read the original article
Hit count: 293
Hi everyone...
I am trying to using Net.TCP in my WCF Service, which is self hosted, when i try to add this service reference through web reference to my client, i am not able access the classes and methods of that service, can any have any idea to achieve this... How I can add web references in this case. My Service has one method (GetNumber) that returns int.
WebService:
public class WebService : IWebService
{
public int GetNumber(int num)
{
return num + 1;
}
}
Service Contract code:
[ServiceContract]
public interface IWebService
{
[OperationContract]
int GetNumber(int num);
}
WCF Service code:
ServiceHost host = new ServiceHost(typeof(WebService));
host.AddServiceEndpoint(typeof(IWebService), new NetTcpBinding(), new Uri("net.tcp://" + Dns.GetHostName() + ":1255/WebService"));
NetTcpBinding binding = new NetTcpBinding();
binding.TransferMode = TransferMode.Streamed;
binding.ReceiveTimeout = TimeSpan.MaxValue;
binding.MaxReceivedMessageSize = long.MaxValue;
Console.WriteLine("{0}", Dns.GetHostName().ToString());
Console.WriteLine("Opening Web Service...");
host.Open();
Console.WriteLine("Web Service is running on port {0}",1255);
Console.WriteLine("Press <ENTER> to EXIT");
Console.ReadLine();
This works fine. Only problem is how to add references of this service in my client application. I just want to send number and to receive an answer. Can anyone help me?
© Stack Overflow or respective owner