WCF, netTcp and Visual Studio 10 - visual-studio-2010

I have a WCF service with netTcp bindings. This is my first WCF service and I'm having some issues with endpoints.
My goal during the development phase is to expose the service from my development machine using port forwarding. I've configured my IIS7 default website to listen to TCP on port 12345 and created the requisite bindings. The port is open on my firewall and port forwarded on the router. The Net.TCP services are all running. I think I've taken all the steps recommended in articles on here!
But, when I try to add a service reference in Visual Studio 10 using the svc file at the IP address for the service it creates an endpoint like this, pointing to my local hostname (VULCAN):
<client>
<endpoint address="net.tcp://vulcan:12345/CloudnetService/Dispatcher.svc"
binding="netTcpBinding" bindingConfiguration="netTcpBinding_IDispatcher"
contract="CloudnetService.IDispatcher" name="netTcpBinding_IDispatcher" />
</client>
This of course works locally, but obviously not on the Internet.
My second problem is that although my implemented service works perfectly well locally, it doesn't seem to be visible from outside. Telnet localhost 12345 finds the service. Netstat shows the port to be listening to TCP. But when I Telnet my IP and port I get "Could not open connection to the host, on port 12345: Connect failed".
This is the system.serviceModel section from my web.config (---.---.-.-- is a placeholder for my IP address):
<bindings>
<netTcpBinding>
<binding name="netTcpBinding_IDispatcher"
closeTimeout="00:01:00"
openTimeout="00:01:00"
receiveTimeout="00:10:00"
sendTimeout="00:01:00"
transactionFlow="false"
hostNameComparisonMode="StrongWildcard"
maxBufferPoolSize="524288"
maxReceivedMessageSize="65536">
<readerQuotas
maxDepth="32"
maxStringContentLength="8192" maxArrayLength="16384"
maxBytesPerRead="4096" maxNameTableCharCount="16384" />
<reliableSession
ordered="true"
inactivityTimeout="00:10:00" />
<security mode="None">
<message
clientCredentialType="None"
algorithmSuite="Default" />
</security>
</binding>
</netTcpBinding>
</bindings>
<services>
<service name="Service.Dispatcher">
<endpoint address=""
binding="netTcpBinding"
bindingConfiguration="netTcpBinding_IDispatcher"
contract="Service.Interfaces.IDispatcher"
name="netTcpBinding_IDispatcher">
</endpoint>
<host>
<baseAddresses>
<add baseAddress="net.tcp://---.---.-.--:12345/CloudnetService"/>
</baseAddresses>
</host>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior>
<serviceMetadata httpGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="true"/>
</behavior>
</serviceBehaviors>
</behaviors>
<serviceHostingEnvironment multipleSiteBindingsEnabled="false" />
Being new to this, I'm confident I'm doing something very basic wrong!
Many thanks in advance.
Tao

TCP based Internet connection is very difficult, as the Internet is not TCP friendly. Any firewall/router on the wire can simply block your traffic, and it is also hard to troubleshoot, as it is the Internet you have to dive into. So usually netTcp is limited to intranet or localhost usage.
You will have to stick to HTTP/HTTPS based bindings.

Related

Poor Peformance with BIG IP F5 WCF NetTCpBinding

I am facing issue of poor performance when used WCF having NetTcpbinding with Load Balancer
We have win form application which consumes WCF (net.tcp protocol). In production we have web Farm having 3 servers with load balancer (F5). WCF hosted in IIS. We are testing with only 1 user
Now when we point WCF to specific server (using either server name or IP); application really perform well. However when we give the DNS name (so that request is pass through load balancer) there is a significant drop in performance. Network team is saying from there side everything is properly working. Please help
Following is the configuration that i have tin WCF web.config file.
<system.serviceModel>
<diagnostics performanceCounters="All" />
<services>
<service behaviorConfiguration="GetProxyEnabled" name="companyname.InvOps.ServiceLayer.PAServiceServer">
<host>
<baseAddresses>
<add baseAddress="net.tcp://USHOUIOWEB012VT/PAService"/>
<!--<add baseAddress="net.tcp://xxx.uat.companyname.net/PAService/"/>-->
</baseAddresses>
</host>
<endpoint address="netTcpAddress" behaviorConfiguration="NetTcpEndPointBehaviour" binding="netTcpBinding" bindingConfiguration="NetTcpBinding" contract="companyname.InvOps.ServiceLayer.IPAService" />
<endpoint address="mex" binding="mexTcpBinding" contract="IMetadataExchange" />
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="GetProxyEnabled">
<serviceMetadata httpGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="true"/>
<dataContractSerializer maxItemsInObjectGraph="2147483647"/>
<serviceThrottling maxConcurrentCalls="200" maxConcurrentInstances="400" maxConcurrentSessions="200"/>
</behavior>
</serviceBehaviors>
<endpointBehaviors>
<behavior name="NetTcpEndPointBehaviour">
<dataContractSerializer maxItemsInObjectGraph="2147483647"/>
</behavior>
</endpointBehaviors>
</behaviors>
<bindings>
<netTcpBinding>
<binding name="NetTcpBinding"
closeTimeout="05:45:00"
openTimeout="05:45:00"
receiveTimeout="05:45:00"
sendTimeout="05:45:00"
transactionFlow="false"
transferMode="Buffered"
transactionProtocol="OleTransactions"
hostNameComparisonMode="StrongWildcard"
listenBacklog="10"
maxBufferPoolSize="2147483647"
maxBufferSize="2147483647"
maxConnections="10"
maxReceivedMessageSize="2147483647">
<readerQuotas maxDepth="32"
maxStringContentLength="2147483647"
maxArrayLength="2147483647"
maxBytesPerRead="2147483647"
maxNameTableCharCount="2147483647" />
<reliableSession ordered="true"
inactivityTimeout="05:45:00"
enabled="false" />
<security mode="Transport">
<transport clientCredentialType="Windows" protectionLevel="EncryptAndSign"/>
</security>
</binding>
</netTcpBinding>
</bindings>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" aspNetCompatibilityEnabled="true"/>
</system.serviceModel>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true"/>
</system.webServer>
Really appretiate any feedback or suggesttion. Also what is the recommended settings on F5 when used WCF with NetTcpBinding.
I got it working now. It was Load Balance configuration issue. We have changed the Virtual Server type from Standard to Performance (Layer 7). The performance is not improved to acceptable range.

Hosting the same WCF Service in IIS and in Windows Service

I am trying to decide on an architecture for a change in my web service. I need to make a WCF service. I want to make only one service and then host it either in the IIS or in a Windows service. Is this even possible, making this kind of reuse of a WCF Service? How would I go about doing this? The scenario is that some of our customers do not have access to start a Windows service but can install a WCF in the IIS.
Thank you in advance.
A WCF service is simply an assembly that abides by the WCF hosting interface and then provides a client interface that allows it to be accessed.
Hosting a WCF service occurs equally in IIS, Windows service, WinForm application, or a console application. It truly doesn't matter.
The client interface remains unchanged, although how the interface is exposed might change depending on hosting scenario. For example, you'll probably use one the http bindings in the IIS case, but might use TCP binding for Windows services. These bindings can be defined in the config file, so the code doesn't necessarily have to change to accommodate being hosted one way or the other.
In short, creating the WCF service should be independent of how it will eventually be hosted. For ease of maintenance on your part, though, I'd pick one or the other - Windows service or IIS.
you could have a windows service host the WCF and expose all end points on it..Http,TCP..
Windows service is better than IIS because IIS is a process in itself and then we place upon it a VD to host our website/WCF.As for the Windows Service,it will be one dedicated thread catering only to the WCF.I am sharing the app.config of windows service (details changed) to show how we have hosted WCF...hope it helps..
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.diagnostics>
<sources>
<source name="System.ServiceModel"
switchValue="Off" propagateActivity="true" >
<listeners>
<add name="SERVICE_MONITOR" type="System.Diagnostics.XmlWriterTraceListener"
initializeData="MyApp_MONITOR.svclog" />
</listeners>
</source>
<source name="MyApp_TRACE" switchValue="All" >
<listeners>
<add name="MyApp_TRACE_LISTENER" type="System.Diagnostics.XmlWriterTraceListener"
initializeData="MyApp_TRACE.svclog" />
</listeners>
</source>
</sources>
<trace autoflush="true" />
</system.diagnostics>
<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior name="OverAllServiceBehavior">
<serviceSecurityAudit
auditLogLocation="Application"
serviceAuthorizationAuditLevel="Failure"
messageAuthenticationAuditLevel="Failure"
suppressAuditFailure="true" />
<serviceDebug includeExceptionDetailInFaults="True" />
<serviceMetadata httpGetEnabled="True" httpsGetEnabled="True" />
<serviceThrottling maxConcurrentCalls="10000" maxConcurrentSessions="10000"
<dataContractSerializer maxItemsInObjectGraph="2147483647"/>
<serviceCredentials>
<userNameAuthentication
userNamePasswordValidationMode="Custom"
customUserNamePasswordValidatorType="MyAppHost.Authenticate, MyAppHost"/>
<serviceCertificate findValue="MyApp_MESSAGE" storeLocation="LocalMachine"
storeName="My" x509FindType="FindBySubjectName" />
<clientCertificate>
<authentication
certificateValidationMode="PeerTrust"
trustedStoreLocation="LocalMachine" />
</clientCertificate>
</serviceCredentials>
</behavior>
</serviceBehaviors>
<endpointBehaviors>
<behavior name="OverAllEndPointBehavior" />
</endpointBehaviors>
</behaviors>
<bindings>
<basicHttpBinding>
<binding name="ServiceBasicHttpEndPointBinding" closeTimeout="00:00:59"
openTimeout="00:00:59"
messageEncoding="Text"
<readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647"
maxNameTableCharCount="2147483647" />
<security mode="Message">
<message clientCredentialType="Certificate"/>
</security>
</binding>
</basicHttpBinding>
<wsHttpBinding>
<binding name="ServiceWSHttpEndPointBinding" closeTimeout="00:00:59"
openTimeout="00:00:59"
<readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647"
maxNameTableCharCount="2147483647" />
<security mode="TransportWithMessageCredential">
<transport clientCredentialType="None" />
<message clientCredentialType="Certificate"/>
</security>
</binding>
</wsHttpBinding>
<netTcpBinding>
<binding name="ServiceTCPEndPointBinding" maxBufferSize="2147483647"
<readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647"
maxNameTableCharCount="2147483647" />
<security mode="TransportWithMessageCredential">
<transport
clientCredentialType="Certificate"
protectionLevel="EncryptAndSign" />
<message clientCredentialType="UserName" algorithmSuite="TripleDes"/>
</security>
</binding>
</netTcpBinding>
</bindings>
<services>
<service behaviorConfiguration="OverAllServiceBehavior"
name="MiddleWare.ServiceClasses.ServiceClass">
<host>
<baseAddresses>
<add baseAddress="net.tcp://127.0.0.1:15010/ServiceTCPEndPointMEX"/>
<add baseAddress="http://127.0.0.1:15020/ServiceHttpEndPointMEX"/>
<add baseAddress="https://127.0.0.1:15030/ServiceWSHttpEndPointMEX"/>
</baseAddresses>
</host>
<endpoint address="net.tcp://127.0.0.1:15040/ServiceTCPEndPoint"
contract="MiddleWare.ServiceContracts.IServiceContract" />
<endpoint address="http://127.0.0.1:15050/ServiceBasicHttpEndPoint"
contract="MiddleWare.ServiceContracts.IServiceContract"/>
<endpoint address="https://127.0.0.1:15060/ServiceWSHttpEndPoint"
contract="MiddleWare.ServiceContracts.IServiceContract"/>
<endpoint address="mex" binding="mexTcpBinding" contract="IMetadataExchange" />
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
<endpoint address="mex" binding="mexHttpsBinding" contract="IMetadataExchange" />
</service>
</services>
</system.serviceModel>
<appSettings>
<add key="UserName" value="USER"/>
<add key="Password" value="PASSWORD"/>
</appSettings>
</configuration>

WCF Hosted as Service

I have a VB.NET WCF service hosted as a Window Service. I was able to create an install package, install the service to my machine, and start the service manually from Services in Administrative Tools.
Now when I try to reference the service in my test console application (Address: http://localhost:8080/), I get the following error:
There was an error downloading 'http://localhost:8080'.`
Unable to connect to the remote
server No connection could be made
because the target machine actively
refused it 127.0.0.1:8080`
Metadata contains a reference that
cannot be resolved:
'http://localhost:8080/'. Could not
connect to http://localhost:8080/. TCP
error code 10061: No connection could
be made because the target machine
actively refused it 127.0.0.1:8080.
Unable to connect to the remote server
No connection could be made because
the target machine actively refused it
127.0.0.1:8080 If the service is defined in the current solution, try
building the solution and adding the
service reference again.
Not sure what I can do about this. Any ideas???
Thanks,
Jason.
Here's the code from app.config inside my service:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.diagnostics>
<sources>
<!-- This section defines the logging configuration for My.Application.Log -->
<source name="DefaultSource" switchName="DefaultSwitch">
<listeners>
<add name="FileLog"/>
<!-- Uncomment the below section to write to the Application Event Log -->
<!--<add name="EventLog"/>-->
</listeners>
</source>
</sources>
<switches>
<add name="DefaultSwitch" value="Information" />
</switches>
<sharedListeners>
<add name="FileLog"
type="Microsoft.VisualBasic.Logging.FileLogTraceListener, Microsoft.VisualBasic, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL"
initializeData="FileLogWriter"/>
</sharedListeners>
</system.diagnostics>
<system.serviceModel>
<services>
<service name="ExStreamWCF.Service1"
behaviorConfiguration="ExStreamWCF.Service1Behavior">
<!-- Service Endpoints -->
<host>
<baseAddresses>
<add baseAddress = "http://localhost:8080/Design_Time_Addresses/JasonsService/Service/" />
</baseAddresses>
</host>
<endpoint address="" binding="wsHttpBinding" contract="ExStreamWCF.IService1">
<identity>
<dns value="localhost"/>
</identity>
</endpoint>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="ExStreamWCF.Service1Behavior">
<serviceMetadata httpGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="false"/>
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
</configuration>
If anyone needs more from me please let me know!
Not sure if it's really an issue - but on a production server, I would never use localhost as my base address.
So can you try to change:
<service name="ExStreamWCF.Service1"
behaviorConfiguration="ExStreamWCF.Service1Behavior">
<host>
<baseAddresses>
<add baseAddress = "http://localhost:8080/Design_Time_Addresses/JasonsService/Service/" />
</baseAddresses>
</host>
to
<service name="ExStreamWCF.Service1"
behaviorConfiguration="ExStreamWCF.Service1Behavior">
<host>
<baseAddresses>
<add baseAddress = "http://YourServerName:8080/Design_Time_Addresses/JasonsService/Service/" />
</baseAddresses>
</host>
Does that make any difference when calling into the service??

Do I need to do anything special to make WCF calls work over HTTPS, ..if HTTP works fine?

I have two versions of the same proof-of-concept site: The unsecure version:
http://www.tlsadmin.com/tlsadmin/PortalHome.aspx
and the secure version:
https://www.tlsadmin.com/tlsadmin/PortalHome.aspx
The problem I have is that my WCF-Based web services don't seem to work under HTTPS. Is there something I'm missing, or not understanding about this? I thought a relative URL for the SVC file would cover everything
<asp:ScriptManager ID="ScriptManager1" runat="server" >
<Services>
<asp:ServiceReference Path="~/Services/Contacts.svc" />
<asp:ServiceReference Path="~/Services/Domains.svc" />
<asp:ServiceReference Path="~/Services/TreeViewNavigation.asmx" />
<asp:ServiceReference Path="/Services/FullSoaSchedulerService.svc/json" />
</Services>
</asp:ScriptManager>
Perhaps I need to add an additional binding for the webservice to work over HTTPS?
<service name="LC.www.nexthop.mx.POC.grid_WebService.Domains">
<endpoint address="" behaviorConfiguration="LC.www.nexthop.mx.POC.grid_WebService.DomainsAspNetAjaxBehavior"
binding="webHttpBinding" contract="LC.www.nexthop.mx.POC.grid_WebService.Domains" />
</service>
You want to add a custom binding to your configuration to enable it for HTTPS by setting your binding's security mode to transport.
<bindings>
<webHttpBinding>
<binding name="httpsBinding">
<security mode="Transport">
</security>
</binding>
</webHttpBinding>
</bindings>
The default security mode is None which doesn't play well with HTTPS.
Then assign that binding to your endpoint:
<service name="LC.www.nexthop.mx.POC.grid_WebService.Domains">
<endpoint address="" behaviorConfiguration="LC.www.nexthop.mx.POC.grid_WebService.DomainsAspNetAjaxBehavior"
binding="webHttpBinding" bindingConfiguration="httpsBinding" contract="LC.www.nexthop.mx.POC.grid_WebService.Domains" />
</service>
This blog post helped me out when I first ran into this situation.
Hope this helps!!

"Baseaddress not found"-error when deploying WCF service on GoDaddy

I'm trying to deploy a WCF-service, but I'm having dificulties getting the final bits to work. I'm not a deployment guru in any way, so please bear with me.
I'm using a WebHttpBinding to make Ajax calls to the service using JSON, but I receive the error: "Could not find a base address that matches scheme http for the endpoint with binding WebHttpBinding. Registered base address schemes are [].".
Here is a snippet of my web.config:
<system.serviceModel>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true">
<baseAddressPrefixFilters>
<add prefix="http://mysite.com/" />
</baseAddressPrefixFilters>
</serviceHostingEnvironment>
<bindings>
<webHttpBinding>
<binding name="webHttp">
<security mode="None">
<transport clientCredentialType="None"
proxyCredentialType="None"
realm="string" />
</security>
</binding>
</webHttpBinding>
</bindings>
<services>
<service name="LicenseManager.LicenseService" behaviorConfiguration="ServiceAspNetAjaxBehavior">
<endpoint address="" behaviorConfiguration="AjaxBehavior"
binding="webHttpBinding" contract="LicenseManager.ILicenseService" />
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
<host>
<baseAddresses>
<add baseAddress="http://mysite.com/" />
</baseAddresses>
</host>
</service>
</services>
<behaviors>
<endpointBehaviors>
<behavior name="AjaxBehavior">
<enableWebScript/>
</behavior>
</endpointBehaviors>
<serviceBehaviors>
<behavior name="ServiceAspNetAjaxBehavior">
<serviceMetadata httpGetEnabled="true" httpGetUrl="" />
<serviceDebug httpHelpPageEnabled="true" includeExceptionDetailInFaults="true" />
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
I've made so many changes and tried so many options that I honestly lost overview of what I'm doing. I hope you can find that tiny error that make it all work.
Thank you.
Is your site running directly under http://mysite.com, or is it running under an application/vdir under that site? If so, add the application in your <baseAddressPrefixFilter> element:
<baseAddressPrefixFilters>
<add prefix="http://mysite.com/MyApplication" />
</baseAddressPrefixFilters>
I don't think you need the trailing / either - but I don't think that's causing the issue.
Hopefully this helps! Let em know and I'll update my answer accordingly.
The error was caused by a silly mistake made by me.
My DNS was not set up yet, so I used GoDaddy's "Preview DNS" feature that lets me view the website before the DNS is set up. I used the preview address (mydomain.com.previewdns.com) when I should just have used mydomain.com.
My bad, thanks for the help!

Resources