Click here to Skip to main content
15,881,172 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a wcf service that works fine for one call. I have tried several different things and I just can't get it to accept more than one call from the client. This is my first wcf service so any help would be great. Below is my code.

for service1.svc.cs

C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ServiceModel;
using System.Data.SqlClient;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Net;
using System.Net.NetworkInformation;
using System.Threading;
using System.Globalization;
using System.Timers;

namespace aim_wcf_service
{
    // NOTE: You can use the "Rename" command on the "Refactor" menu to change the class name "Service1" in code, svc and config file together.
    [ServiceBehavior(InstanceContextMode=InstanceContextMode.PerCall, ConcurrencyMode = ConcurrencyMode.Multiple)]
    public class NIM_Latency : IService1
    {
    
        #region IService1 Members

        public void submitData(Latency latency)
        {
            SqlConnection cs = new SqlConnection(@"Server=130-ASQL1-P-001.ocsd.LOCAL;Initial Catalog=AIM;User ID=user;Password=pass");

            cs.Open();

            SqlCommand insert = new SqlCommand(@"Insert into NIM_Latency (stationName, latency, stationIP) values ('" + latency.stationName + "', '" + latency.latency + "', '" + latency.stationip + "')", cs);
            insert.CommandType = CommandType.Text;
            insert.ExecuteNonQuery();
            cs.Close();

          
        }

        public void updateData(Latency latency)
        {
            SqlConnection cs = new SqlConnection(@"Server=130-ASQL1-P-001.ocsd.LOCAL;Initial Catalog=AIM;User ID=user;Password=pass");

            cs.Open();

            SqlCommand update = new SqlCommand(@"Update NIM_Latency set latency = '" + latency.latency + "' where stationName = '" + System.Environment.MachineName + "'", cs);
            update.CommandType = CommandType.Text;
            update.ExecuteNonQuery();
            cs.Close();
            
        }

        #endregion
    }
}


then for IService1.cs

C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.ServiceModel.Web;
using System.Text;

namespace aim_wcf_service
{
    // NOTE: You can use the "Rename" command on the "Refactor" menu to change the interface name "IService1" in both code and config file together.
    [ServiceContract]
    public interface IService1
    {
        [OperationContract]
        void submitData(Latency latency);
        [OperationContract]
        void updateData(Latency latency);
    }


    // Use a data contract as illustrated in the sample below to add composite types to service operations.
    [DataContract]
    public class Latency
    {
        [DataMember]
        public string stationName;
        [DataMember]
        public long latency;
        [DataMember]
        public string stationip;
    }
}


and my web.config

C#
<?xml version="1.0"?>
<configuration>

  <system.web>
    <compilation debug="true" targetFramework="4.0" />
    <customErrors mode ="Off">    
    </customErrors>
  </system.web>
  <system.serviceModel>
    <behaviors>
      <serviceBehaviors>
        <behavior>
          <!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment -->
          <serviceMetadata httpGetEnabled="true"/>
          <!-- 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"/>
        </behavior>
      </serviceBehaviors>
    </behaviors>
    <serviceHostingEnvironment multipleSiteBindingsEnabled="false" />
  </system.serviceModel>
 <system.webServer>
    <modules runAllManagedModulesForAllRequests="true"/>
  </system.webServer>
  
</configuration>


that was the web.config from the wcf service. Just to be safe here is the app.config from the client(windows service).

C#
<?xml version="1.0" encoding="utf-8"?>
<configuration>
    <system.serviceModel>
        <bindings>
            <basicHttpBinding>
                <binding name="BasicHttpBinding_IService1" />
            </basicHttpBinding>
        </bindings>
        <client>
            <endpoint address="http://localhost:3909/NIM_Latency.svc" binding="basicHttpBinding"
                bindingConfiguration="BasicHttpBinding_IService1" contract="ServiceReference1.IService1"
                name="BasicHttpBinding_IService1" />
        </client>
    </system.serviceModel>
  <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="System.Reactive" publicKeyToken="31bf3856ad364e35" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-1.1.11111.0" newVersion="1.1.11111.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="System.Reactive.Windows.Threading" publicKeyToken="31bf3856ad364e35" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-1.1.11111.0" newVersion="1.1.11111.0" />
      </dependentAssembly>
    </assemblyBinding>
  </runtime>
</configuration>


after debugging further, it throws the following error when the client calls the service the second time.

Could not find endpoint element with name 'BasicHttpBinding_IService1' and contract 'ServiceReference1.IService1' in the ServiceModel client configuration section. This might be because no configuration file was found for your application, or because no endpoint element matching this name could be found in the client element.
Posted
Updated 6-Jun-13 7:10am
v4
Comments
Can you post the web.config as well?
What type of client you are talking about? WCFTestClient or any other?
Dustin Prevatt 6-Jun-13 9:09am    
The client is a windows service
Dustin Prevatt 6-Jun-13 9:16am    
I am updating the question to include my web.config
Bernhard Hiller 6-Jun-13 2:41am    
What do you mean with "can't get it to accept more than one call"? What happens at the second call? Nothing? An error - what's the error message/stack trace? Other behavior?

Hi Dustin:

In your sqlConnection try to add this code Min Pool Size=0;Max Pool Size=10;. So in your case i believe that solution would be something like that

SqlConnection cs = new SqlConnection(@"Server=130-ASQL1-P-001.ocsd.LOCAL;Initial Catalog=AIM;User ID=user;Password=pass; Min Pool Size=0;Max Pool Size=10;");
 
Share this answer
 
Comments
Dustin Prevatt 6-Jun-13 9:16am    
I tried that but still no luck.
Dustin Prevatt 6-Jun-13 9:18am    
I have updated the question to include my web.config
Well in this case i thing should be tried with this in your service
[ServiceBehavior(ConcurrencyMode = ConcurrencyMode.Multiple)]

Also could you read more about ultiple concurrency in

http://msdn.microsoft.com/en-us/library/ms731193.aspx
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900