Solved

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

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

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

758 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now