Answered by:
Proxy for WCF service with NetTcpBinding

Question
-
Hi,
My WCF service run in IIS server with NetTcpBinding endpoint.
My client .NET application runs behind web proxy address.
The client is unable to contact the net.tcp service running in IIS, but without proxy it's work fine.
What is the solution?
Any help, greatly appreciated.
Thanks
sriniFriday, February 5, 2010 7:12 PM
Answers
-
Hi Norilka,
Thanks for your further description. So http based duplex binding is not working due to NAT restriction on client callback channel.
It seems netTcpBinding is the proper choice, but for your network environment, it require a proxy server to make it work.
I'm afraid so far tcp bindign doesn't have built-in support for supplying web proxy(like the webrequest proxy setting for http based protocols). You can try submit the issue to connect feedback site as a request on this:
#Welcome to the Windows Communication Foundation (WCF) site on Microsoft Connect!
https://connect.microsoft.com/wcf?wa=wsignin1.0
Currently, for two way communication between client and server, if it is not possible to establish an endpoint on client proactively, other possible solution is using a polling approach at client(to constantly poll information from server).
Please remember to mark the replies as answers if they help and unmark them if they provide no help.- Proposed as answer by James Peckham Friday, February 19, 2010 3:13 AM
- Marked as answer by Steven Cheng - MSFT Monday, February 22, 2010 2:03 AM
Friday, February 19, 2010 2:26 AM
All replies
-
Hi norilka,
As for the 'proxy' you mentioned here, is it the network proxy(such as http proxy or socket proxy)? If so, I'm afraid so far for netTcpBindign(which rely on the raw TCP communication) cannot leverage the .NET webproxy system. Here is a web article which also mentioend this:
#WCF netTcpBinding and ISA Server 2006 as a Proxy
http://geekswithblogs.net/MyTalk/archive/2008/09/25/125455.aspx
is it possible for you to use http based binding(for those client that need to connect via an intermediate webproxy)? If so, you can use WebRequest.DefaultWebProxy to supply the proxy:
#Proxy Detection - Take the Burden Off Users with Automatic Configuration in .NET
http://msdn.microsoft.com/en-us/magazine/cc300743.aspx
[WCF]How to supply dedicated credentials for webproxy authentication in WCF client
http://blogs.msdn.com/stcheng/archive/2008/12/03/wcf-how-to-supply-dedicated-credentials-for-webproxy-authentication.aspx
Please remember to mark the replies as answers if they help and unmark them if they provide no help.Monday, February 8, 2010 10:29 AM -
Hi Steven,
Thank you for replay. All this topics is interesting, but I think is not in my case :(
So this is my client cod :
NetTcpBinding objNetTcpBinding = new NetTcpBinding();
objNetTcpBinding.Security.Mode = SecurityMode.None;
objNetTcpBinding.PortSharingEnabled = true;
string endPointAddress = "net.tcp://mycompany.com:808/servicesite/vService.svc";
DuplexChannelFactory<IServiceChannel> objChannelFactory = new DuplexChannelFactory<IServiceChannel>( new ServiceCallback(this),
objNetTcpBinding,
endPointAddress);
objIServices = objChannelFactory.CreateChannel();
objItServices.Open();
My service run under IIS.
So When I run this client in home or my friend home it's work fine.
But if I run this client on my office it doesn't.
Because in office for go to internet I need set up proxy.
For IE ->Tools->Internet Options->Connection->Lan Settings->enable checkBox("Use a proxy server for ....")->Address :"gal.lp.com" Port : "8080"
So my question is : "How I can 'explain' to my client with NetTcpBinding, how work with thit proxy ? "
If my explanation is bad let me know, I will try different way ;-)
- Thanks Norilka
sriniWednesday, February 10, 2010 9:00 AM -
IIS supports only http and https. so u cant use nettcpbinding.Wednesday, February 10, 2010 11:38 AM
-
IIS from version 7.0 support NetTcpBindin.
Again my cod work between 2-3-5-10 different PC in different location, different IP etc...
But if you havein some place go to internet by proxy. I did explain that. Cod stop working !!!
- Norilka
sriniWednesday, February 10, 2010 7:35 PM -
Hi norilka,
Yes, IIS 7.0 support non-http bindings in virtual directory/site. However, the problem here is that the webproxy support in WCF(actually for .NET framework application) is based on http proxy. So far there is no built-in socket proxy(like sock5) support in those webrequest classes. The reference I sent you in previous reply is all the webproxy support in .NET framework currently. And the proxy setting in IE webbrowser is also http proxy.
for your office environment, if there is central proxy server/firewall server setup in your domain network, you can try installing a system proxy client like ISA client that will act as a system proxy underlyingly(intercept http and tcp communication)
#Firewall Client for ISA Server
http://www.microsoft.com/downloads/details.aspx?FamilyID=05C2C932-B15A-4990-B525-66380743DA89&displaylang=en
If using a system proxy is not possible, I'm afraid you may need to consider switch to http binding instead of tcp based binding.
Please remember to mark the replies as answers if they help and unmark them if they provide no help.Friday, February 12, 2010 2:40 AM -
Hi Steven,
Thank you a lot. But Today I am in very difficult situation. I did start from WSDualHttpBinding for create very simple chat and deploy this WCF service on IIS.
But NAT for WSDualHttpBinding is problem !!!
Look at some explanation about WSDualHttpBinding :
However, your problem is more complex. You're using wsDualHttpBinding, and you're
passing the local machine's name as the ClientBaseAddress. Keep in mind that when using
wsDualHttpBinding, the service will POST the message to the address indicated by
ClientBaseAddress. In your local network, this will not cause any problems, because the
local DNS for the machine that hosts the service is able to identify the machine name.
But in the cloud, we have no knowledge of what the domain http://MyPC is, so the
message cannot be sent to the client successfully... Any service that is hosted in the
internet and uses ws-addressing that passes a machine name to the ReplyTo element will
hit this issue. If you're not behind a NAT, you can try to specify your local machine's
IP address as the ClientBaseAddress. But if you're behind a NAT, this will be a
problem... You can use a duplex NetTcpBinding, which should not hit this issue .
So I go to NetTcpBinding, another problem ;-) So all of this problem I can't resolve diagrammatically.
So what I have to do.
Idea very simple : clientWPFChat => WCFService( Dual ) + IIS <= clientWPFChat .
Silverlight doesn't work for this situation.
So ???????
;-) Norilka
sriniFriday, February 12, 2010 8:24 AM -
Hi Norilka,
Thanks for your further description. So http based duplex binding is not working due to NAT restriction on client callback channel.
It seems netTcpBinding is the proper choice, but for your network environment, it require a proxy server to make it work.
I'm afraid so far tcp bindign doesn't have built-in support for supplying web proxy(like the webrequest proxy setting for http based protocols). You can try submit the issue to connect feedback site as a request on this:
#Welcome to the Windows Communication Foundation (WCF) site on Microsoft Connect!
https://connect.microsoft.com/wcf?wa=wsignin1.0
Currently, for two way communication between client and server, if it is not possible to establish an endpoint on client proactively, other possible solution is using a polling approach at client(to constantly poll information from server).
Please remember to mark the replies as answers if they help and unmark them if they provide no help.- Proposed as answer by James Peckham Friday, February 19, 2010 3:13 AM
- Marked as answer by Steven Cheng - MSFT Monday, February 22, 2010 2:03 AM
Friday, February 19, 2010 2:26 AM -
Hi Stiven,
Thank you very match to your response
;-) Norilka
srini- Proposed as answer by Swpnil Vyas Friday, December 26, 2014 6:35 AM
- Unproposed as answer by Swpnil Vyas Friday, December 26, 2014 6:35 AM
Friday, February 19, 2010 6:16 AM -
Hello all,
Sniper here, from the long time i am trying to resolve the issue that connecting TCP Client to TCP Server (having static IP ) behind proxy server in c#.
first in the mind i wrote simple TCP Client program for this type of communication , but
while debugging i found that for
TCPClient m_TCPClient = new TCPClient("some static IP",Port no);
application is wating for long time ( the time which i was set in connection OpenTimeOut)
after that it fails to connect.
I also found WCF technology for creating services , in that i referred TCPNetBinding but still it not able to communicate with my TCP server behind proxy connection.
so here i am sharing with you , how to connect to TCP Server behind proxy.
Let's Understand
Actually TCP/IP Communication is one type of transport layer communication. in OSI model.
an every data packet is sent over the network in form of data segments.
IP (Internet protocol) & ICMP(internet control messaage protocol) are the two most important protocol in the internet family they actually add the Destination address , source address & other details in the data packets which are transmitted over the network.
now in case for Proxy server communication , the proxy is acts like the middle layer of communication between Client & server , server just knows the addresss of proxy server which is acting as like Client , & at Client end, proxy server will acts like server, so the proxy server just passes the message from Client To Server & vise versa.
How To Solve?
so when u r trying to connect to TCP Server behind the proxy , first connect to proxy server
using
TCPClient m_TCPClient = new TCPClient("proxy server IP address",proxy server Port no);
after getting conneted, send ICMP command over TCP channel , actually this command is specified for SOCK5 proxy communication protocols. we will just use that protocol to communicate with our TCP server.
System.Net.Sockets.TcpClient t1 = null;
string str = "CONNECT proxy_machine_IP_address:proxy_port_no HTTP/1.1\n " +
"Accept: */*\n " +
"Host: proxy_machine_ip_address\n " +
"Proxy-Connection: Keep-Alive\n\n ";
byte[] btr = Encoding.ASCII.GetBytes(str);
t1 = new TcpClient("proxy_machine_ip_address", proxy_machine_port_no);
t1.GetStream().Write(btr, 0, btr.Length);
after writing this ICMP command over the network , the proxy server will reply at client end that whether the connection is established or not. you just have to read that message after that you can start your communication.
What to do in WCF?
WCF netTCpBinding is just an wrapper class over basic socket communication, i never tried to connect the Client to server over proxy connection, but here i am suggesting 1 example that how to
do the same stuff in WCF just follow the below steps.
1. create on WCF service project having at least one operation contract , & one callback contract.
2. create an WCf client for the same project.
3. after complete test, just replace that WCf service running behind with TCP Listener program running on the same port where the WCF service is running.
4. now run the WCf Client project ,
if you are using typed Clients or Channel factory, when the constructor is being called to create the channel between the client & server. you will see their is some predefied protocol request is forwarded from client to TCp Listener..
5. so for every method call from Client to Server or vise versa, their is predefined protocol message which is tranmitted over the TCP.
just copy those message & try to send them using TCpClient rather that WCf Clietn.
Please let me know if you have any quires.
Regards
Sniper
for more u can visit me at http://sniperguru.blogspot.in/- Edited by Swpnil Vyas Friday, December 26, 2014 6:37 AM
Friday, December 26, 2014 6:37 AM