Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WCF ERROR: The server did not provide a meaningful reply;

Tags:

wcf

please somebody can help me to find out what is happened. I have my WCF service which worked fine, and now suddenly I have this error:

The server did not provide a meaningful reply; this might be caused by a contract mismatch, a premature session shutdown or an internal server error

I must tell that it still works when I select some thousands of records, but when the data is huge I receive this error, although before it worked fine!

    private static string ConnString = "Server=127.0.0.1; Port=5432; Database=DBname; User Id=UName; Password=MyPassword;"
    DataTable myDT = new DataTable();

                NpgsqlConnection myAccessConn = new NpgsqlConnection(ConnString);
                myAccessConn.Open();
        string query = "SELECT * FROM Twitter";

                NpgsqlDataAdapter myDataAdapter = new NpgsqlDataAdapter(query, myAccessConn);

                myDataAdapter.Fill(myDT);
                foreach (DataRow dr in myDT.Rows)
                {
   **WHEN I HAVE TOO MANY RECORDS IT STOPS HERE**
        ...

web.config

<configuration>
    <system.web>
        <compilation debug="false" targetFramework="4.0" />
      <httpRuntime maxRequestLength="2147483647" executionTimeout="100000" />
    </system.web>
  <system.diagnostics>
    <trace autoflush="true" />
    <sources>
      <source name="System.ServiceModel"
              switchValue="Information, ActivityTracing"
              propagateActivity="true">
        <listeners>
          <add name="traceListener" type="System.Diagnostics.XmlWriterTraceListener" initializeData="Traces4.svclog"/>
        </listeners>
      </source>
    </sources>
  </system.diagnostics>
  <system.serviceModel>
        <bindings>
            <basicHttpBinding>
                <binding name="BasicHttpBinding_IDBService" closeTimeout="00:30:00"
                    openTimeout="00:30:00" receiveTimeout="00:30:00" sendTimeout="00:30:00"
                    allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
                    maxBufferSize="2147483647" maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647"
                    messageEncoding="Text" textEncoding="utf-8" transferMode="Streamed"
                    useDefaultWebProxy="true">
                    <readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647" maxArrayLength="2147483647"
                        maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />
                    <security mode="None">
                        <transport clientCredentialType="None" proxyCredentialType="None"
                            realm="" />
                        <message clientCredentialType="UserName" algorithmSuite="Default" />
                    </security>
                </binding>
            </basicHttpBinding>
        </bindings>
    <client>
      <endpoint address="" binding="basicHttpBinding" 
          bindingConfiguration="BasicHttpBinding_IDBService" contract="DBServiceReference.IDBService"
          name="BasicHttpBinding_IDBService" />
    </client>
        <behaviors>
            <serviceBehaviors>
                <behavior name="">
                  <serviceMetadata httpGetEnabled="true" />
                  <serviceDebug includeExceptionDetailInFaults="true" />
                  <dataContractSerializer maxItemsInObjectGraph="2147483646" />
                </behavior>
            </serviceBehaviors>
        </behaviors>
        <serviceHostingEnvironment aspNetCompatibilityEnabled="false" multipleSiteBindingsEnabled="true" />
    </system.serviceModel>
</configuration>

client config (Edited)

<configuration>
        <system.serviceModel>
            <bindings>
                <basicHttpBinding>
                    <binding name="BasicHttpBinding_IRouteService" maxBufferSize="2147483647"
                        maxReceivedMessageSize="2147483647">
                        <security mode="None" />
                    </binding>
                    <binding name="BasicHttpBinding_IDBService" closeTimeout="00:30:00"
                        openTimeout="00:30:00" receiveTimeout="00:30:00" sendTimeout="00:30:00"
                        maxBufferSize="2147483647" maxReceivedMessageSize="2147483647"
                        transferMode="Buffered" >

                        <security mode="None" />
                    </binding>
                </basicHttpBinding>
                <customBinding>
                    <binding name="CustomBinding_IRouteService">
                        <binaryMessageEncoding />
                        <httpTransport maxReceivedMessageSize="2147483647"
                            maxBufferSize="2147483647" />
                    </binding>
                </customBinding>
            </bindings>

            <client>
                <endpoint address="http://dev.virtualearth.net/webservices/v1/routeservice/routeservice.svc"
                    binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IRouteService"
                    contract="BingRoutingService.IRouteService" name="BasicHttpBinding_IRouteService" />
                <endpoint address="http://dev.virtualearth.net/webservices/v1/routeservice/routeservice.svc/binaryHttp"
                    binding="customBinding" bindingConfiguration="CustomBinding_IRouteService"
                    contract="BingRoutingService.IRouteService" name="CustomBinding_IRouteService" />
                <endpoint address="" binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IDBService"
                    contract="DBServiceReference.IDBService" name="BasicHttpBinding_IDBService" />
            </client>
        </system.serviceModel>
    </configuration>

In my file scvlog I don' t get any exception! I don't have any other idea what else I can do for understand where is the problem. Please somebody help me!!!

like image 508
Aliya Avatar asked Apr 23 '13 15:04

Aliya


2 Answers

A different answer, just in case anyone arrives here as I did looking for a general answer to the question.

It seems that the DataContractSerializer that does the donkey-work is incredibly finicky, but doesn't always pass the real error to the client. The server process dies straight after the failure - hence no error can be found. In my case the problem was an enum that was used as flags, but not decorated with the [Flags] attribute (picky or what!).

To solve it I created an instance of the serializer and inspected the error in the debugger; here's a code snippet since I have it to hand.

EDIT: In response to request in comments ...

Amended the code snippet to show the helper method I now use. Much the same as before, but in a handy generic wrapper.

public static T CheckCanSerialize<T>(this T returnValue) {
    var lDCS = new System.Runtime.Serialization.DataContractSerializer(typeof(T));

    Byte[] lBytes;
    using (var lMem1 = new IO.MemoryStream()) {
        lDCS.WriteObject(lMem1, returnValue);
        lBytes = lMem1.ToArray();
    }

    T lResult;
    using (var lMem2 = new IO.MemoryStream(lBytes)) {
        lResult = (T)lDCS.ReadObject(lMem2);
    }

    return lResult;
}

And to use this, instead of returning an object, return the object after calling the helper method, so

public MyDodgyObject MyService() {
    ... do lots of work ...
    return myResult;
}

becomes

public MyDodgyObject MyService() {
    ... do lots of work ...
    return CheckCanSerialize(myResult);
}

Any errors in serialization are then thrown before the service stops paying attention, and so can be analysed in the debugger.

Note; I wouldn't recommend leaving the call in production code, it has the overhead of serializing and deserializing the object, without any real benefit once the code is debugged.

Hope this helps someone - I've wasted about 3 hours trying to track it down.

like image 92
Richard Petheram Avatar answered Nov 18 '22 03:11

Richard Petheram


I don't know if it's really can be an answer, but I have tried to change in web.config from <security mode="None" /> to <security mode="Transport" /> and It worked!!!

I'd want to pay attention that this part should be changed only in web.config and in client configuration remains <security mode="None" />, because with Transport in both It doesn't work!

So after that, I decided to try to come back again to None security and It worked for some minutes and then stopped again, and it came back the error:

The server did not provide a meaningful reply; this might be caused by a contract mismatch, a premature session shutdown or an internal server error

So It seems that the solution in my case is to set in web.config

security mode to Transport

like image 8
Aliya Avatar answered Nov 18 '22 02:11

Aliya