Category name:WCF

Getting rid of : WCF-Custom" raised an error message. Details "System.Data.SqlClient.SqlException: Timeout expired

December 22, 2010 / Comments Off on Getting rid of : WCF-Custom" raised an error message. Details "System.Data.SqlClient.SqlException: Timeout expired

I had a nice setup in my BizTalk environment. I had 4 receive locations polling for data (in the same table) and it all boiled down to execute a stored procedure with different parameters. I used the WCF adapter with SQL bindings for that.
For some obscure reason, I would get timeouts in the eventlog. Below is a screenshot of the receive port setup I had. Only one is shown but I had four of them.

Some important things to notice:

  • PolledDataAvailablestatement, is not used cause Pollwhiledatatfound = false. But you still have to put stuff in there to make things work.
  • Execute a specific sproc, with the number of records you want to receive as a parameter.
  • UseAmbientTransaction, no, no,no, had too many problems in the past when using msdtc and receive locations (locks and stuff) so this is a NO.
  • ReceiveTimeout is set to 10 minutes. This is a bit long but i never touched that value, it’s the default.

To make things a little bit more clear, The stored procedure I used looks looked like this :

 CREATE PROCEDURE [dbo].[Get_TeVertalen_Berichten]
(
 @MaximumAantal INT = NULL
)
AS
BEGIN
 EXEC [dbo].[Get_Berichten_Internal]
  @MaximumAantalInternal = @MaximumAantal,
  @OudeBerichtStatus = ‘TeVertalen’,
  @NieuweBerichtStatus = ‘VertalenGestart’,
  @Richting  = ‘Ingaand’  
END

And here is the code of Get_Berichten_Internal:

CREATE PROCEDURE [dbo].[Get_Berichten_Internal]
(
 @MaximumAantalInternal INT = 15,
 @OudeBerichtStatus  VARCHAR(200),
 @NieuweBerichtStatus VARCHAR(200),
 @Richting    VARCHAR(20) 
)
AS
BEGIN
 BEGIN TRY
  — Declare variables
  DECLARE @AFFECTED_KEYS TABLE
  (
   BerichtID NUMERIC(18, 0)
  )
  DECLARE @AFFECTED_ROWS INT
   — Some sets needed
  SET NOCOUNT ON
  — Perform the update statement and capture all the keys
  UPDATE
   TOP (@MaximumAantalInternal) dbo.tb_Bericht
  SET  
   BerichtStatus = @NieuweBerichtStatus
  OUTPUT
   INSERTED.BerichtID
  INTO
   @AFFECTED_KEYS
  WHERE
   BerichtStatus = @OudeBerichtStatus
  AND
   ExternBerichtTypeID IS NOT NULL
  AND
   InternBerichtTypeID IS NOT NULL
  AND
   Richting = @Richting
  — DO STUFF WITH THE AFFECTED KEYS
  <– SNIP–>
 END TRY
END

Now everything looks good and in the query analyzer everything was working blazingly fast. But I started to see the following message in the eventlog every 10 minutes (hmm that’s the receive timeout).  And sometimes several (four to be exactly) of them within a very short period of time.

Event Type: Warning
Event Source: BizTalk Server 2006
Event Category: BizTalk Server 2006
Event ID: 5740
Date:  14-12-2010
Time:  10:47:07
User:  N/A
Computer: BA34T
Description:
The adapter “WCF-Custom” raised an error message. Details “System.Data.SqlClient.SqlException: Timeout expired.  The timeout period elapsed prior to completion of the operation or the server is not responding.
   at Microsoft.ServiceModel.Channels.Common.Design.AdapterAsyncResult.End()
   at Microsoft.ServiceModel.Channels.Common.Channels.AdapterInputChannel.EndTryReceive(IAsyncResult result, Message& message)
   at System.ServiceModel.Dispatcher.InputChannelBinder.EndTryReceive(IAsyncResult result, RequestContext& requestContext)
   at System.ServiceModel.Dispatcher.ErrorHandlingReceiver.EndTryReceive(IAsyncResult result, RequestContext& requestContext)”.

For more information, see Help and Support Center at http://go.microsoft.com/fwlink/events.asp.

And once this message started to appear, stuff went downhill from there on. I could see in the profiler that stored procedures were taking ages, and even simple updates of a single record would take thirty seconds or so. Lock-Time-outs and deadlocks were occuring on a very regular basis. Even though the receive locations werent receiving any data. So nothing was received and I still got may daily portion of errors/warnings/suspended stuff in BizTalk because of this.
So basically it looked like I was having some kind of locking problem even if no work was done by the second stored procedure. But the second procedure did an update (even when there was nothing to update) and maybe that triggered the nasty behaviour.

I started a discusiion on MSDN to see if anybody could help : <<See here>>

 But eventually i cghanged something to make this behaviour go away. The idea was only to perform the update when there was stuff to update. So i changed the first procedure to :

CREATE PROCEDURE [dbo].[Get_TeVertalen_Berichten]
(
   @MaximumAantal INT = NULL
)
AS
BEGIN
 SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
 DECLARE @Aantal int
 SELECT
  @Aantal=count(*)
 FROM
  dbo.tb_Bericht WITH (NOLOCK)
 WHERE
  BerichtStatus = ‘TeVertalen’
 AND
  ExternBerichtTypeID IS NOT NULL
 AND
  InternBerichtTypeID IS NOT NULL
 AND
  Richting = ‘Ingaand’
 IF @Aantal > 0
 BEGIN
  EXEC [dbo].[Get_Berichten_Internal]
    @MaximumAantalInternal = @MaximumAantal,
    @OudeBerichtStatus  = ‘TeVertalen’,
    @NieuweBerichtStatus = ‘VertalenGestart’,
    @Richting    = ‘Ingaand’  
 END 
END

 And by first checking if there was any work to do and only then do an update, I got rid of the deadlocks and the errors in the eventlog.
I really don’t know why this solved it, but my guess is there is some bug in the WCF adapters, that go wrong if you start a transaction but return no data.

Everything is running smooth now and I hope this post will help somebody experiencing the same problems.

BizTalk HotRod number 5 is now online !

February 12, 2009 / Comments Off on BizTalk HotRod number 5 is now online !

Topics covered :

  • Application Servers: BizTalk vs. Dublin
  • Unit Testing in BizTalk Server 2009
  • Monitoring a WCF Service Using BAM: A Walkthrough
  • Operations Management for BizTalk
  • Governing the SOA Runtime with AmberPoint
  • BizTalk monitoring and exception handling from any desktop
  • Add Governance to BizTalk with SOA Software

So lots of interesting stuff again !. Go to the site of BizTalk HotRod and download your copy >>here<<

Excellent post about BizTalk Protocol Transition

January 23, 2009 / Comments Off on Excellent post about BizTalk Protocol Transition

Today I found an excellent post about BizTalk Protocol transition by Paolo Salvatori.
It’s absolutely worth reading if you have to work with Webservices / Single Sign On.

He covers 3 scenarios:

Scenario 1 – Messaging Only Scenario with a SOAP Receive Location
Scenario 2 – Messaging Only Scenario with a WCF-Custom Receive Location
Scenario 3 – Orchestration with an Inline Send Port

 Have a read of the post >>Here<<

How to expose an old style WSDL (Flattened) with the schema’s included from BizTalk 2006 R2 with a WCF adapter

October 6, 2008 / Comments Off on How to expose an old style WSDL (Flattened) with the schema’s included from BizTalk 2006 R2 with a WCF adapter

It is really nice to have WCF around. With WCF you are ready for the future. Unfortunaltely this is only true in a Microsoft landscape. The new style WSDL with the schema’s no longer included is one of those enhancements that should be really nice. Unfortunately there are tons of software out there that cannot handle the default WSDL behaviour of a WCF service. Below is a picture of the default WSDL behaviour.

DefaultSoap

And this is not the behavoiur old clients like. So we have to modify the WSDL that’s spitted out by a WCF service.

To make things happen I googled around a lot and finally after some very good posts of Thomas Restrepo and LocoTheGrande(Don’t know who’s behind that blog post) i had a class up and running that should do what I wanted. Below is the code of that class….

 //
// InlineXsdInWsdlBehavior.cs
//
// Author:
//    Tomas Restrepo (tomasr@mvps.org)
//

using System;
using System.Collections;
using System.Collections.Generic;
using System.Configuration;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.ServiceModel.Channels;
using System.ServiceModel.Configuration;
using System.ServiceModel.Description;
using System.ServiceModel.Dispatcher;
using System.Text;
using System.Xml;
using System.Xml.Schema;
using System.Web.Services;
using System.Web.Services.Description;
using WsdlDescription = System.Web.Services.Description.ServiceDescription;

namespace FH.CE.ESB.WSDL.Extensions
{
    /// <summary>
    /// IEndpointBehavior implementation that will
    /// force WCF to generate all schemas inline into the
    /// generated WSDL files, instead of as individual files.
    /// </summary>
    public class InlineXsdInWsdlBehavior : BehaviorExtensionElement,IWsdlExportExtension, IEndpointBehavior
    {

        #region IWsdlExportExtension Implementation
        //
        // IWsdlExportExtension Implementation
        //
        public void ExportContract(WsdlExporter exporter,WsdlContractConversionContext context)
        {
            // never called
        }

        public void ExportEndpoint(WsdlExporter exporter,WsdlEndpointConversionContext context)
        {
            XmlSchemaSet schemaSet = exporter.GeneratedXmlSchemas;

            foreach (WsdlDescription wsdl in exporter.GeneratedWsdlDocuments)
            {
                //
                // Recursively find all schemas imported by this wsdl
                // and then add them. In the process, remove any
                // <xsd:imports/>
                //
                List<XmlSchema> importsList = new List<XmlSchema>();
                foreach (XmlSchema schema in wsdl.Types.Schemas)
                {
                    AddImportedSchemas(schema, schemaSet, importsList);
                }
                wsdl.Types.Schemas.Clear();
                foreach (XmlSchema schema in importsList)
                {
                    RemoveXsdImports(schema);
                    wsdl.Types.Schemas.Add(schema);
                }
            }
        }

        #endregion // IWsdlExportExtension Implementation

        #region Private Methods
        //
        // Private Methods
        //

        /// <summary>
        /// Recursively extract all the list of imported
        /// schemas
        /// </summary>
        /// <param name=”schema”>Schema to examine</param>
        /// <param name=”schemaSet”>SchemaSet with all referenced schemas</param>
        /// <param name=”importsList”>List to add imports to</param>
        private void AddImportedSchemas(XmlSchema schema,XmlSchemaSet schemaSet,List<XmlSchema> importsList)
        {
            foreach (XmlSchemaImport import in schema.Includes)
            {
                ICollection realSchemas =
                   schemaSet.Schemas(import.Namespace);
                foreach (XmlSchema ixsd in realSchemas)
                {
                    if (!importsList.Contains(ixsd))
                    {
                        importsList.Add(ixsd);
                        AddImportedSchemas(ixsd, schemaSet, importsList);
                    }
                }
            }
        }

        /// <summary>
        /// Remove any &lt;xsd:imports/&gt; in the schema
        /// </summary>
        /// <param name=”schema”>Schema to process</param>
        private void RemoveXsdImports(XmlSchema schema)
        {
            for (int i = 0; i < schema.Includes.Count; i++)
            {
                if (schema.Includes[i] is XmlSchemaImport)
                    schema.Includes.RemoveAt(i–);
            }
        }

        #endregion // Private Methods

        #region IEndpointBehavior Implementation

        public void AddBindingParameters(ServiceEndpoint endpoint,BindingParameterCollection bindingParameters)
        {
            // not needed
        }

        public void ApplyClientBehavior(ServiceEndpoint endpoint,ClientRuntime clientRuntime)
        {
            // not needed
        }

        public void ApplyDispatchBehavior(ServiceEndpoint endpoint,EndpointDispatcher dispatcher)
        {
            // not needed
        }

        public void Validate(ServiceEndpoint endpoint)
        {
            // not needed
        }

        public override System.Type BehaviorType
        {
            get { return typeof(InlineXsdInWsdlBehavior); }
        }

        protected override object CreateBehavior()
        {
            return new InlineXsdInWsdlBehavior();
        }

        #endregion // IContractBehavior Implementation

    } // class InlineXsdInWsdlBehavior

} // namespace Winterdom.ServiceModel.Extensions

The code above is not the original code of Thomas Restrepo. The last two methods were added by me. I found the directions of how to do that in the post of LocoTheGrande. I made sure that I gac-ed the component an tried to add the behaviour to a Service that was generated by BizTalk. And I tried really hard but could not succeed. So finally I was out of options and decided to write a mail to Thomas Restrepo. His Email address was on hist site so I thought I give it a try. And I got a reply from Thomas the same evening helping me on my way. Basically he said the following things..

1. Make sure the component is in the GAC.
2. Edit the machine.Config
3. Use one of the Custom WCF adapters. (The default adapters dont allow you to change behaviour)

So I fired up the good old svcConfigEditor, looked for the machine.config in the C:WINDOWSMicrosoft.NETFrameworkv2.0.50727 directory and opened it with the editor. Then I made a modification to support the InlineWsdl behaviour. Below is a screenshot of that.

Then I Went back to BizTalk and fired up the BizTalk WCF Service Publishing Wizard, I then chose the CustomIsolated WCF adapter and finished the Wizard.
After everything was done I opened up the port in the BizTalk Server Administration Console and added my behaviour. Below is a screenshot of that.

Then I browsed to my endpoint and looked at the WSDL….. Ahhhhh reward how nice. The WSDL has all the schema’s included.

 

Besides the fact that the WSDL inluded the correct XSD now this also has the benefit of exposing the correct cardinality of the elements.
Hope this helps anywone who is struggeling with this problem. Again many thanks to Thomas restrepo !

 

Interesting stuff coming with the BizTalk Adaper Pack

August 15, 2008 / Comments Off on Interesting stuff coming with the BizTalk Adaper Pack

I really can’t wait for the BizTalk Adapter pack. Finally we get a good SQL adapter capable of almost everything. I had concurrency problems in the past cause the Adapter always has a transaction level Serializable. Now with the new SQL Adapter the transaction level is settable. Have a read of the SQL LOB adapter capabillities >> here <<

They also threw in some goodies in the Adapter pack, The various Adapters will now show up as native BizTalk Adapters, have a look >> here <<

Some very interesting BixTalk/WCF screencasts

December 14, 2007 / Comments Off on Some very interesting BixTalk/WCF screencasts

I was looking at my list of Blog entries at bloglines and I saw an interesting screen cast from Aaron Skonnard I decided to have a look and was surprised to see how many extra functionality is provided by the WCF adapters. I decided to look at some more web cast about the WCF adapters and learned very interesting new things. Have a look at them and see if you learn something new.


Screen cast: BizTalk WCF Adapters — Send Port Basics


Screen cast: BizTalk WCF Adapters — Send Ports & Custom WCF Bindings


Screen cast: BizTalk WCF Adapters — Send Ports and Action Mappings


Screen cast: BizTalk WCF Adapters — Send Port Message Templates

BizTalk V-Next

October 29, 2007 / Comments Off on BizTalk V-Next

At last they have shed some light on what the next version will be :


Service Oriented Architecture










Deeper alignment with the .NET Framework – Building deeply on the investments made with Windows Communication Foundation and Windows Workflow Foundation by closer alignment of these technologies and BizTalk Server to enable customers to build richer composite applications and service oriented architectures than they can today.


Hosted Services – BizTalk Services, which represent hosted versions of a core set of platform services. While currently in incubation, BizTalk Services is an Internet Service Bus (ISB) that combines identity and access control, message routing (relay), and publish/subscribe event brokering (eventing). For more information, see BizTalk Labs.


Composite Applications










Broader Model Support – Building on the work with XLANG (BizTalk Server) and XAML (WF) by providing a richer set of domain-specific models


Runtime – Building on the host investments made with WF and BizTalk Server, to enhance the deployment and management experience of composite applications.


Business Process Management













Human Tasks – Integration with SharePoint Server to provide expanded support for human task-based scenarios.


Model Driven – Enhancements to existing visual modeling and design experiences that span roles and help foster team collaboration.


Complex Event Processing – Enhancements to BAM to provide broader monitoring support.


complete post, have a look here

Beware of default settings in WCF.

October 3, 2007 / Comments Off on Beware of default settings in WCF.

 I use bloglines (http://www.bloglines.com/) to monitor several BizTalk related blogs.


First of all, I saw a post of Jesus Rodriguez about some SOA Tips.Via his blog I ended up at the blog of David Pallman. Now this guys has some interesting tips on WCF.


WCF Tips #1 – Service Interface Design
WCF Tips #2 – Service Class Design
WCF Tips #3 – Service Hosting
WCF Tips #4 – Configuration
WCF Tips #5 – Infrastructure
WCF Tips #6 – Instrumentation
WCF Tips #7 – Clients


I believe it was the next day, I read something from Tomas Restrepo about the same David Pallman and him stressing the importance of tip 4 (WCF Tips #4 – Configuration). So I read a little about those defaults and understood the problems that they could cause.


And this morning I found a post about just this topic. Its a post from Tim Rayburn and has to do with serializing a huge XML file. Have a read of the article here. The defaults provided by svcutil were just not good enough for him. So he is in a way proving the point of Tomas.

  • Recent Posts
  • Recent Comments
  • Archives
  • Categories
  • Meta