0

we have an SP web part calling WCF service using simple http binding. They are located on different servers in different countries, so not the same machine. Using WCF we send/receive some files, which are processed at the WCF server site, parsed and stored to database. It takes some time, of course, but usually not more than minute or 2. On development server it works normally but on production server we are facing problems like

System.Threading.ThreadAbortException: Thread was being aborted. at System.Net.UnsafeNclNativeMethods.OSSOCK.recv(IntPtr socketHandle, Byte* pinnedBuffer, Int32 len, SocketFlags socketFlags) at System.Net.Sockets.Socket.Receive(Byte[] buffer, Int32 offset, Int32 size, SocketFlags socketFlags, SocketError& errorCode) at System.Net.Sockets.NetworkStream.Read(Byte[] buffer, Int32 offset, Int32 size) at System.Net.PooledStream.Read(Byte[] buffer, Int32 offset, Int32 size) at System.Net.Connection.SyncRead(HttpWebRequest request, Boolean userRetrievedStream, Boolean probeRead) at System.Net.ConnectStream.ProcessWriteCallDone(ConnectionReturnResult returnResult) at System.Net.HttpWebRequest.GetResponse() at System.ServiceModel.Channels.HttpChannelFactory`1.HttpRequestChannel.HttpChannelRequest.WaitForReply(TimeSpan timeout) at System.ServiceModel.Channels.RequestChannel.Request(Message message, TimeSpan timeout) at System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[] outs, TimeSpan timeout) at System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCallMessage methodCall, ProxyOperationRuntime operation) at System.ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessage message) at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type) at DHI.FRMP.Sharepoint.Tasks.MCSPConnector.IMCSPConnector.TaskUpdate(TaskUpdateRequest request) at DHI.FRMP.Sharepoint.Tasks.TaskEditSave.TaskEditSave.btnSaveChanges_Click(Object sender, ImageClickEventArgs e)

or

System.Threading.ThreadAbortException: Thread was being aborted. at System.Threading.WaitHandle.WaitOneNative(SafeHandle waitableSafeHandle, UInt32 millisecondsTimeout, Boolean hasThreadAffinity, Boolean exitContext) at System.Threading.WaitHandle.InternalWaitOne(SafeHandle waitableSafeHandle, Int64 millisecondsTimeout, Boolean hasThreadAffinity, Boolean exitContext) at System.Net.LazyAsyncResult.WaitForCompletion(Boolean snap) at System.Net.Connection.SubmitRequest(HttpWebRequest request, Boolean forcedsubmit) at System.Net.ServicePoint.SubmitRequest(HttpWebRequest request, String connName) at System.Net.HttpWebRequest.SubmitRequest(ServicePoint servicePoint) at System.Net.HttpWebRequest.GetRequestStream(TransportContext& context) at System.Net.HttpWebRequest.GetRequestStream() at System.ServiceModel.Channels.HttpOutput.WebRequestHttpOutput.GetOutputStream() at System.ServiceModel.Channels.HttpOutput.Send(TimeSpan timeout) at System.ServiceModel.Channels.HttpChannelFactory`1.HttpRequestChannel.HttpChannelRequest.SendRequest(Message message, TimeSpan timeout) at System.ServiceModel.Channels.RequestChannel.Request(Message message, TimeSpan timeout) at System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[] outs, TimeSpan timeout) at System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCallMessage methodCall, ProxyOperationRuntime operation) at System.ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessage message) at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type) at DHI.FRMP.Sharepoint.Tasks.MCSPConnector.IMCSPConnector.GetTaskCatchmentList(GetTaskCatchmentListRequest request) at DHI.FRMP.Sharepoint.Tasks.TaskAdd.ddlWaterRegion_SelectedIndexChanged(Object sender, EventArgs e)

WE have already checked that the client is properly closed and disposed. We also know that the web service call is processed correctly (from the logs). Streams are closed.

WCF is hosted in windows service application, used .NET 4.0. WCF config:

<system.serviceModel>
<client />
<bindings>
  <basicHttpBinding>
    <binding name="StreamedHTTP" closeTimeout="04:01:00" openTimeout="04:01:00"
      receiveTimeout="04:10:00" sendTimeout="04:01:00" maxBufferSize="2147483647"
      maxReceivedMessageSize="2147483647" messageEncoding="Mtom" transferMode="Streamed">
      <readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647"
        maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />
    </binding>
  </basicHttpBinding>
</bindings>
<services>
  <service name="DHI.FRMP.MCSPConnector.MCSPConnector">
    <endpoint address="" binding="basicHttpBinding" bindingConfiguration="StreamedHTTP"
      contract="DHI.FRMP.MCSPConnector.IMCSPConnector">
      <identity>
        <dns value="localhost" />
      </identity>
    </endpoint>
    <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
  </service>
</services>
<behaviors>
  <serviceBehaviors>
    <behavior>
      <!-- To avoid disclosing metadata information, 
      set the values below to false before deployment -->
      <serviceMetadata httpGetEnabled="True" httpsGetEnabled="False"/>
      <!-- To receive exception details in faults for debugging purposes, 
      set the value below to true.  Set to false before deployment 
      to avoid disclosing exception information -->
      <serviceDebug includeExceptionDetailInFaults="True"/>
    </behavior>
  </serviceBehaviors>
</behaviors>

Client creation code

    public static IMCSPConnectorChannel CreateWCFclient(out ChannelFactory<IMCSPConnectorChannel> factory)
    {

        BasicHttpBinding myBinding = new BasicHttpBinding();
        TimeSpan timeOut = new TimeSpan(4, 1, 0);
        int maxSize = 2147483647;
        myBinding.CloseTimeout = timeOut;
        myBinding.OpenTimeout = timeOut;
        myBinding.ReceiveTimeout = timeOut;
        myBinding.SendTimeout = timeOut;
        myBinding.AllowCookies = false;
        myBinding.BypassProxyOnLocal = false;
        myBinding.HostNameComparisonMode = HostNameComparisonMode.StrongWildcard;
        myBinding.MaxBufferSize = maxSize;
        myBinding.MaxBufferPoolSize = maxSize;
        myBinding.MaxReceivedMessageSize = maxSize;
        myBinding.MessageEncoding = WSMessageEncoding.Mtom;
        myBinding.TextEncoding = System.Text.Encoding.UTF8;
        myBinding.TransferMode = TransferMode.Streamed;
        myBinding.UseDefaultWebProxy = true;
        myBinding.ReaderQuotas.MaxDepth = 128;
        myBinding.ReaderQuotas.MaxStringContentLength = maxSize;
        myBinding.ReaderQuotas.MaxArrayLength = maxSize;
        myBinding.ReaderQuotas.MaxBytesPerRead = maxSize;
        myBinding.ReaderQuotas.MaxNameTableCharCount = maxSize;

        ChannelFactory<IMCSPConnectorChannel> myFactory = null;
        //SPSecurity.RunWithElevatedPrivileges(delegate()
        //{
        var constants = new Settings(SPContext.Current.Site);//siteelev);
        string endpointAddress = constants.WcfUrl;
        EndpointAddress myEndpoint = new EndpointAddress(endpointAddress);

        myFactory = new ChannelFactory<IMCSPConnectorChannel>(myBinding, myEndpoint);

        //});
        IMCSPConnectorChannel channel = myFactory.CreateChannel();
        factory = myFactory;
        return channel;

    }

Client and factory are both disposed after each usage.

Any idea what can be wrong?

1

it has started to work - since nobody answered me here, I placed the same question also to MSDN and placed there also the answer https://social.msdn.microsoft.com/Forums/vstudio/en-US/55096c4e-9d3a-487b-a98d-8a7fe962cfb1/wcf-called-from-sharepoint-thread-abort-exception?forum=wcf&prof=required

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.