Generating swagger for azure functions until its available OOB

Please follow the steps below to generate swagger for Azure functions

  1. Get a fiddler/postman session working with your function so that you have the json ouput.
  2. Past the Json as class using the following in Visual Studiopastedimage
  3. Create a webapi application, configure swagger (the howto can be found here https://www.youtube.com/watch?v=LIhT6HIpLf8)and create a controller method with the necessary input and output values (no method implementation is necessary except for returning expected output)
            // GET api/values/5
    public List<Rootobject> Get()
    {
    return new List<Rootobject>();}
  4. Then just navigate to  http://yourapplication:portno/swagger  to make sure all the datatypes for your particular operation are shown accordingly.
  5. Then download the swagger file from http://yourapplication:portno/swagger/docs/v1  and save it to a file
  6. Then navigate to http://editor.swagger.io/#/ open the saved file (copy paste also works) and  add or remove what you need….

Hopefully this will help in saving some time…

Using EntLib with BizTalk.

1) Create a new c# project and add all the necessary entlib dlls that you need. (this will help because we would not be adding references to entlib dlls for every biztalk project.

2) Create static wrappers classes for say Exception handling

  Policy- is the name that you give when you configure the Exception handling block.

public static class Helpers
    {

        public static void LogException(string policy, Exception ex)
        {
            ExceptionPolicy.HandleException(ex, policy);
        }

    }

3) Add  a reference to the above project in the biztalk project and invoke it as if you are invoking any other .net method

4) Create app.config file using the EntLib tool say BizTalkEnlib.config

5) Modify the BTSNTSvc.exe.config to include the following section right under the configuration node
 <configSections>
    <section name=”enterpriseLibrary.ConfigurationSource” type=”Microsoft.Practices.EnterpriseLibrary.Common.Configuration.ConfigurationSourceSection, Microsoft.Practices.EnterpriseLibrary.Common, Version=4.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35″ />
  </configSections>

6)Include the following right before the close of the configuration node

 <enterpriseLibrary.ConfigurationSource selectedSource=”File Configuration Source”>
    <sources>
      <add name=”File Configuration Source” type=”Microsoft.Practices.EnterpriseLibrary.Common.Configuration.FileConfigurationSource, Microsoft.Practices.EnterpriseLibrary.Common, Version=4.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35″
        filePath=”C:\Program Files (x86)\Microsoft BizTalk Server 2009\BizTalkEntLib.config” />
    </sources>
  </enterpriseLibrary.ConfigurationSource>

thats it and you are all set to go!

Bulk insert using WCF SQL Adapter

We had a scenario where we had to do a bulk insert of about 200 msgs into sql, after a lot of branistomring and googling we came up with the following solution

– Create a new table type
CREATE TYPE [dbo].[BulkInsertDBType] AS TABLE(
      [ID] [nvarchar](50) NULL,
      [Creation_Date_Time] [nvarchar](50) NULL
)

– Create a stored proc with  MERGE  

 

Create PROC [dbo].[sp_BulkInsertInsert]
 @List  BulkInsertDBType READONLY
  
AS
      SET NOCOUNT ON
      SET XACT_ABORT ON 
     
      BEGIN TRAN
      MERGE BulkInsertDBTable AS [Target]
USING @List   AS [Source]
ON [Target].[ID] = [Source].[ID]
WHEN NOT MATCHED THEN
    INSERT ( [ID], [Creation_Date_Time] )
    VALUES ( [Source].[ID], [Source].[Creation_Date_Time]);
COMMIT

Conclusion: the new WCF SQL Adapter supports table data type which helps for inserting bulk data!

Configure BizTalk for WCF tracing

Add the following to the biztalk config for tracing all the WCF calls and messages

<system.diagnostics>
    <sources>
      <source name=”System.ServiceModel.MessageLogging”>
        <listeners>
          <add name=”messages”
          type=”System.Diagnostics.XmlWriterTraceListener”
          initializeData=”c:\wcfTrace.e2e” />
        </listeners>
      </source>
    </sources>
  </system.diagnostics>

Simple method to calculate checksum

string str = “123456 string 1344”;

 System.Security.Cryptography.MD5CryptoServiceProvider provider = new System.Security.Cryptography.MD5CryptoServiceProvider();

byte[] byteArray = provider.ComputeHash(System.Text.Encoding.UTF8.GetBytes(str)); double d = BitConverter.ToDouble(byteArray, 0); int i = BitConverter.ToInt32(byteArray, 0);

http://social.msdn.microsoft.com/Forums/en-US/csharpgeneral/thread/5eafd0a2-1fae-437a-aeb1-f3aeca231

BizTalk Modify/Add namespace custom pipeline component (Excecute method).

 public IBaseMessage Execute(IPipelineContext pContext, IBaseMessage pInMsg)
        {
          
            IBaseMessagePart bodyPart = pInMsg.BodyPart;
            string targetNameSpace = “http://targetnamespace“;
            if (bodyPart != null)
            {
                Stream originalStream = bodyPart.GetOriginalDataStream();
                if (originalStream != null)
                {
                    XmlReaderSettings settings = new XmlReaderSettings();
                    settings.IgnoreComments = true;
                    settings.IgnoreProcessingInstructions = true;
                    settings.IgnoreWhitespace = true;
                    using (XmlReader reader = XmlReader.Create(originalStream, settings))
                    {

                        XmlWriterSettings ws = new XmlWriterSettings();
                        ws.Indent = true;
                        ws.Encoding = System.Text.Encoding.UTF8;
                        ws.ConformanceLevel = ConformanceLevel.Auto;

                        MemoryStream outputStream = new MemoryStream();
                        using (XmlWriter writer = XmlWriter.Create(outputStream, ws))
                        {
                            reader.Read();
                            if (reader.NodeType == XmlNodeType.XmlDeclaration)
                                reader.Read();

                            //Root Node
                            if (reader.NodeType == XmlNodeType.Element)
                            {

                                // Associate the the new root node with the new namespace
                                writer.WriteStartElement(reader.Name, targetNameSpace);
                               // Append the rest of the xml file (After the roor node)

                                writer.WriteRaw(reader.ReadInnerXml());
                            }
                        }
                        outputStream.Position = 0;
                        bodyPart.Data = outputStream;
                    }
                }
            }
            return pInMsg;
        
        }

Add db_datareader and db_datawriter roles to a user for a database.

USE [dbname]
GO

/****** Object:  User [domain\user]    Script Date: 05/26/2011 05:37:39 ******/
IF  EXISTS (SELECT * FROM sys.database_principals WHERE name = N’domain\user’)
DROP USER [domain\user]
GO

USE [dbname]
GO

/****** Object:  User [domain\user]    Script Date: 05/26/2011 05:37:39 ******/
GO

CREATE USER [domain\user] FOR LOGIN [domain\user] WITH DEFAULT_SCHEMA=[dbo]
GO

EXEC sp_addrolemember N’db_datareader’, N’domain\user’
EXEC sp_addrolemember N’db_datawriter’, N’domain\user’

GO

How to check for the existence/count of a given distinguished property in BizTalk

 System.Convert.ToInt32(xpath(Response_Select_Query,”count(copy xpath from schema and paste here)”));

———————————————-OR———————————————————————————

theStringValue = xpath(inputMessage, “string(//*[local-name()=’MyElementName’])”);

from the following link

http://www.arquitecturadesoftware.org/blogs/joaomartins/archive/2007/04/11/biztalk-check-if-promoted-property-exists-in-context.aspx

And now you can use System.String.IsNullOrEmpty(theStringValue) to check if the value is present.