none
WCF service shutting down RRS feed

  • Question

  • Hi,

    i have been trying to access WCF service function(Which loads C++ Dll's too) in a C# client project.

    When ever i start client program it fetches the service, loads the dll, but suddenly WCF service will be terminated from the system tray.

    I have added timeout parameters in web.config(Service) and app.config(Client).

    i have tried to log the error as said here but still its not logging the errors.

    what's causing this error, any help will be appreciated.

    Regards,
    Jithendra
    Friday, January 30, 2015 12:46 PM

Answers

  • Hi,

    My problem was in c++ Dll not in WCFService which i was loading in WCF Service. As per this Link explanation, i was doing

    this

    char* pszReturn = new char[256];

    instead of this

    char* pszReturn = NULL;
    pszReturn = (char*)::CoTaskMemAlloc(ulSize);

    this was causing error in returning the value, and in result below exception was thrown.

    Content Type application/soap+xml; charset=utf-8 was sent to a service expectingtext/xml; charset=utf-8. The client and service bindings may be mismatched.

    Hope it helps somebody and Special Thanks for @

    Avatar of darnold924
    darnold924

    for leading me to this.

    Regards,

    Jithendra.

    • Marked as answer by Jithendra_hyd Tuesday, February 3, 2015 8:10 AM
    Tuesday, February 3, 2015 8:10 AM

All replies


  • i have tried to log the error as said here but still its not logging the errors.

    What do you mean you are trying to log the error?  The only way you are going to do that is to use try/catches at the highest code point on the WCF service side and log the exception with something like Log4Net. And you would be using the exception.Tostring() to get the stack trace and inner exception message too and log it with Log4Net.

    http://www.codeproject.com/Articles/140911/log-net-Tutorial

    https://msdn.microsoft.com/en-us/library/system.exception.tostring(v=vs.110).aspx

    You asking what is causing the error without some exception messages posted by you is like you are the one looking for a needle in a haystack.

    Friday, January 30, 2015 3:53 PM
  • @darnold924 , i am facing below error, i got this when i was trying to debug.

    An error occurred while receiving the HTTP response to
    http://localhost:50316/Service1.svc.
      This could be due to the service
      endpoint binding not using the HTTP
      protocol. This could also be due to an
      HTTP request context being aborted by
      the server (possibly due to the
      service shutting down). See server
      logs for more details.]
    When i searched this error in web, i found several solutions, like adding/increasing timeout parameters in web.config, but none of them helped me to resolve this error.


    Sunday, February 1, 2015 6:37 AM
  • All you have is generic exception message, a catch22 error,  that WCF throws out there to the client. The WCF service is blowing up, and the real exception is being swallowed on the service side, because WCF does not throw exceptions over the boundary between the WCF service and the client.   

    You don't have the real  exception message that is causing the problem, which I gave advis on how to get the real exception message.

    Hey and however, I could be wrong! But I have faced that bullet. :) 

    Sunday, February 1, 2015 7:46 AM
  • I have traced the error by logging trace.svclog here , i am trying to understand it, any help will be appreciated.

    Monday, February 2, 2015 6:15 AM
  • You don't know what the error is and you won't go after it. I can tell that you don't have a try/catch in any code on the service side - none no where to be found.

    So it is what it is for you.

    Monday, February 2, 2015 11:49 AM
  • @

    Avatar of darnold924

    I have added try/Catch in server side as well the exception that throws is as below.

    System.ServiceModel.CommunicationException was unhandled
      _HResult=-2146233087
      _message=An error occurred while receiving the HTTP response to http://localhost:50368/Service1.svc. This could be due to the service endpoint binding not using the HTTP protocol. This could also be due to an HTTP request context being aborted by the server (possibly due to the service shutting down). See server logs for more details.
      HResult=-2146233087
      IsTransient=false
      Message=An error occurred while receiving the HTTP response to http://localhost:50368/Service1.svc. This could be due to the service endpoint binding not using the HTTP protocol. This could also be due to an HTTP request context being aborted by the server (possibly due to the service shutting down). See server logs for more details.
      RemoteStackTrace=
    Server stack trace: 
       at System.ServiceModel.Channels.HttpChannelUtilities.ProcessGetResponseWebException(WebException webException, HttpWebRequest request, HttpAbortReason abortReason)
       at System.ServiceModel.Channels.HttpChannelFactory`1.HttpRequestChannel.HttpChannelRequest.WaitForReply(TimeSpan timeout)
       at System.ServiceModel.Channels.RequestChannel.Request(Message message, TimeSpan timeout)
       at System.ServiceModel.Dispatcher.RequestChannelBinder.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.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[] outs)
       at System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCallMessage methodCall, ProxyOperationRuntime operation)
       at System.ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessage message)
    
    Exception rethrown at [0]: 
    
      Source=mscorlib
      StackTrace:
        Server stack trace: 
           at System.ServiceModel.Channels.HttpChannelUtilities.ProcessGetResponseWebException(WebException webException, HttpWebRequest request, HttpAbortReason abortReason)
           at System.ServiceModel.Channels.HttpChannelFactory`1.HttpRequestChannel.HttpChannelRequest.WaitForReply(TimeSpan timeout)
           at System.ServiceModel.Channels.RequestChannel.Request(Message message, TimeSpan timeout)
           at System.ServiceModel.Dispatcher.RequestChannelBinder.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.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[] outs)
           at System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCallMessage methodCall, ProxyOperationRuntime operation)
           at System.ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessage message)
        Exception rethrown at [0]: 
           at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg)
           at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type)
           at TestClient.ServiceReference1.IService1.Genkey()
           at TestClient.ServiceReference1.Service1Client.Genkey() in e:\Jit_Edit\WcfService1\TestClient\Service References\ServiceReference1\Reference.cs:line 81
           at TestClient.Program.Main(String[] args) in e:\Jit_Edit\WcfService1\TestClient\Program.cs:line 15
           at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
           at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
           at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
           at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
           at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
           at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
           at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
           at System.Threading.ThreadHelper.ThreadStart()
      InnerException: System.Net.WebException
           _HResult=-2146233079
           _message=The underlying connection was closed: An unexpected error occurred on a receive.
           HResult=-2146233079
           IsTransient=false
           Message=The underlying connection was closed: An unexpected error occurred on a receive.
           Source=System
           StackTrace:
                at System.Net.HttpWebRequest.GetResponse()
                at System.ServiceModel.Channels.HttpChannelFactory`1.HttpRequestChannel.HttpChannelRequest.WaitForReply(TimeSpan timeout)
           InnerException: System.IO.IOException
                _HResult=-2146232800
                _message=Unable to read data from the transport connection: An existing connection was forcibly closed by the remote host.
                HResult=-2146232800
                IsTransient=false
                Message=Unable to read data from the transport connection: An existing connection was forcibly closed by the remote host.
                Source=System
                StackTrace:
                     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)
                InnerException: System.Net.Sockets.SocketException
                     _HResult=-2147467259
                     _message=An existing connection was forcibly closed by the remote host
                     HResult=-2147467259
                     IsTransient=false
                     Message=An existing connection was forcibly closed by the remote host
                     Source=System
                     ErrorCode=10054
                     NativeErrorCode=10054
                     StackTrace:
                          at System.Net.Sockets.Socket.Receive(Byte[] buffer, Int32 offset, Int32 size, SocketFlags socketFlags)
                          at System.Net.Sockets.NetworkStream.Read(Byte[] buffer, Int32 offset, Int32 size)
                     InnerException: 

    till now i have tried most of the solutions suggested in Internet, i need to know what is the error causing this, their are so many out their who faced same error but most of them didn't get correct solution for this. Here is my entire code i am working on.

    Code

    This code contains 2 solutions, HelloWorld is a C++ Dll which is i am trying to load in service & WcfService1 Contains both WCF service and Client Projects. These projects have all the changes made till now based on internet solutions.


    Monday, February 2, 2015 12:31 PM
  • Well, you need a classlib project .NET that is going to reference the C++ DLL, and the WCF  service has reference to the classlib project. It might work for you. I doubt it, and you need to dump the C++ DLL if it's a non .NET managed DLL.

    And where is the inner exception message if any?

    Monday, February 2, 2015 12:54 PM
  • Also, if that C++ program is trying to send something that is not serializable, it's going send things down the tubes. 
    Monday, February 2, 2015 12:58 PM
  • @

    Avatar of darnold924

    darnold924

    Well, you need a classlib project .NET that is going to reference the C++ DLL, and the

    WCF service has reference to the classlib project. It might work for you. I doubt it,

    and you need to dump the C++ DLL if it's a non .NET managed DLL.

    What'll it do exactly, nothing but it'll just create a middle layer between WCFApp and C++ Dll rather using DLLIMPORT is generic one rite which is also reccommended.

    This is what i am getting since from yesterday and this error is been traced in SvcLog.

    Content Type application/soap+xml; charset=utf-8 was sent to a service expecting

    text/xml; charset=utf-8. The client and service bindings may be mismatched.

    and Here's my WCFService Web.config

    <configuration>
      <appSettings>
        <add key="aspnet:UseTaskFriendlySynchronizationContext" value="true" />
      </appSettings>
      <system.web>
        <compilation debug="true" targetFramework="4.5" />
        <httpRuntime targetFramework="4.5" maxRequestLength="2147483647"/>
      </system.web>
      <system.serviceModel>
        <!-- Bindings Very Important Jit Edit -->
        <bindings>
          <basicHttpBinding>
            <!-- Added few extra Params to binding to increase Timeout Jit Edit -->
            <binding name="ServicesBinding"
                     textEncoding="utf-8"
                     closeTimeout="00:01:00"
                     openTimeout="00:10:00" 
                     receiveTimeout="01:00:00" 
                     sendTimeout="01:00:00"
                     allowCookies="false" 
                     bypassProxyOnLocal="false" 
                     hostNameComparisonMode="StrongWildcard"
                     maxBufferSize="655360" 
                     maxBufferPoolSize="524288" 
                     maxReceivedMessageSize="2147483648"
                     messageEncoding="Text" 
                     transferMode="Streamed"
                     useDefaultWebProxy="true">
              <readerQuotas 
                maxArrayLength="2000000" 
                maxStringContentLength="2000000"/>
            </binding>
          </basicHttpBinding>
        </bindings>
        <diagnostics>
          <messageLogging logMalformedMessages="true" logMessagesAtTransportLevel="true" />
        </diagnostics>
        <!-- Service EndPoint Address, Tally with Bindings above Jit Edit -->
        <services>
          <service name="WcfService1.Service1" behaviorConfiguration="metadataAndDebug">
            <endpoint address="" 
                      binding="basicHttpBinding"
                      bindingConfiguration="ServicesBinding" 
                      name="ServicesBinding" 
                      contract="WcfService1.IService1">
              <!-- Using Localhost system as DNS by default Jit Edit -->
              <identity>
                <dns value="localhost" />
              </identity>
            </endpoint>
            <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
            <host>
              <baseAddresses>
                <add baseAddress="http://localhost:50368/Service1.svc" />
              </baseAddresses>
            </host>
          </service>
        </services>
        <behaviors>
          <serviceBehaviors>
            <behavior name="metadataAndDebug">
              <!-- Jit Edit -->
              <dataContractSerializer maxItemsInObjectGraph="2147483647"/>
              <!-- To avoid disclosing metadata information, set the values below to false before deployment -->
              <serviceMetadata httpGetEnabled="true" httpsGetEnabled="true" httpGetUrl=""/>
              <!-- 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="false" httpHelpPageEnabled="true"/>     
            </behavior>
          </serviceBehaviors>
        </behaviors>
        <protocolMapping>
            <add binding="basicHttpsBinding" scheme="http" />
        </protocolMapping>    
        <serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="false" />
      </system.serviceModel>
      <system.webServer>
        <modules runAllManagedModulesForAllRequests="true"/>
        <!--
            To browse web app root directory during debugging, set the value below to true.
            Set to false before deployment to avoid disclosing web app folder information.
          -->
        <directoryBrowse enabled="true"/>
      </system.webServer>
    
    </configuration>

    and here's my app.config from client.

    <?xml version="1.0" encoding="utf-8" ?>
    <configuration>
      <startup>
        <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
      </startup>
      <system.serviceModel>
        <diagnostics>
          <messageLogging logMalformedMessages="true" logMessagesAtTransportLevel="true" />
        </diagnostics>
        <!-- Bindings Very Important Jit Edit -->
        <bindings>
          <basicHttpBinding>
            <binding name="ServicesBinding" maxReceivedMessageSize="2000000" />
          </basicHttpBinding>
        </bindings>
        <!-- Client EndPoint Address, Tally with Bindings above Jit Edit -->
        <client>
          <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
          <endpoint address="http://localhost:50368/Service1.svc" binding="basicHttpBinding"
              bindingConfiguration="ServicesBinding" contract="ServiceReference1.IService1"
              name="ServicesBinding" />
        </client>
      </system.serviceModel>
    </configuration>

    i don't see anything beyond this, both Bindings are same and using basichttpbinding and timeout params in web.config is completely set as suggested in Forums.

    Is there anything to add to web.config.

    Tuesday, February 3, 2015 6:09 AM
  • Hi,

    My problem was in c++ Dll not in WCFService which i was loading in WCF Service. As per this Link explanation, i was doing

    this

    char* pszReturn = new char[256];

    instead of this

    char* pszReturn = NULL;
    pszReturn = (char*)::CoTaskMemAlloc(ulSize);

    this was causing error in returning the value, and in result below exception was thrown.

    Content Type application/soap+xml; charset=utf-8 was sent to a service expectingtext/xml; charset=utf-8. The client and service bindings may be mismatched.

    Hope it helps somebody and Special Thanks for @

    Avatar of darnold924
    darnold924

    for leading me to this.

    Regards,

    Jithendra.

    • Marked as answer by Jithendra_hyd Tuesday, February 3, 2015 8:10 AM
    Tuesday, February 3, 2015 8:10 AM
  • darnold924

    for leading me to this.

    His eyes are open now and not shut! :)

    Tuesday, February 3, 2015 4:10 PM