2
votes

I added Wcf Service Library project to solution and it created 2 classes (Service1, IService1) and config file. Now I want to add that service to my Console project in the same solution. I click "Add Service Reference -> Discover" and it finds that service.

When I create Windows Class Library project and create there the same example as in just created Wcf Service Library project and then try to add it as reference to my Console project, so clicking on Discover doesn't return anything. Why?

What is the difference when I create Wcf Service Library project or Windows Class Library project and create there the same as in Wcf Service Library?

Edited

The Discover works only if the service is in Wcf Service Library. But once I move to other project (Console, Class Library) the Discover doesn't find it anymore. Why?

app.config

<?xml version="1.0" encoding="utf-8" ?>
<configuration>

  <system.web>
    <compilation debug="true" />
  </system.web>
  <!-- When deploying the service library project, the content of the config file must be added to the host's 
  app.config file. System.Configuration does not support config files for libraries. -->
  <system.serviceModel>
    <services>
      <service name="WcfServiceLibrary1.Service1">
        <host>
          <baseAddresses>
            <add baseAddress = "http://localhost:8732/Design_Time_Addresses/WcfServiceLibrary1/Service1/" />
          </baseAddresses>
        </host>
        <!-- Service Endpoints -->
        <!-- Unless fully qualified, address is relative to base address supplied above -->
        <endpoint address ="" binding="wsHttpBinding" contract="WcfServiceLibrary1.IService1">
          <!-- 
              Upon deployment, the following identity element should be removed or replaced to reflect the 
              identity under which the deployed service runs.  If removed, WCF will infer an appropriate identity 
              automatically.
          -->
          <identity>
            <dns value="localhost"/>
          </identity>
        </endpoint>
        <!-- Metadata Endpoints -->
        <!-- The Metadata Exchange endpoint is used by the service to describe itself to clients. --> 
        <!-- This endpoint does not use a secure binding and should be secured or removed before deployment -->
        <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
      </service>
    </services>
    <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>
  </system.serviceModel>

</configuration>

Service1.cs

namespace WcfServiceLibrary1
{
    // 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]
        string GetData(int value);

        [OperationContract]
        CompositeType GetDataUsingDataContract(CompositeType composite);

        // TODO: Add your service operations here
    }

    // Use a data contract as illustrated in the sample below to add composite types to service operations
    [DataContract]
    public class CompositeType
    {
        bool boolValue = true;
        string stringValue = "Hello ";

        [DataMember]
        public bool BoolValue
        {
            get { return boolValue; }
            set { boolValue = value; }
        }

        [DataMember]
        public string StringValue
        {
            get { return stringValue; }
            set { stringValue = value; }
        }
    }
}

IService.cs

namespace WcfServiceLibrary1
{
    // NOTE: You can use the "Rename" command on the "Refactor" menu to change the class name "Service1" in both code and config file together.
    public class Service1 : IService1
    {
        public string GetData(int value)
        {
            return string.Format("You entered: {0}", value);
        }

        public CompositeType GetDataUsingDataContract(CompositeType composite)
        {
            if (composite == null)
            {
                throw new ArgumentNullException("composite");
            }
            if (composite.BoolValue)
            {
                composite.StringValue += "Suffix";
            }
            return composite;
        }
    }
}
4
Not sure what you mean by Discover. Service library is a class library with some plumbing added. Know I built a WCF Service starting with Class Library and it works. Three projects. The Service (class), Service Host (console), and Service Client (console). The client needs the host running. Are you sure the service is running?paparazzo
the service is running. I run the service by running it from its bin/Debug directory and then trying to add Service Reference.theateist
Still broken? Please post the code where start the host.paparazzo
this will help you- tilr.blogspot.com/2014/06/…DevT

4 Answers

6
votes

After some checking I came to conclusion that only if you create WCF Service Library you can create client with Add Service Reference->Discover button without running the host explicitly and it will find the service.

If you create Class Library project that will have then your service files so you cannot create client with Add Service Reference->Discover if the service is not hosted(is not running). You should run the host and only after it put the address of service in Address bar and press Go

1
votes

Looks like WCF options shows up only when you create a project using wcf project template, if you have an existing project (class library) you could convert it by adding this in the first property group more discussion Here

In the first section, add the following line: {3D9AD99F-2412-4246-B90B-4EAA41C64699};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}

0
votes

turn on in project properties Wcf options start host

0
votes

I had the same problem. Go to Debug -> Start without debugging. This should start host and client applications. Then go to client and add service reference. In other words, the service has to be running