Raghuveer
Raghuveer

Reputation: 2638

WCF Service Not working when try to connect to database

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?

Upvotes: 1

Views: 1608

Answers (2)

Raghuveer
Raghuveer

Reputation: 2638

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........

Upvotes: 2

SliverNinja - MSFT
SliverNinja - MSFT

Reputation: 31651

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>

Upvotes: 0

Related Questions