Solved

ServiceHost only supports class service types. - Self host wcf service

Posted on 2010-08-27
5
2,256 Views
Last Modified: 2012-05-10
while self hosting wcf service with console app,
getting error : 'ServiceHost only supports class service types.'
on line
ServiceHost host = new ServiceHost(typeof(IService1));
ConsoleService
--------------
static void Main(string[] args)
        {
            ServiceHost host = new ServiceHost(typeof(IService1));

            host.Open();

            Console.WriteLine("Host Open... Enter to close ");
            Console.ReadLine();

            host.Close();

        }

Console Service App.Config
--------------------------
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
    <system.serviceModel>
        <behaviors>
            <serviceBehaviors>
                <behavior name="NewBehavior">
                    <serviceMetadata httpGetEnabled="true" />
                </behavior>
            </serviceBehaviors>
        </behaviors>
        <services>
            <service behaviorConfiguration="NewBehavior" name="WcfServiceLibrary4.Service1">
                <clear />
                <endpoint address="basic" binding="basicHttpBinding" contract="WcfServiceLibrary4.IService1"
                    listenUriMode="Explicit">
                    <identity>
                        <certificateReference storeName="My" storeLocation="LocalMachine"
                            x509FindType="FindBySubjectDistinguishedName" />
                    </identity>
                </endpoint>
                <endpoint address="ws" binding="ws2007HttpBinding" contract="WcfServiceLibrary4.IService1"
                    listenUriMode="Explicit">
                    <identity>
                        <certificateReference storeName="My" storeLocation="LocalMachine"
                            x509FindType="FindBySubjectDistinguishedName" />
                    </identity>
                </endpoint>
                <endpoint address="net.tcp://localhost:8731/IService1" binding="netTcpBinding"
                    bindingConfiguration="" contract="WcfServiceLibrary4.IService1" />
                <host>
                    <baseAddresses>
                        <add baseAddress="http://localhost:8731/IService1" />
                    </baseAddresses>
                </host>
            </service>
            <service name="NewServiceType">
                <clear />
                <endpoint address="net.pipe://localhost/IService1" binding="netNamedPipeBinding"
                    bindingConfiguration="" contract="WcfServiceLibrary4.IService1" />
            </service>
        </services>
    </system.serviceModel>
</configuration>

WcfServiceLibrary4 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="WcfServiceLibrary4.Service1" behaviorConfiguration="WcfServiceLibrary4.Service1Behavior">
        <host>
          <baseAddresses>
            <add baseAddress = "http://localhost:8731/Design_Time_Addresses/WcfServiceLibrary4/Service1/" />
          </baseAddresses>
        </host>
        <!-- Service Endpoints -->
        <!-- Unless fully qualified, address is relative to base address supplied above -->
        <endpoint address ="" binding="wsHttpBinding" contract="WcfServiceLibrary4.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 name="WcfServiceLibrary4.Service1Behavior">
          <!-- 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>

Open in new window

0
Comment
Question by:doramail05
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
5 Comments
 
LVL 3

Accepted Solution

by:
with earned 500 total points
ID: 33548736
IService1 is an interface.  ServiceHost doesn't want that, it wants the class that implements the interface.  Try this:

ServiceHost host = new ServiceHost(typeof(Service1));
0
 
LVL 1

Author Comment

by:doramail05
ID: 33549763
had this,

Cannot load the X.509 certificate identity specified in the configuration.
0
 
LVL 1

Author Comment

by:doramail05
ID: 33549799
then added this
<identity>
            <dns value="localhost" />
to app.config's endpoints,

but later had this :

There is already a listener on IP endpoint 0.0.0.0:8731.  Make sure that you are not trying to use this endpoint multiple times in your application and that there are no other applications listening on this endpoint.

0
 
LVL 3

Expert Comment

by:with
ID: 33551133
It looks like there is a configuration for named pipes, but ultimately it is using HTTPS.  Describe how you want to access this service so we can configure the correct binding and endpoint.
0
 
LVL 1

Expert Comment

by:Vee_Mod
ID: 33806361
doramail05,
The reason that you now have "0" open questions is that a variety of Cleanup Volunteers and Moderators have closed your questions for you - not because of any action that you took.

I am going to TEMPORARILY restore your ability to ask new questions but you need to understand clearly that it is your responsibility to manage the questions you post.

Please review the information below about what are the appropriate actions to take for your questions:

a) Respond to all Expert comments, even if it is to say "sorry, but that doesn't work". Allow the Experts 24 hours to reply. If you receive no further responses, either delete and repost the question or use the "Request Attention" option to ask the Moderators for assistance.

b) If you solved the question yourself, post your self-solution in a new comment, then close the question using the Accept as Solution option beside *your* comment. This will start the auto-close procedure.

c) If one or more Expert comments provided a solution you have already tested and confirmed, use the Accept as Solution or Accept Multiple Solutions options to award the points to a single Expert or split them accordingly.

d) If no Expert provided a solution or your question does not seem to be going anywhere, you may request deletion using the Delete Question link/button.

 
Vee_Mod
Experts-Exchange Moderator
0

Featured Post

SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
In this video, viewers are given an introduction to using the Windows 10 Snipping Tool, how to quickly locate it when it's needed and also how make it always available with a single click of a mouse button, by pinning it to the Desktop Task Bar. Int…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question