Microsoft Developer Network > Página principal de foros > Windows Communication Foundation > Multiple Services with one implementation class
Formular una preguntaFormular una pregunta
 

RespondidaMultiple Services with one implementation class

  • sábado, 04 de julio de 2009 15:17Etowah_man Medallas del usuarioMedallas del usuarioMedallas del usuarioMedallas del usuarioMedallas del usuario
     
    I have a two service contracts, call them IService1 and IService2 within the same file/namespace.

    I have one implementation class where I am trying to implement both of the services:

    public

     

    class Service1 : IService1, IService2

    {

     

    public string GetData(int value)

    {

     

    return string.Format("You entered: {0}", value);

    }
    ....

    I have added a second address/endpoint to my app.config file:

    <

     

    services>

    <

     

    service name="TestMultipleInterfaces.Service1" behaviorConfiguration="TestMultipleInterfaces.Service1Behavior">

    <

     

    host>

    <

     

    baseAddresses>

    <

     

    add baseAddress = "http://localhost:8731/Design_Time_Addresses/TestMultipleInterfaces/Service1/" />

    </

     

    baseAddresses>

    </

     

    host>

    <!--

     

    Service Endpoints -->

    <!--

     

    Unless fully qualified, address is relative to base address supplied above -->

    <

     

    endpoint address ="Rosey" binding="wsHttpBinding" contract="TestMultipleInterfaces.IService1">

    <

     

    identity>

    <

     

    dns value="localhost"/>

    </

     

    identity>

    </

     

    endpoint>

     

    <

     

    endpoint address ="TestManage" binding="wsHttpBinding" contract="TestMultipleInterfaces.IService2" >

    <

     

    identity>

    <

     

    dns value="localhost"/>

    </

     

    identity>

    </

     

    endpoint>

     

    <

     

    endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>

    </

     

    service>

    </

     

    services>

    What happens when I try to run this is that I get an error saying ' Cannot obtain Metadata from
    http://localhost:8731/Design_Time_Addresses/TestMultipleInterfaces/Service1/mex'

    I may be missing something simple here. Does this have to do with the addresses I have given my endpoints?

    Thanks!


    EM

Respuestas

Todas las respuestas

  • sábado, 04 de julio de 2009 20:46Stipe-Ivan Latkovic Medallas del usuarioMedallas del usuarioMedallas del usuarioMedallas del usuarioMedallas del usuario
     Tiene código
    When using mex bindings, you have to specify the serviceMetadata attribute. First you have to create a new service behavior:

    <behaviors>
      <serviceBehaviors>
        <behavior name="serviceBehavior">
          <serviceMetadata />
        </behavior>
      </serviceBehaviors>
    </behaviors>
    

    Then you have to assign the behavior to the service using the behaviorConfiguration attribute. 

    Did this help?

    Regards,
    John


  • sábado, 04 de julio de 2009 21:12Etowah_man Medallas del usuarioMedallas del usuarioMedallas del usuarioMedallas del usuarioMedallas del usuario
     

    Actually, that part is already in my config file, I just didn't include it in the above code. The code will work if I remove one of the interfaces and only implement my service class from one of the interfaces. When I add the other one though, thats when I get this error.

    Thanks!


    EM
  • domingo, 05 de julio de 2009 3:17Stipe-Ivan Latkovic Medallas del usuarioMedallas del usuarioMedallas del usuarioMedallas del usuarioMedallas del usuario
     RespondidaTiene código
    Try adding this to your service's behavior definition:
    <serviceDebug includeExceptionDetailInFaults="True" />
    

    Did it help in localizing the error? 

    Regards,
    John
    • Marcado como respuestaEtowah_man domingo, 05 de julio de 2009 21:15
    •  
  • domingo, 05 de julio de 2009 21:15Etowah_man Medallas del usuarioMedallas del usuarioMedallas del usuarioMedallas del usuarioMedallas del usuario
     
    Ah, good tip! Totally forgot about that.

    As I figured, it was something stupid.  I had operation names in my second service that were the same as in my first service, and that conflicted. I fixed it by giving the second service different operation names.

    Thanks!
    EM