wcf etiketine sahip kayıtlar gösteriliyor. Tüm kayıtları göster
wcf etiketine sahip kayıtlar gösteriliyor. Tüm kayıtları göster

16 Ağustos 2013 Cuma

WCF Servislerinde Unity Kullanımı

WCF servislerinizde Unity veya farklı bir Dependency Injection Framework’u kullanmak istiyorsanız aşağıdaki makale oldukça yardımcı.
Kendimize özel ServiceHostFactory oluşturup register işlemlerini istediğimiz gibi yapabiliyoruz.
 
 
Dikkat edilmesi gereken önemli bir not:
** WcfHostClient.exe üzerinden host işlemi yapıyorsanız (development ortamında) kendinize özel ServiceHostFactory’i kullanamıyorsunuz. Bunu aşmak için WebHost isimli bir proje yaratın ve svc dosyanızı yaratın.
Svc dosyada aşağıdaki gibi Factory tanımı yapın. Bu projeyi hem development ortamında, hem de devreye alımlarda kullanabilirsiniz.
 
<%@ ServiceHost Service="Service.Wcf.Service1" Factory="Service.Wcf.MyServiceHostFactory"%>
 
Serkan

3 Ağustos 2012 Cuma

IIS'e WCF Servis Deploy'unda BaseAddress

Selamlar,

Bildiğiniz gibi WCF servislerini farklı ortamlarda host edebilirsiniz.
Biz şirket içinde yazdığımız wcf servisleri genelde IIS sunucularında yayınlıyoruz.
Hemen hemen her devreye alımda da endpoint’lerin URI’ları konusunda sorunlar yaşıyoruz J

Burada bilinmesi ve dikkat edilmesi gereken en önemli nokta; IIS servisin svc dosyasını base olarak kabul etmektedir.
Dolayısıyla web.config dosyasına baseaddress eklememeliyiz.
Örnek servis ve client configleri ile konu daha iyi anlaşılacaktır.

Hem netTcp hem de basicHttp binding destekleyen bir servisimiz olsun.
IIS’te basicHttp için 8018, netTcp için 8019 portlarını ayarladık. Svc dosyamızın ismi DistributedService.Wcf.ScheduledJobsService.svc şeklinde ve herhangi bir sub folder’ın altında değil.
Birden fazla endPoint tanımladığımız için bunların relative adreslerini de belirtmemiz gerekiyor. netTcp için address kısmına netTcpAdres diye bir giriş yaptım. Servis referans olarak eklenebilmesi için mexTcpBinding eklendi ve ona da özel bir adres atandı (mexTcpAdres).

<system.serviceModel>
    <services>
      <service behaviorConfiguration="Basic_Service_Behavior" name="DistributedService.Wcf.ScheduledJobsService">
        <endpoint address="netTcpAdres" binding="netTcpBinding" bindingConfiguration="ScheduledJobsServiceBinding" contract="DistributedService.Contracts.Interfaces.IScheduledJobsService"/>
        <endpoint address="mexTcpAdres" binding="mexTcpBinding" bindingConfiguration="" contract="IMetadataExchange"/>
        <endpoint address="" binding="basicHttpBinding" bindingConfiguration="ScheduledJobsServiceBindingHttp" contract="DistributedService.Contracts.Interfaces.IScheduledJobsService"/>
        <endpoint address="mex" binding="mexHttpBinding" bindingConfiguration="" contract="IMetadataExchange"/>
      </service>
    </services>
    <behaviors>
      <serviceBehaviors>
        <behavior name="Basic_Service_Behavior">
          <serviceDebug includeExceptionDetailInFaults="true"/>
          <serviceMetadata/>
        </behavior>
      </serviceBehaviors>
    </behaviors>
    <bindings>
      <netTcpBinding>
        <binding name="ScheduledJobsServiceBinding" maxReceivedMessageSize="900000000" receiveTimeout="00:15:00" sendTimeout="00:15:00">
          <reliableSession inactivityTimeout="15:00:00"/>
        </binding>
      </netTcpBinding>
      <basicHttpBinding>
        <binding name="ScheduledJobsServiceBindingHttp" maxReceivedMessageSize="900000000" receiveTimeout="00:15:00" sendTimeout="00:15:00"/>
      </basicHttpBinding>
    </bindings>
</system.serviceModel>

Visual Studio’da bir test projesi yarattık ve service referans olarak ekleme yaptık.
Oluşan config dosyası şu şekilde:
<system.serviceModel>
    <bindings>
      <basicHttpBinding>
        <binding name="BasicHttpBinding_IScheduledJobsService" closeTimeout="00:01:00"
          openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
          allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
          maxBufferSize="65536" maxBufferPoolSize="524288" maxReceivedMessageSize="65536"
          messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered"
          useDefaultWebProxy="true">
          <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
            maxBytesPerRead="4096" maxNameTableCharCount="16384" />
          <security mode="None">
            <transport clientCredentialType="None" proxyCredentialType="None"
              realm="" />
            <message clientCredentialType="UserName" algorithmSuite="Default" />
          </security>
        </binding>
      </basicHttpBinding>
      <netTcpBinding>
        <binding name="NetTcpBinding_IScheduledJobsService" closeTimeout="00:01:00"
          openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
          transactionFlow="false" transferMode="Buffered" transactionProtocol="OleTransactions"
          hostNameComparisonMode="StrongWildcard" listenBacklog="10" maxBufferPoolSize="524288"
          maxBufferSize="65536" maxConnections="10" maxReceivedMessageSize="65536">
          <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
            maxBytesPerRead="4096" maxNameTableCharCount="16384" />
          <reliableSession ordered="true" inactivityTimeout="00:10:00"
            enabled="false" />
          <security mode="Transport">
            <transport clientCredentialType="Windows" protectionLevel="EncryptAndSign" />
            <message clientCredentialType="Windows" />
          </security>
        </binding>
      </netTcpBinding>
    </bindings>
    <client>
      <endpoint address="net.tcp://testapp.bimar.com:8019/DistributedService.Wcf.ScheduledJobsService.svc/netTcpAdres"
        binding="netTcpBinding" bindingConfiguration="NetTcpBinding_IScheduledJobsService"
        contract="ServiceReference1.IScheduledJobsService" name="NetTcpBinding_IScheduledJobsService">
        <identity>
          <servicePrincipalName value="host/ testapp.bimar.com" />
        </identity>
      </endpoint>
      <endpoint address="http:// testapp.bimar.com:8018/DistributedService.Wcf.ScheduledJobsService.svc"
        binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IScheduledJobsService"
        contract="ServiceReference1.IScheduledJobsService" name="BasicHttpBinding_IScheduledJobsService" />
    </client>
  </system.serviceModel>

Renkli kısımlarda gördüğünüz gibi;
Baseadress olarak svc dosyası görünüyor. BasicHttp için özel bir adres vermemiştik. netTcp için verdiğimiz özel adres (netTcpAdres) base adrese eklenmiş durumda.

Konuyla ilgili aşağıdaki linkleri de inceleyebilirsiniz.



İyi Çalışmalar

Serkan

27 Eylül 2011 Salı

Calling WCF Service with Service Reference

Doğru Kullanım
ServiceReference1.ArdTarifeServiceClient obj = new ServiceReference1.ArdTarifeServiceClient();
                    using (obj)
                    {
                        string s = (obj.Increment().ToString());
                    }

Daha Doğru Kullanım
bool mSuccess = false;
            ServiceReference1.ArdTarifeServiceClient obj = new ServiceReference1.ArdTarifeServiceClient();
            try
            {
                string s = obj.Increment().ToString();
                obj.Close();
                mSuccess = true;
            }
            finally
            {
                if (!mSuccess)
                    obj.Abort();
            }

Yanlış Kullanım ve Olacaklar

int t = 0;
            try
            {
                for (int i = 0; i < 500; i++)
                {
                    t = i;
                    ServiceReference1.ArdTarifeServiceClient obj = new ServiceReference1.ArdTarifeServiceClient();
                    string s = (obj.Increment().ToString());
                }
            }
            catch (Exception ex)
            {
                string hata = t + ".ci satirda : " + ex.ToString();
            }


System.TimeoutException: The open operation did not complete within the allotted timeout of 00:01:00. The time allotted to this operation may have been a portion of a longer timeout. ---> System.TimeoutException: The socket transfer timed out after 00:00:59.9990000. You have exceeded the timeout set on your binding. The time allotted to this operation may have been a portion of a longer timeout. ---> System.Net.Sockets.SocketException: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond
   at System.Net.Sockets.Socket.Receive(Byte[] buffer, Int32 offset, Int32 size, SocketFlags socketFlags)
   at System.ServiceModel.Channels.SocketConnection.ReadCore(Byte[] buffer, Int32 offset, Int32 size, TimeSpan timeout, Boolean closing)
   --- End of inner exception stack trace ---
   at System.ServiceModel.Channels.SocketConnection.ReadCore(Byte[] buffer, Int32 offset, Int32 size, TimeSpan timeout, Boolean closing)
   at System.ServiceModel.Channels.SocketConnection.Read(Byte[] buffer, Int32 offset, Int32 size, TimeSpan timeout)
   at System.ServiceModel.Channels.DelegatingConnection.Read(Byte[] buffer, Int32 offset, Int32 size, TimeSpan timeout)
   at System.ServiceModel.Channels.ConnectionUpgradeHelper.InitiateUpgrade(StreamUpgradeInitiator upgradeInitiator, IConnection& connection, ClientFramingDecoder decoder, IDefaultCommunicationTimeouts defaultTimeouts, TimeoutHelper& timeoutHelper)
   at System.ServiceModel.Channels.ClientFramingDuplexSessionChannel.SendPreamble(IConnection connection, ArraySegment`1 preamble, TimeoutHelper& timeoutHelper)
   at System.ServiceModel.Channels.ClientFramingDuplexSessionChannel.DuplexConnectionPoolHelper.AcceptPooledConnection(IConnection connection, TimeoutHelper& timeoutHelper)
   at System.ServiceModel.Channels.ConnectionPoolHelper.EstablishConnection(TimeSpan timeout)
   at System.ServiceModel.Channels.ClientFramingDuplexSessionChannel.OnOpen(TimeSpan timeout)
   --- End of inner exception stack trace ---

Server stack trace:
   at System.ServiceModel.Channels.ClientFramingDuplexSessionChannel.OnOpen(TimeSpan timeout)
   at System.ServiceModel.Channels.CommunicationObject.Open(TimeSpan timeout)
   at System.ServiceModel.Channels.ServiceChannel.OnOpen(TimeSpan timeout)
   at System.ServiceModel.Channels.CommunicationObject.Open(TimeSpan timeout)
   at System.ServiceModel.Channels.ServiceChannel.CallOpenOnce.System.ServiceModel.Channels.ServiceChannel.ICallOnce.Call(ServiceChannel channel, TimeSpan timeout)
   at System.ServiceModel.Channels.ServiceChannel.CallOnceManager.CallOnce(TimeSpan timeout, CallOnceManager cascade)
   at System.ServiceModel.Channels.ServiceChannel.EnsureOpened(TimeSpan timeout)
   at System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[] outs, TimeSpan timeout)
   at System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCallMessage methodCall, ProxyOperationRuntime operation)
   at System.ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessage message)





15 Temmuz 2011 Cuma

wcf servisi ( WcfSvcHost ) / LLBLGenPro 64 Bit Problem - wcf service ( WcfSvcHost ) / LLBLGenPro 64 bit problem workaround

64 bit bilgisayarlarda wcf projesi yapiyorsaniz, wcfsvchost.exe kullanarak wcf servisini host ediyorsaniz, 32bit derlenmis dll lerin kullaniminda sıkıntı yasayabilirsiniz.

Sorun MS’un bir bug’indan kaynaklaniyor. Uygulama 32 bit calissa bile host.exe yi 64 bit calistiriyor. Workaround var. Corflags.exe kullanilarak wcfsvchost.exe ye her zaman 32 bit calis denilebiliyor.

 

İlgili linkler asagida:

https://connect.microsoft.com/VisualStudio/feedback/details/349510/vs2008-incorrectly-launches-x64-version-of-wcfsvchost-for-x86-debugging

 

http://controlflow.info/?p=9

 

 

Clint Side Error / İstemciden Gelen Hata

The server was unable to process the request due to an internal error.  For more information about the error, either turn on IncludeExceptionDetailInFaults (either from ServiceBehaviorAttribute or from the <serviceDebug> configuration behavior) on the server in order to send the exception information back to the client, or turn on tracing as per the Microsoft .NET Framework 3.0 SDK documentation and inspect the server trace logs.

 

Server Side Error / Wcf Servisten Gelen Hata

Could not load file or assembly 'Oracle.DataAccess, Version=2.112.1.2, Culture=neutral, PublicKeyToken=89b483f429c47342' or one of its dependencies. The system cannot find the file specified.

 

Solution  / Çözüm

 

(WcfSvcHost.exe)

Open -> Visual Studio 2010 Command Prompt, (Run As Administrator)

 

Cd \

Cd C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE

corflags /32BIT+ /FORCE WcfSvcHost.exe

 

corflags : warning CF011 : The specified file is strong name signed.  Using /For

ce will invalidate the signature of this image and will require the assembly to

be resigned.

 

(LLBLGenPro.exe)

C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC>corflags /32BIT+ /FORCE "

C:\Program Files (x86)\Solutions Design\LLBLGen Pro v2.6\LLBLGenPro.exe"

 

Microsoft (R) .NET Framework CorFlags Conversion Tool.  Version  4.0.30319.1

Copyright (c) Microsoft Corporation.  All rights reserved.

 

corflags : warning CF011 : The specified file is strong name signed.  Using /For

ce will invalidate the signature of this image and will require the assembly to

be resigned.

 

Bu warning’i aldıysanız her şey yolunda demektir. /32BIT- yazarak komutu tekrar çalıştırdığınız 64 bit moda geri dönebilirsiniz.