0

I have a windows service that hosts a WCF service. I have a client that consumes the service. The client does not recognize the ServiceReference1 even though I added it as a Service Reference.

I have been trying to fix this all day - I have read the code multiple times - I have used WCF before with no issues (in the same manner as this).

Interface

namespace ValidStateService
{
    [ServiceContract]
    public interface IValidStateWCFService
    {
        // Add two numbers
        [OperationContract(IsOneWay = false)]
        int AddNumbers(int numA, int numB);  

    }
}

Implementation of the Interface

namespace ValidStateService
{
    public class ValidStateWCFService : IValidStateWCFService
    {

        // Call the agent to add two numbers and return the result
        public int AddNumbers(int numA, int numB)
        {

            try
            {
                    return 20;  // Always return 20 for testing
            }
            catch (Exception ex)
            {
                return -1;
            }
        }    
    }
}

Windows Service App.config

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
    <startup> 
        <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
    </startup>
    <system.serviceModel>
        <behaviors>
            <serviceBehaviors>
                <behavior name="">
                    <serviceMetadata httpGetEnabled="true" httpsGetEnabled="true" />
                    <serviceDebug includeExceptionDetailInFaults="false" />
                </behavior>
            </serviceBehaviors>
        </behaviors>
        <services>
            <service name="ValidStateService.ValidStateWCFService">
                <endpoint address="" binding="basicHttpBinding" contract="ValidStateService.IValidStateWCFService">
                    <identity>
                        <dns value="localhost" />
                    </identity>
                </endpoint>
                <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
                <host>
                    <baseAddresses>
                        <add baseAddress="http://localhost:8732/ValidStateService/" />
                    </baseAddresses>
                </host>
            </service>
        </services>
    </system.serviceModel>
</configuration>

Now on a Winform i have added reference to the service but servicereference1 is not recognized. Code to add two numbers *Winform App.config*

private void buttonGetDataFromAgent_Click(object sender, EventArgs e)
{

    try
    {
        InstanceContext context = new InstanceContext(this);
        ServiceReference1.   // Winform App does not recognize this i.e no intellisense 

??????

Client App.config

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <startup>
    <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
  </startup>

  <system.serviceModel>
    <client>
      <endpoint address="http://localhost:8732/ValidStateService/"
        binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IValidStateWCFService"
        contract="ServiceReference1.IValidStateWCFService" name="BasicHttpBinding_IValidStateWCFService" />
    </client>
    <bindings>
      <basicHttpBinding>
        <binding name="BasicHttpBinding_IValidStateWCFService" />
      </basicHttpBinding>
    </bindings>
  </system.serviceModel>
</configuration>
Tim
  • 28,212
  • 8
  • 63
  • 76
user1438082
  • 2,740
  • 10
  • 48
  • 82
  • 2
    Have you tried adding `using ServiceReference1;` to your using directives? – Tim Sep 09 '13 at 02:40
  • yes - i don't understand whats going on. i have done this before many times on visual studio 2010 - now on 2012 - maybe an issue with this. i have created a standalone wcf client/server on 2012 and it worked fine – user1438082 Sep 09 '13 at 18:31
  • i started creating a brand new service and referencing it. I still cannot add the using servicereference1 - i have no idea whats wrong here. – user1438082 Sep 09 '13 at 19:11

0 Answers0