WCF and Sharepoint. "An existing connection was forcibly closed by the remote host"


  • I try to use Sharepoint as a WCF client. I have aspx forms. this forms are called when the user clic k the task in her/his task list. when the form is loading this calls a method that is in the WCf service.

    I have Sharepoint in one server and  the WCf service is in other server but in the same lan. there is not any firewall or netwaorking divece between them. The error the I receive is "An existing connection was forcibly closed by the remote host "

    What I have in the web.config file is:


                    <binding name="NetTcpBinding_IAmpesOmis" closeTimeout="00:01:00"
                        openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
                        transactionFlow="false" transferMode="Buffered" transactionProtocol="OleTransactions"
                        hostNameComparisonMode="StrongWildcard" listenBacklog="10"
                        maxBufferPoolSize="524288" maxBufferSize="65536" maxConnections="10"
                        <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
                            maxBytesPerRead="4096" maxNameTableCharCount="16384" />
                        <reliableSession ordered="true" inactivityTimeout="00:10:00"
                            enabled="false" />
                        <security mode="Transport">
                            <transport clientCredentialType="Windows" protectionLevel="EncryptAndSign" />
                            <message clientCredentialType="Windows" />
                <endpoint address="net.tcp://XXXXX:8081/" binding="netTcpBinding"
                    bindingConfiguration="NetTcpBinding_IAmpesOmis" contract="AmpesOmisService.IAmpesOmis"
                        <dns value="host\XXXXX" />

    When I test the conection between server out of sharepoint, everything works ok. I developed an application for testing and this is working ok outside of sharepoint.


    Does someone have any idea?








    Monday, October 06, 2008 9:26 PM

All replies

  • Hi Henry,


    An unexpected error is happening on the service side, so the connection is closed. You will have to enable the WCF trace to find out what is going on,




    <source name="System.ServiceModel.MessageLogging" switchValue="Information, ActivityTracing">


    <add name="ServiceModelMessageLoggingListener" />



    <source name="System.ServiceModel" switchValue="Error, ActivityTracing" propagateActivity="true">


    <add name="ServiceModelTraceListener" />





    <add initializeData="messages.svclog" type="System.Diagnostics.XmlWriterTraceListener, System, Version=, Culture=neutral, PublicKeyToken=b77a5c561934e089" name="ServiceModelMessageLoggingListener" traceOutputOptions="Timestamp">


    <add initializeData="tracelog.svclog" type="System.Diagnostics.XmlWriterTraceListener, System, Version=, Culture=neutral, PublicKeyToken=b77a5c561934e089" name="ServiceModelTraceListener" traceOutputOptions="Timestamp">



    <trace autoflush="true" />



    You will usually find the error in the tracelog.svclog file.




    • Proposed as answer by Pablo Cibraro Thursday, October 16, 2008 2:42 PM
    Tuesday, October 07, 2008 2:16 PM

    Thanks Pablo.  I will try to put the <system.diagnostics> in my WCF. Pablo the WCF service is host in a window service. the WCf uses TCp protocol.


    is this going to work as well?


    thanks again!!


    Tuesday, October 07, 2008 6:05 PM

    Ok Pablo what I get in the Tracelog.svlog is


    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 '10675199.02:48:05.4775807'.


    I am sure that it is not timeout since I have 10:00:00 in timeouts. I do not know I do not have idea where is the problem. When I use the WCf service in the a littler application that i didi for testing the WCf service is working ok, The problem is when I try to use the WCf in Sharepoint in one of my ASPx forms.


    Do you have some idea?


    Thank for your help!1


    Tuesday, October 07, 2008 6:20 PM
  • Hi,

    I am fiddeling with the same issue. But you are corrent its not about the Timeout! Infact when you make the 

    <security mode="None"> from  <security mode="Transport">, the connections gets established. But the whole point is it will run without any Security setting :(

    Is this something to with the the use who is accessing the service or the machine/s which are talking to each other? 

    Wednesday, October 15, 2008 6:36 AM
  • Henry,

    We are sailing on the same boat, the only difference here is that I am running a pure Client Server (Service) enviornment.  I have a wiered doubt - Is this something to do with the amount od data that particular service is sending across ?

    Did you tried with a simple service, single method (contract and implementation) ?  I have 12 services our of which few works - other dont.

    Infact this started when I was trying to add reference to the services but it denied for few - then I created a seperate settings for svcutil (svcutil.config) and created the client using that.

    I got all the endpoints created (which were not happening using the add reference), BUT now the services say.."An existing connection was forcibly closed by the remote host". I have a doubt about the amount of data its transporting....Need to try it out.

    What do you think?

    Thursday, October 16, 2008 6:03 PM
  • Hello,

    I've had similar problems and found a cause; hopefully it helps someone else as well... 

    I used a NetTcpBinding with Certificates, Transport security mode and sign+encrypt. It was finally resolved when I set the security mode to TransportWithMessageCredential

    I used code instead of config, but the concept is the same:

    // First the binding
    NetTcpBinding tcpBinding = new NetTcpBinding();
    // TransportWithMessageCredential security, as Transport causes exceptions
    tcpBinding.Security.Mode = SecurityMode.TransportWithMessageCredential;
    // We authenticate with a certificate
    tcpBinding.Security.Transport.ClientCredentialType = TcpClientCredentialType.Certificate;
    // Make sure our data is not just encrypted, but consistent and authenticated by a signature
    tcpBinding.Security.Transport.ProtectionLevel = ProtectionLevel.EncryptAndSign;
    // We will use streams for large amounts of data, so streaming is the way to fly!
    tcpBinding.TransferMode = TransferMode.Streamed;
    // We create the URI to our service
    Uri uri = new Uri(String.Format("net.tcp://{0}:10558/MyService", ip.ToString()));
    // We have multiple IP addresses for a single DNS address, since we cluster our Services.
    // WCF will fail if our server certificate says and our uri is an
    // IP address. We create the DNS EndpointIdentity to tell WCF what the DNS would be.
    EndpointIdentity ident = EndpointIdentity.CreateDnsIdentity("");
    // We do not have any headers at the moment.
    AddressHeaderCollection headers = new AddressHeaderCollection();
    // Create the end point for our client
    EndpointAddress addr = new EndpointAddress(uri, ident, headers);
    // Connect to the client with our tcp binding and end point.
    SyncItServiceClient client = new SyncItServiceClient(tcpBinding, addr);
    // We still need to set up some authentication stuff before opening our client
    // First we have a variable named "clientCertificate" of type X509Certificate2 that
    // we use to authenticate this client.
    client.ClientCredentials.ClientCertificate.Certificate = clientCertificate;
    // In my case, I don't want automatic certificate authentication, so I set it to custom.
    client.ClientCredentials.ServiceCertificate.Authentication.CertificateValidationMode = X509CertificateValidationMode.Custom;
    // Now I add my own X509CertificateValidator derived class with the function Verify
    client.ClientCredentials.ServiceCertificate.Authentication.CustomCertificateValidator = new SyncItCertificateValidator();
    // In my setup I cannot check online for revocations, so we keep it to offline.
    client.ClientCredentials.ServiceCertificate.Authentication.RevocationMode = X509RevocationMode.Offline;
    // No user interaction, we are a service!
    client.ClientCredentials.SupportInteractive = false;
    // And GO!

    Friday, May 22, 2009 12:43 PM