Reputation: 163
I'm working on a client-server project in which clients are deployed over the internet. All the services are written in WCF and use wsHttpBinding
. I need to implement a client callback functionality, and since the clients are behind firewalls and NATs, I'm told I can use netTcpBinding
which bypasses firewall/NAT. So I created the service and the callback contract.
On the client side, this is how I'm trying to connect to it:
var binding = new NetTcpBinding();
binding.Security.Mode = SecurityMode.Message;
binding.Security.Message.ClientCredentialType = MessageCredentialType.UserName;
binding.MaxReceivedMessageSize = Int32.MaxValue;
binding.ReaderQuotas.MaxArrayLength = Int32.MaxValue;
AuthorizationToken authorizationToken =
new AuthorizationToken(Session.Current.Username, Session.Current.Password, RequiredPermission.User);
using (DuplexChannelFactory<INotificationService> channel =
new DuplexChannelFactory<INotificationService>(new InstanceContext(this), binding,
new EndpointAddress("net.tcp://mywebsite.com:808/MyServices/NotificationService.svc")))
{
channel.Credentials.UserName.UserName = authorizationToken.FormatTokenForTransmission();
channel.Credentials.ServiceCertificate.Authentication.CertificateValidationMode =
System.ServiceModel.Security.X509CertificateValidationMode.None;
INotificationService proxy = channel.CreateChannel();
proxy.Subscribe();
}
The code is almost identical to the code that connects to wsHttpBinding
services, except for the binding type and ChannelFactory
. The web.config
also looks like this:
<?xml version="1.0"?>
<configuration>
<system.web>
<compilation debug="true" targetFramework="4.0" />
</system.web>
<system.serviceModel>
<bindings>
<wsHttpBinding>
<binding name="wsHttpConfig" maxReceivedMessageSize="2147483647">
<security mode="Message" >
<message clientCredentialType="UserName"/>
</security>
<readerQuotas maxArrayLength="2147483647"/>
</binding>
</wsHttpBinding>
<netTcpBinding>
<binding name="netTcpConfig">
<security mode="Message" >
<message clientCredentialType="UserName"/>
</security>
<readerQuotas maxArrayLength="2147483647"/>
</binding>
</netTcpBinding>
</bindings>
<services>
<service name="MyProject.Services.NotificationService" behaviorConfiguration="authenticationBehavior">
<endpoint binding="netTcpBinding" bindingConfiguration="netTcpConfig"
contract="MyProject.ServiceContracts.INotificationService" />
<endpoint address="mex"
binding="mexTcpBinding"
bindingConfiguration=""
name="MyServiceMexTcpBidingEndpoint"
contract="IMetadataExchange" />
</service>
// other non-net.tcp services go here
</services>
<behaviors>
<serviceBehaviors>
<behavior name="authenticationBehavior">
<serviceMetadata httpGetEnabled="false" />
<serviceCredentials>
<serviceCertificate findValue="SomeCertificate" storeLocation="LocalMachine"
storeName="TrustedPeople" x509FindType="FindBySubjectName" />
<userNameAuthentication userNamePasswordValidationMode="Custom"
customUserNamePasswordValidatorType="MyProject.Authentication.CustomAuthenticator, MyProject.Authentication" />
</serviceCredentials>
</behavior>
<behavior name="">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="true" />
</behavior>
</serviceBehaviors>
</behaviors>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
</system.serviceModel>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true"/>
</system.webServer>
</configuration>
When I make a service call, the request does get to IIS
, but an exception is thrown with no inner exception message, and on the server side, I get the following trace log:
The socket connection was aborted. This could be caused by an error processing
your message or a receive timeout being exceeded by the remote host, or an underlying
network resource issue. Local socket timeout was '00:01:00
I understand this is a very generic error, and my question is, do you see anything wrong with my Web config settings? Any help is appreciated.
Upvotes: 0
Views: 828
Reputation: 1414
There could be multiple reasons -
1) Check if your net.tcp adapter service is running on (even try resetting it once) 2) Check your IIS service is configured to over Tcp binding 3) Check if tcp ports are open 4) Last try to increase your timeout time
Upvotes: 0