Microsoft Developer Network > Página Inicial dos Fóruns > Windows Communication Foundation > Multiple Services with one implementation class
Fazer uma PerguntaFazer uma Pergunta
 

RespondidoMultiple Services with one implementation class

  • sábado, 4 de julho de 2009 15:17Etowah_man Medalhas de usuárioMedalhas de usuárioMedalhas de usuárioMedalhas de usuárioMedalhas de usuário
     
    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

Respostas

Todas as Respostas

  • sábado, 4 de julho de 2009 20:46Stipe-Ivan Latkovic Medalhas de usuárioMedalhas de usuárioMedalhas de usuárioMedalhas de usuárioMedalhas de usuário
     Contém 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, 4 de julho de 2009 21:12Etowah_man Medalhas de usuárioMedalhas de usuárioMedalhas de usuárioMedalhas de usuárioMedalhas de usuário
     

    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, 5 de julho de 2009 3:17Stipe-Ivan Latkovic Medalhas de usuárioMedalhas de usuárioMedalhas de usuárioMedalhas de usuárioMedalhas de usuário
     RespondidoContém 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 RespostaEtowah_man domingo, 5 de julho de 2009 21:15
    •  
  • domingo, 5 de julho de 2009 21:15Etowah_man Medalhas de usuárioMedalhas de usuárioMedalhas de usuárioMedalhas de usuárioMedalhas de usuário
     
    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