Showing posts with label WCF. Show all posts
Showing posts with label WCF. Show all posts

Friday, March 22, 2019

Test WCF Service by using WCFTestClient.exe

WCFTestClient.exe is GUI tool which is developed by Microsoft to test WCF Service without creating any client application. In WCF test Client tool, you simply pass the input parameters for WCF service and you can view the service response.

There are few steps to use the WCFTestClient.exe and call the WCF Service

              1.       Get WCF Service WSDL URL, if Service is already created .

WCF Order Service:

  

WSDL document:

WCF WSDL


2.       Open Developer Command Prompt for VS 2017 


3.       Type the WCFTestClient and then Enter

Command Prompt

4.       GUI Application – WCF Test Client will be opened

WCF Test Client GUI

5.       Select My Service Projects and  Click on ‘ Add Service’  Option

WCF Test Client


6.       Add Service Popup window will be opened and type the service endpoint URL as address and click OK


WCF Test Client Add Service


Now Service’s methods and signature will be displayed and click on GetData Method

               
WCF Test Client - Add Service


7.       Now pass service input parameter value as 100 and click on Invoke button and you will get “You entered: 100 “as service response.

WCF Test Client Request Response

Thursday, January 31, 2019

WCF : Tuning WCF Service Performance and Default value for Throttling Settings

This blog will discuss how to tune WCF service performance under heavy load and explain the throttling settings.

Here is default value for each throttling setting as per msdn (wcf4.5 and higher version)


Default Value
Single core -processor
MaxConcurrentCalls
16 * No of processor
16
MaxConcurrentInstances
MaxConcurrentCalls + MaxConcurrentInstances
116
MaxConcurrentSessions
100 * No of processor
100

In WCF , service throttling settings control the WCF service performance and server resource unitization, without knowing if you provide the highest value (INT MAX) to these setting, then service will be completed chocked.



We can achieve balance performance of service and controller resource usages by using following settings
  • MaxConcurrentCalls: specify maximum number of message concurrently process by Service Host.
  • MaxConcurrentInstances: specify the maximum number of instance object of service.
  • MaxConcurrentSessions : specify the maximum number of sessions a ServiceHost object can accept
Web.config:

<serviceBehaviors>
        <behavior name="serviceBehavior">
          <serviceThrottling 
            maxConcurrentCalls="16"
             maxConcurrentInstances="116"
             maxConcurrentSessions ="100"
           />
         <serviceMetadata httpGetEnabled="true" httpsGetEnabled="true" />
        </behavior>
      </serviceBehaviors>


Thanks for visiting!!

Monday, January 28, 2019

WCF Exception: “The service operation requires a transaction to be flowed”

WCF Exception: “The service operation requires a transaction to be flowed”
Recently I encountered the wcf transaction error while calling to WCF service and this WCF service is transaction based service and I tried to call service without any transaction scope.

try
            {
                Account.AccountServiceClient account = new Account.AccountServiceClient();
                account.UpdateTaxRefundAmount(taxId, refund);
            }

                   
              catch (Exception ex)
            {
                throw;
            }   


In this blog, we will discuss how to create transaction scope and call transaction enabled service method.



You can use TranscationScope class to define a block of code which will be executed in a transaction and this call expose below methods to manage the current transaction status:
  •  Complete() – all operations within the current transaction scope are completed successfully.
  •   Dispose () – it aborts the current transaction.

Example C# : 
        
using (TransactionScope ts = new TransactionScope(TransactionScopeOption.RequiresNew))
            {
                try
                {
                    // Call service method
                Account.AccountServiceClient account = new Account.AccountServiceClient();
                account.UpdateTaxRefundAmount(taxId, refund);

                    ts.Complete();
                }
                catch (Exception ex)
                {
                    ts.Dispose();
                }
             }

you can define the behavior of truncation scope by passing the below transcationScopeOption to constructor of transcationScope class 
  • Required - a transaction is required by the scope, if there is already an existing transaction scope otherwise it creates new transaction.
  • RequiredNew – it always create a new transaction.
  • Surpress – it suppress the parent transaction or surrounding transaction.

Monday, November 26, 2018

Web API over WCF

While designing the service layer for new application, this debate is always happened in my team.

        Are we going to choose Web API over WCF or going with WCF?

Choosing right technology always contribute the major role of the success of application. If without understanding all possible factor and product requirement, you cherry-picked any technology, it could be a reason for application failure or performance issue and also it could limited the exposure of client.  

Let back on our topic ‘Web API vs WCF’. there is no doubt, WCF provides a lots of feature and it is much more versatile in case of supporting to many transport protocols (HTTP, TCP, Named Pipes etc.) and can easily build secure, reliable and transaction enabled service and much more in messaging like two –way communication (duplex channel) .

Web API if you need to build  a lightweight, restful service based HTTP protocol and it can leverage of the full feature of HTTP protocol like cache control, versioning etc and you want to expose your service to a broad range of client i.e. web browser, tables, mobile then web API always have advantage over WCF. WCF has very extensive configuration compare to web API and WEB API is very simple and light weight service and easily accessible in limited bandwidth device like smart phones and tablet. Web API supports any text format including XML so in performance, Web API is faster than WCF.

WCF:

WCF
WCF

·         Should support special scenarios such as one way messaging, message queues, duplex communication etc.
·         Should support fast transport channels when available, such as TCP, Named Pipes, or maybe even UDP (in WCF 4.5), and you also want to support HTTP when all other transport channels are unavailable.
·         Should be transaction enabled service or it will be called under other transaction scope.

Web API:


Web API
WEB API

·         Should be restful service over HTTP that can use the full features of HTTP (like URIs, request/response headers, caching, versioning, various content formats).
·         Should be expose your service to a broad range of clients including browsers, mobiles, iPhone and tablets.

Thanks for visiting !!

Tuesday, October 23, 2018

WCF Exception : The message with Action 'http://tempuri.org ' cannot be processed at the receiver, due to a ContractFilter mismatch at the EndpointDispatcher


WCF Exception: The message with Action 'http://tempuri.org/IProduct/GetProduct ' cannot be processed at the receiver, due to a ContractFilter mismatch at the EndpointDispatcher. This may be because of either a contract mismatch (mismatched Actions between sender and receiver) or a binding/security mismatch between the sender and the receiver. Check that sender and receiver have the same contract and the same binding (including security requirements, e.g. Message, Transport, None)



There would be many reason for this exception and it can be :

·         Requested Method ‘GetProduct’ signature has been changed.
·         Requested Method ‘GetProduct’ has been deleted from WCF server.
·         Existing Binding Information has been modified or delete.
·         Binding security setting are not consistent between client and server

To resolve this contract mismatch issue, recreate or refresh the wcf client proxy, most proabaly this issue will be resolved.

Thanks for visiting!!

Wednesday, October 3, 2018

WCF Exception : Network access for Distributed Transaction Manager (MSDTC) has been disabled. Please enable DTC for network access in the security configuration for MSDTC using the Component Services Administrative tool


I recently faced the below error message, when I tried to access transaction flow enabled WCF service.

InnerException = {"Network access for Distributed Transaction Manager (MSDTC) has been disabled. Please enable DTC for network access in the security configuration for MSDTC using the Component Services Administrative tool."}



I followed the below steps to resolve above issue on my local system
  •  Enable Network DTC Access : 
1.       Run dcomcnfg in start to open the Component Services Administrative tool




2.       Click on Local DTC and open the property window




             3.   Click on security Tab and make below security settings to enable Network DTC Access




  •  Enabled Firewall Rules related to Distributed Transaction Coordinator (TCP-IN/TPC-Out) : 
1.       Open the Window Firewall
2.       Click on the Advanced Security :
§  Inbound Rules  -> Distributed Transaction Coordinator (TCP-IN)   à Enabled








§  Outbound Rules -> Distributed Transaction Coordinator (TCP-Out) à Enabled










Thanks for Visiting!!

SQL Server - Identify unused indexes

 In this blog, we learn about the index usage information (SYS.DM_DB_INDEX_USAGE_STATS) and analyze the index usage data (USER_SEEKS, USER_S...