c# - Setting up WCF TCP service in a web application -
i've been battling days, literally going through hundred articles giving partial guidelines on how set wcf tcp based service in web application. if can me, make question complete guideline.
current status
the net.tcp connection works on development machine. works locally after being deployed windows server 2008 r2. however, doesn't work remotely, though it's possible telnet port 808 on server remotely. scroll bottom of question details. please if can.
i create new question detail , update question answer if result out of it.
code
i created serverhubservice.svc
following content:
namespace manage.signalr { [servicecontract] public class serverhubservice { [operationcontract] public void updateserverstatus(string serverstatus) { // } } }
configuration of application hosting service
following online tutorial, added following web.config (i tried many different variations). web.config of web application hosting service later want connect tcp.
<configuration> <system.servicemodel> <services> <service behaviorconfiguration="serverhubbehavior" name="manage.signalr.serverhubservice"> <endpoint address="" binding="nettcpbinding" bindingconfiguration="portsharingbinding" name="myserviceendpoint" contract="manage.signalr.serverhubservice"> <identity> <dns value="localhost" /> </identity> </endpoint> <endpoint address="mex" binding="mextcpbinding" bindingconfiguration="" name="myservicemextcpbidingendpoint" contract="imetadataexchange" /> <host> <baseaddresses> <add baseaddress="net.tcp://test.mydomain.com:808/signalr/serverhubservice.svc" /> </baseaddresses> </host> </service> </services> <behaviors> <servicebehaviors> <behavior name="serverhubbehavior"> <servicemetadata httpgetenabled="true" /> <servicedebug includeexceptiondetailinfaults="false" /> </behavior> </servicebehaviors> </behaviors> <bindings> <nettcpbinding> <binding name="portsharingbinding" portsharingenabled="true"/> </nettcpbinding> </bindings> <servicehostingenvironment aspnetcompatibilityenabled="true" minfreememorypercentagetoactivateservice="0" multiplesitebindingsenabled="true" /> </system.servicemodel> </configuration>
httpgetenabled="true"
important because otherwise cannot create service reference service.
configuration of server web application running
i setting on development machine has iis 7.5
i read iis express (built visual studio) doesn't support net.tcp, set new website in iis 7.5 using .net 4.5 , has net.tcp binding
i went advanced settings website , set enabled protocols http,net.tcp
i ensured windows feature non-http activation enabled (and restarted). it's windows feature "turn windows features on or off" find this.
confirming web application running
the website works fine rest of web application. set test.mydomain.com point 127.0.0.1 in hosts
file. can visit http://test.mydomain.com/signalr/serverhubservice.svc , show me nice auto generated page .net, explaining how use service.
so far good.
the page generated .net tells me use address generate connection service:
net.tcp://computername/signalr/serverhubservice.svc/mex
trying connect service client
if not remember set httpgetenabled="true"
error when trying create service reference it. if use wcf test client (also tool included in visual studio) , didn't set httpgetenabled, error following:
error: cannot obtain metadata net.tcp://computername/signalr/serverhubservice.svc/mex
if windows (r) communication foundation service have access, please check have enabled metadata publishing @ specified address. enabling metadata publishing, please refer msdn documentation @ http://go.microsoft.com/fwlink/?linkid=65455.ws-metadata
exchange error uri: net.tcp://computername/signalr/serverhubservice.svc/mex metadata contains reference cannot resolved: 'net.tcp://computername/signalr/serverhubservice.svc/mex'. not connect net.tcp://computername/signalr/serverhubservice.svc/mex. connection attempt lasted time span of 00:00:04.0032289.
tcp error code 10061: no connection made because target machine actively refused [2001:0:4137:9e76:c81:a4c:a547:b2fd]:808. no connection made because target machine actively refused [2001:0:4137:9e76:c81:a4c:a547:b2fd]:808
however, if you've done above, should able add reference service.
calling methods in service
when trying call simple hello world method in service wcf test client, returns following error:
could not connect net.tcp://computername/signalr/serverhubservice.svc. connection attempt lasted time span of 00:00:04.0002288. tcp error code 10061: no connection made because target machine actively refused it.
this inner stacktrace included in error:
no connection made because target machine actively refused [2001:0:5ef5:79fb:3884:a:a547:b2fd]:808 @ system.net.sockets.socket.doconnect(endpoint endpointsnapshot, socketaddress socketaddress) @ system.net.sockets.socket.connect(endpoint remoteep) @ system.servicemodel.channels.socketconnectioninitiator.connect(uri uri, timespan timeout)
if use netstat -an |find /i "listening"
see nothing listening on port 808, it's because net.tcp listener adapter service not running.
confirmation
the call goes through now, confirmation needed before can declared success. need confirm in fact net.tcp call on port 808 , not call on http endpoint. trying wireshark, doesn't show up, because it's call happening , local machine.
deployment
the last challenge conquer deploy on web server, ensuring works on development machine, works on web server.
it doesn't work after publish windows server 2008 r2. gives common socketexception: existing connection forcibly closed remote host
.
it works locally on server, doesn't work remotely.
here checklist used check server:
- is
net.tcp listener adapter
service running? yes - is iis site binding
net.tcp
set808:*
? yes - is enabled protocols under advanced settings site in iis set
http,net.tcp
? yes - is server listening on port 808? yes, checked
netstat -an |find /i "listening"
- is port 808 open in firewall? yes.
- firewall turned off on server.
- i can telnet server on port 808 outside
telnet mydomain.com 808
- in configuration of service on server, following confirmed:
- baseaddress adjusted
net.tcp://mydomain.com:808/signalr/serverhubservice.svc
- this
localhost
before, changedmydomain.com
after didn't work on server:<identity><dns value="mydomain.com" /></identity>
- baseaddress adjusted
- it has been tested client locally on server , on server. both can connect port 808 telnet , both give same error message.
what configuration missing on server? close goal. please assist me in troubleshooting , complete question.
here client configuration on server calling service:
<system.servicemodel> <bindings> <nettcpbinding> <binding name="myserviceendpoint" /> </nettcpbinding> </bindings> <client> <endpoint address="net.tcp://mydomain.com:808/signalr/serverhubservice.svc" binding="nettcpbinding" bindingconfiguration="myserviceendpoint" contract="serverhubservice.serverhubservice" name="myserviceendpoint"> <identity> <dns value="mydomain.com" /> </identity> </endpoint> </client> </system.servicemodel>
i tried without 808 configured in endpoint, rumored default port net.tcp connections. however, still gives same result.
instead of trying lots of things randomly, question perhaps: how 1 debug this? can install program on either server tell me why call being blocked?
with wireshark configured this, it's possible @ call coming server on port 808 , possibly determine why call doesn't work. however, have no idea how analyze @ present time.
good luck
i gave , implemented in socket layer instead. worked immediately. hope can else, though. i'm setting answer because many of issues solved , did work locally eventually, problem remaining related me specific environment.
you have generate proxy based on metadata exposed on http tcp.(make sure httpgetenabled set true). address use @ client should hosted address. please refer below post.
http://blogs.msdn.com/b/swiss_dpe_team/archive/2008/02/08/iis-7-support-for-non-http-protocols.aspx
Comments
Post a Comment