1

I created a WCF service to communicate with database, first I created a sample Helloworld! method it's working fine

but when I try to call the actual methods it's giving following exception

An error occurred while receiving the HTTP response to http://10.11.32.211:87/Service.svc. This could be due to the service endpoint binding not using the HTTP protocol.

In the browser

An existing connection was forcibly closed by the remote host

My web.config file

<configuration>
<system.web>
<compilation debug="true" targetFramework="4.0"/>
</system.web>

<!--<system.serviceModel>
<behaviors>
  <serviceBehaviors>
    <behavior name="">
      <serviceMetadata httpGetEnabled="true"/>
      <serviceDebug includeExceptionDetailInFaults="true"/>
    </behavior>
  </serviceBehaviors>
</behaviors>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true"/>
</system.serviceModel>-->

<system.serviceModel>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true"/>
<services>
  <service behaviorConfiguration="ServiceBehavior" name="Service">
    <endpoint address="" binding="basicHttpBinding" contract="IService">
      <identity>
        <dns value="localhost"/>
      </identity>
    </endpoint>
    <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
  </service>
  </services>
  <behaviors>
   <serviceBehaviors>
     <behavior name="ServiceBehavior">
      <serviceMetadata httpGetEnabled="true"/>
      <serviceDebug includeExceptionDetailInFaults="true"/>
      <dataContractSerializer maxItemsInObjectGraph="2147483646"/>
       <serviceThrottling maxConcurrentCalls="3000" maxConcurrentSessions="3000" maxConcurrentInstances="3000"/>
     </behavior>
    </serviceBehaviors>
  </behaviors>
 </system.serviceModel>
 </configuration>

I go through these links but it didn't worked MSDN LINK1

Edit

Actually what I am doing with this service is to execute a stored procedure on the server

using (con = new SqlConnection(connectionString))
        {
            using (cmd = new SqlCommand(selectStatement, con) { CommandType = CommandType.StoredProcedure })
            {
                adapter = new SqlDataAdapter(cmd);
                table = new DataTable();
                adapter.Fill(table);
                return table;
            }
        }

I am able to call the same stored procedure from different website manually but not using this service....

What is it? and why this is coming?

Cœur
  • 37,241
  • 25
  • 195
  • 267
Raghuveer
  • 2,630
  • 3
  • 29
  • 59
  • Config for both server and client are needed. (Just the services part of the graph) – Mark M May 30 '12 at 12:36
  • @MarkM this service is working fine when i try to call a `helloworld` method which will take a string input and returns a string – Raghuveer May 30 '12 at 12:43
  • @MarkM can you share a link or some code for server and client configuration – Raghuveer May 30 '12 at 12:45
  • 3
    Use a tool like [Fiddler](http://www.fiddler2.com/fiddler2/version.asp) and/or enable [WCF Tracing](http://msdn.microsoft.com/en-us/library/ms733025.aspx) to find out what's going wrong. This can be caused by many things, for example an incorrect query (does it run fine in SSMS?), wrong permissions (is the app pool user allowed to connect?), broken query string (is the database accessible?), too much data (see answer by SliverNinja), or an incorrect binding at the client. Please debug first. – CodeCaster May 30 '12 at 13:35
  • 1
    If you have a service method already working follow CodeCaster's suggestions. Unless you've set up another endpoint for the malfunctioning call it's probably not a configuration issue. – Mark M May 30 '12 at 13:41
  • @MarkM Hey [this](http://stackoverflow.com/a/42332/1196411) solved my problem – Raghuveer May 31 '12 at 06:23

2 Answers2

2

i found the answer for this here, we just need to instantiate the datatable with a specified name in its constructor

like

DataTable dt = new DataTable("TableName");

I don't know why this gives error but this solved the issue........

Community
  • 1
  • 1
Raghuveer
  • 2,630
  • 3
  • 29
  • 59
0

Try increasing the send or receive timeout and assigning proper readerQuotas for basicHttpBinding.

  <bindings>
    <basicHttpBinding>
      <binding  maxBufferSize="5000000" maxBufferPoolSize="524288" maxReceivedMessageSize="5000000" receiveTimeout="00:10:00" sendTimeout="00:10:00" >
        <readerQuotas maxDepth="32" maxStringContentLength="80192" maxArrayLength="50000000" maxBytesPerRead="4096" maxNameTableCharCount="16384"/>
      </binding>
    </basicHttpBinding>
  </bindings>
Raghuveer
  • 2,630
  • 3
  • 29
  • 59
SliverNinja - MSFT
  • 31,051
  • 11
  • 110
  • 173
  • Did you try [this approach](http://stackoverflow.com/q/7209823/175679)? This is often a sign of returning too much data. Try reducing the data size to a single record instead of all records from your DB to verify. – SliverNinja - MSFT May 30 '12 at 13:27
  • 1
    Thanks actually i do have the same problem, just now i checked with the insert sp its working(its storing record in db) but showing error in client side – Raghuveer May 30 '12 at 13:34
  • Thanks for sharing back your solution (*giving the `DataTable` a name*)! – SliverNinja - MSFT May 31 '12 at 12:27