Solved

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

Posted on 2010-08-27
5
2,192 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
  • 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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

This article discusses the ASP.NET AJAX ModalPopupExtender control. In this article we will show how to use the ModalPopupExtender control, how to display/show/call the ASP.NET AJAX ModalPopupExtender control from javascript, how to show/display/cal…
In .NET 2.0, Microsoft introduced the Web Site.  This was the default way to create a web Project in Visual Studio 2005.  In Visual Studio 2008, the Web Application has been restored as the default web Project in Visual Studio/.NET 3.x The Web Si…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…

776 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