none
Comparação de WS com WCF COM+

    Pergunta

  • Olá Pessoal,

    Estou testando o tempo de resposta de serviços utilizando WS, WCF e COM+.
    Porem o resultado está estranho, a comparação esta correta?

    Estrutura de retorno:
        [Serializable()]
        public class FakeEntity
        {
            public int Id { get; set; }
            public string Description { get; set; }
            public DateTime CreatedDate { get; set; }
            public double Value { get; set; }
        }


    Método que gera um array desta estrutura:
            public static FakeEntity[] GetList(int registries, int descriptionSize)
            {
                List<FakeEntity> result = new List<FakeEntity>(registries);
                for (int i = 0; i < registries; i++)
                {
                    FakeEntity instance = new FakeEntity()
                    {
                        Id = i,
                        Description = new string('X', descriptionSize),
                        CreatedDate = DateTime.Now,
                        Value = new Random().NextDouble()
                    };

                    result.Add(instance);
                }

                return result.ToArray();
            }


    Métodos de teste do cliente em WinForms:
            private void WriteMessage(string type, DateTime start, DateTime end, int registries, int descriptionSize)
            {
                TimeSpan span = end.Subtract(start);
                txtMessage.Text = string.Format("{0} - {4} - Registries: {1} - Description Size: {2} - Time:{5}:{6}:{7}.{8}\r\n{3}", DateTime.Now, registries, descriptionSize, txtMessage.Text, type, span.Hours, span.Minutes, span.Seconds, span.Milliseconds);
            }

            private void btnWS_Click(object sender, EventArgs e)
            {
                try
                {
                    int registries = Convert.ToInt32(txtRegistries.Text);
                    int descriptionSize = Convert.ToInt32(txtDescriptionSize.Text);

                    DateTime start = DateTime.Now;
                    using (TesteServicoWS.FakeWSServiceSoapClient client = new TesteServico.Client.TesteServicoWS.FakeWSServiceSoapClient())
                    {
                        TesteServicoWS.FakeEntity[] list = client.GetList(registries, descriptionSize);
                    }
                    DateTime end = DateTime.Now;

                    WriteMessage("WS", start, end, registries, descriptionSize);
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.ToString());
                }
            }

            private void btnWCF_Click(object sender, EventArgs e)
            {
                try
                {
                    int registries = Convert.ToInt32(txtRegistries.Text);
                    int descriptionSize = Convert.ToInt32(txtDescriptionSize.Text);

                    DateTime start = DateTime.Now;
                    using (TesteServicoWCF.FakeServiceClient client = new TesteServico.Client.TesteServicoWCF.FakeServiceClient())
                    {
                        FakeEntity[] list = client.GetList(registries, descriptionSize);
                    }
                    DateTime end = DateTime.Now;

                    WriteMessage("WCF", start, end, registries, descriptionSize);
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.ToString());
                }
            }

            private void btnCOM_Click(object sender, EventArgs e)
            {
                try
                {
                    int registries = Convert.ToInt32(txtRegistries.Text);
                    int descriptionSize = Convert.ToInt32(txtDescriptionSize.Text);

                    DateTime start = DateTime.Now;
                    TesteServico.COM.FakeCOM client = new TesteServico.COM.FakeCOM();
                    FakeEntity[] list = client.GetList(registries, descriptionSize);
                    client = null;
                    DateTime end = DateTime.Now;

                    WriteMessage("COM", start, end, registries, descriptionSize);
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.ToString());
                }
            }

            private void btnWSOLD_Click(object sender, EventArgs e)
            {
                try
                {
                    int registries = Convert.ToInt32(txtRegistries.Text);
                    int descriptionSize = Convert.ToInt32(txtDescriptionSize.Text);

                    DateTime start = DateTime.Now;
                    using (TesteServicoOLD.FakeWSService client = new TesteServico.Client.TesteServicoOLD.FakeWSService())
                    {
                        TesteServicoOLD.FakeEntity[] list = client.GetList(registries, descriptionSize);
                    }
                    DateTime end = DateTime.Now;

                    WriteMessage("WS OLD", start, end, registries, descriptionSize);
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.ToString());
                }
            }


    Config WCF:
     <system.serviceModel>

        <services>
       <service behaviorConfiguration="TesteServico.WCF.Service1Behavior" name="TesteServico.WCF.FakeWCFService">
            <endpoint address=""
                      binding="wsHttpBinding"
                      contract="TesteServico.WCF.IFakeService">
         <identity>
          <dns value="localhost"/>
         </identity>
        </endpoint>
        
            <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
          </service>
      </services>


        <behaviors>
       <serviceBehaviors>
        <behavior name="TesteServico.WCF.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>

    Config do Cliente:
        <system.serviceModel>
            <bindings>
             
                <basicHttpBinding>
                    <binding name="FakeWSServiceSoap"
                             maxReceivedMessageSize="999999999"
                             messageEncoding="Text">
                        <security mode="None" />
                    </binding>
                </basicHttpBinding>
             
                <wsHttpBinding>
                    <binding name="WSHttpBinding_IFakeService"
                             maxReceivedMessageSize="999999999"
                             messageEncoding="Text" >
                        <security mode="Message" />
                    </binding>
                </wsHttpBinding>
             
            </bindings>
         
            <client>
                <endpoint address="http://localhost:1898/FakeWSService.asmx"
                    binding="basicHttpBinding" bindingConfiguration="FakeWSServiceSoap"
                    contract="TesteServicoWS.FakeWSServiceSoap" name="FakeWSServiceSoap" />
             
                <endpoint address="http://localhost:1918/FakeWCFService.svc"
                    binding="wsHttpBinding" bindingConfiguration="WSHttpBinding_IFakeService"
                    contract="TesteServicoWCF.IFakeService" name="WSHttpBinding_IFakeService">
                </endpoint>
            </client>
        </system.serviceModel>

    quinta-feira, 5 de novembro de 2009 17:57

Respostas

Todas as Respostas

  • Boas Azize,

    Em uma olhada superficial, você tem que levar em consideração as features, por exemplo, comparar WCF com WSHttpBinding vs. ASMX puro, então provavelmente o ganho não será significativo, porque por padrão, esse binding já traz uma série de features habilitadas.

    Uma boa comparação é esse que a Microsoft fez: http://msdn.microsoft.com/en-us/library/bb310550.aspx.
    http://www.israelaece.com
    quinta-feira, 5 de novembro de 2009 18:19
    Moderador
  • Olá Israel,

    Obrigado pela resposta. Eu já tinha visto esta avaliação, por isso mesmo resolvi testar na prática.
    Veja os resultados pelo programa que eu fiz.

    O COM+ tem práticamente o mesmo desempenho que o WS puro.
    E o WCF é o pior deles, tudo bem, está utilizando o WSHttpBinding, e não o BasicHttpBinding, que eu acredito que seria melhor.

    Mas eu acreditava que o COM+ iria se sair muito melhor do que qualquer um deles. E na verdade esta no mesmo nível que o WS.
    quinta-feira, 5 de novembro de 2009 20:27
  • Ops, esqueci de colar o resultado.

    05/11/2009 18:16:17 - COM - Registries: 1000 - Description Size: 100 - Time:0:0:0.46
    05/11/2009 18:16:15 - COM - Registries: 1000 - Description Size: 100 - Time:0:0:0.46
    05/11/2009 18:16:14 - COM - Registries: 1000 - Description Size: 100 - Time:0:0:0.31
    05/11/2009 18:16:13 - COM - Registries: 1000 - Description Size: 100 - Time:0:0:0.31
    05/11/2009 18:16:11 - COM - Registries: 1000 - Description Size: 100 - Time:0:0:0.31
    05/11/2009 18:16:10 - COM - Registries: 1000 - Description Size: 100 - Time:0:0:0.46
    05/11/2009 18:16:09 - COM - Registries: 1000 - Description Size: 100 - Time:0:0:0.31
    05/11/2009 18:16:07 - COM - Registries: 1000 - Description Size: 100 - Time:0:0:0.46
    05/11/2009 18:16:06 - COM - Registries: 1000 - Description Size: 100 - Time:0:0:0.31
    05/11/2009 18:16:04 - COM - Registries: 1000 - Description Size: 100 - Time:0:0:0.31
    05/11/2009 18:16:03 - COM - Registries: 1000 - Description Size: 100 - Time:0:0:0.31
    05/11/2009 18:16:01 - COM - Registries: 1000 - Description Size: 100 - Time:0:0:0.46
    05/11/2009 18:16:00 - COM - Registries: 1000 - Description Size: 100 - Time:0:0:0.46
    05/11/2009 18:15:59 - COM - Registries: 1000 - Description Size: 100 - Time:0:0:0.46
    05/11/2009 18:15:58 - COM - Registries: 1000 - Description Size: 100 - Time:0:0:0.46
    05/11/2009 18:15:57 - COM - Registries: 1000 - Description Size: 100 - Time:0:0:0.46
    05/11/2009 18:15:56 - COM - Registries: 1000 - Description Size: 100 - Time:0:0:0.46
    05/11/2009 18:15:55 - COM - Registries: 1000 - Description Size: 100 - Time:0:0:0.46
    05/11/2009 18:15:54 - COM - Registries: 1000 - Description Size: 100 - Time:0:0:0.31
    05/11/2009 18:15:53 - COM - Registries: 1000 - Description Size: 100 - Time:0:0:0.31
    05/11/2009 18:15:50 - COM - Registries: 1000 - Description Size: 100 - Time:0:0:0.46
    05/11/2009 18:15:49 - COM - Registries: 1000 - Description Size: 100 - Time:0:0:0.359
    05/11/2009 18:15:37 - WS OLD - Registries: 1000 - Description Size: 100 - Time:0:0:0.46
    05/11/2009 18:15:34 - WS OLD - Registries: 1000 - Description Size: 100 - Time:0:0:0.46
    05/11/2009 18:15:33 - WS OLD - Registries: 1000 - Description Size: 100 - Time:0:0:0.46
    05/11/2009 18:15:32 - WS OLD - Registries: 1000 - Description Size: 100 - Time:0:0:0.46
    05/11/2009 18:15:31 - WS OLD - Registries: 1000 - Description Size: 100 - Time:0:0:0.31
    05/11/2009 18:15:30 - WS OLD - Registries: 1000 - Description Size: 100 - Time:0:0:0.62
    05/11/2009 18:15:29 - WS OLD - Registries: 1000 - Description Size: 100 - Time:0:0:0.62
    05/11/2009 18:15:28 - WS OLD - Registries: 1000 - Description Size: 100 - Time:0:0:0.46
    05/11/2009 18:15:27 - WS OLD - Registries: 1000 - Description Size: 100 - Time:0:0:0.46
    05/11/2009 18:15:26 - WS OLD - Registries: 1000 - Description Size: 100 - Time:0:0:0.46
    05/11/2009 18:15:25 - WS OLD - Registries: 1000 - Description Size: 100 - Time:0:0:0.46
    05/11/2009 18:15:24 - WS OLD - Registries: 1000 - Description Size: 100 - Time:0:0:0.46
    05/11/2009 18:15:23 - WS OLD - Registries: 1000 - Description Size: 100 - Time:0:0:0.62
    05/11/2009 18:15:22 - WS OLD - Registries: 1000 - Description Size: 100 - Time:0:0:0.46
    05/11/2009 18:15:21 - WS OLD - Registries: 1000 - Description Size: 100 - Time:0:0:0.46
    05/11/2009 18:15:20 - WS OLD - Registries: 1000 - Description Size: 100 - Time:0:0:0.46
    05/11/2009 18:15:19 - WS OLD - Registries: 1000 - Description Size: 100 - Time:0:0:0.62
    05/11/2009 18:15:17 - WS OLD - Registries: 1000 - Description Size: 100 - Time:0:0:0.46
    05/11/2009 18:15:16 - WS OLD - Registries: 1000 - Description Size: 100 - Time:0:0:0.31
    05/11/2009 18:15:15 - WS OLD - Registries: 1000 - Description Size: 100 - Time:0:0:0.46
    05/11/2009 18:15:14 - WS OLD - Registries: 1000 - Description Size: 100 - Time:0:0:0.375
    05/11/2009 18:15:05 - WCF - Registries: 1000 - Description Size: 100 - Time:0:0:0.375
    05/11/2009 18:15:04 - WCF - Registries: 1000 - Description Size: 100 - Time:0:0:0.265
    05/11/2009 18:15:03 - WCF - Registries: 1000 - Description Size: 100 - Time:0:0:0.250
    05/11/2009 18:15:02 - WCF - Registries: 1000 - Description Size: 100 - Time:0:0:0.281
    05/11/2009 18:15:01 - WCF - Registries: 1000 - Description Size: 100 - Time:0:0:0.234
    05/11/2009 18:15:00 - WCF - Registries: 1000 - Description Size: 100 - Time:0:0:0.265
    05/11/2009 18:14:59 - WCF - Registries: 1000 - Description Size: 100 - Time:0:0:0.265
    05/11/2009 18:14:56 - WCF - Registries: 1000 - Description Size: 100 - Time:0:0:0.250
    05/11/2009 18:14:54 - WCF - Registries: 1000 - Description Size: 100 - Time:0:0:0.250
    05/11/2009 18:14:51 - WCF - Registries: 1000 - Description Size: 100 - Time:0:0:0.281
    05/11/2009 18:14:50 - WCF - Registries: 1000 - Description Size: 100 - Time:0:0:0.265
    05/11/2009 18:14:49 - WCF - Registries: 1000 - Description Size: 100 - Time:0:0:0.265
    05/11/2009 18:14:48 - WCF - Registries: 1000 - Description Size: 100 - Time:0:0:0.250
    05/11/2009 18:14:47 - WCF - Registries: 1000 - Description Size: 100 - Time:0:0:0.265
    05/11/2009 18:14:46 - WCF - Registries: 1000 - Description Size: 100 - Time:0:0:0.281
    05/11/2009 18:14:44 - WCF - Registries: 1000 - Description Size: 100 - Time:0:0:0.265
    05/11/2009 18:14:43 - WCF - Registries: 1000 - Description Size: 100 - Time:0:0:0.281
    05/11/2009 18:14:41 - WCF - Registries: 1000 - Description Size: 100 - Time:0:0:0.265
    05/11/2009 18:14:37 - WCF - Registries: 1000 - Description Size: 100 - Time:0:0:1.781
    quinta-feira, 5 de novembro de 2009 20:29
  • Boas Azize,

    Mas acredito que na comparação, você deveria desligar a segurança, pois os outros não possuem.

                <wsHttpBinding>
                    <binding name="WSHttpBinding_IFakeService"
                             maxReceivedMessageSize="999999999"
                             messageEncoding="Text" >
                        <security mode="None" />
                    </binding>
                </wsHttpBinding>

    Outra coisa, seria você comparar a performance de WCF vs. COM+, mas utilizando o binding NetTcpBinding, que é a forma de comunicação do COM+, e pode ser muito mais rápido que HTTP, pois não tem o overhead do protocolo e da serialização XML.
    http://www.israelaece.com
    sexta-feira, 6 de novembro de 2009 00:22
    Moderador
  • Olá Israel,

    Quando eu altero a configuração para None, ele gera a aseguinte exception:

    System.ServiceModel.CommunicationException: The server did not provide a meaningful reply; this might be caused by a contract mismatch, a premature session shutdown or an internal server error.

    sexta-feira, 6 de novembro de 2009 13:55
  • Boas Azize,

    Você tem que colocar a mesma configuração do lado do cliente, ou simplesmente refazer a referencia.
    http://www.israelaece.com
    sexta-feira, 6 de novembro de 2009 15:07
    Moderador
  • Desculpe, mas eu não entendi muito bem.

    Eu tenho a seguinte configuração no servidor onde roda o WCF no IIS:

     <system.serviceModel>
      <services>
       <service behaviorConfiguration="TesteServico.WCF.Service1Behavior" name="TesteServico.WCF.FakeWCFService">
            <endpoint address=""
                      binding="wsHttpBinding"
                      contract="TesteServico.WCF.IFakeService">
        </endpoint>    
            <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
          </service>
      </services>
        <behaviors>
       <serviceBehaviors>
        <behavior name="TesteServico.WCF.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>


    E tenho a seguinte configuração no cliente, rodando em outra máquina:
        <system.serviceModel>
            <bindings>
                <basicHttpBinding>
                    <binding name="FakeWSServiceSoap" maxReceivedMessageSize="999999999"
                        messageEncoding="Text">
                        <security mode="None" />
                    </binding>
                </basicHttpBinding>
             
                <wsHttpBinding>
                    <binding name="WSHttpBinding_IFakeService" maxReceivedMessageSize="999999999"
                        messageEncoding="Text">
                        <security mode="None">
                            <transport realm="" />
                        </security>
                    </binding>
                </wsHttpBinding>
            </bindings>
         
            <client>
                <endpoint address="http://localhost:1898/FakeWSService.asmx"
                    binding="basicHttpBinding" bindingConfiguration="FakeWSServiceSoap"
                    contract="TesteServicoWS.FakeWSServiceSoap" name="FakeWSServiceSoap" />
                <endpoint address="http://localhost:1918/FakeWCFService.svc"
                    binding="wsHttpBinding" bindingConfiguration="WSHttpBinding_IFakeService"
                    contract="TesteServicoWCF.IFakeService" name="WSHttpBinding_IFakeService">
                    <identity>
                        <userPrincipalName value="XXXXXXXXXXXXXXX" />
                    </identity>
                </endpoint>
            </client>
        </system.serviceModel>


    Porem continua gerando a mesma exception.
    Eu já fiz o update da referência mas não resolveu.

    Qual o passo a passo que eu devo fazer para isso funcionar?

    sexta-feira, 6 de novembro de 2009 15:58
  • Boas Azize,

    Remova esse elemento:

    <identity>
        <userPrincipalName value="XXXXXXXXXXXXXXX" />
    </identity>
    http://www.israelaece.com
    sexta-feira, 6 de novembro de 2009 16:08
    Moderador