Excellent post of Charles Young about Dublin and BizTalk

October 16, 2008 / Comments Off on Excellent post of Charles Young about Dublin and BizTalk

I was reading the post of Charles Young about Dublin and BizTalk Server – What’s the difference?

I can only say, it’s really worth a read, and after reading it, you will probably know you will still be doing BizTalk and XLANG for a long time.
The goodies mentioned in the article that come with BizTalk will just not be available for WF for a long long time to come.

COme on have read of the article here:Dublin and BizTalk Server – What’s the difference?

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 !

 

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