Tuesday, October 13, 2009

Mapping several elements to a single element

Frequently we have one block of XML that we want to split to diferent blocks. For instance, when exporting to SQL stored procedures. It is easy to do. Sometimes the opposite happens and the tables are imported from SQL: we have the information divided by several blocks on one XML and we want it grouped.

Let's imagine a simple scenario: one table included the name of a person, the other the professional information. How can we group it to a single element?

We use XSLT.

Supposing that one of the segments has all the keys, the trick is to loop that segment to read the keys and pull the information from all. This way the order of the elements is not important, the association is made by key.

This template compiles the information:

 <xsl:template name="NameValueTemplate">
  <xsl:param name="param1" />
  <xsl:for-each select="//ElementKey">
   <xsl:if test="Id/text()=$param1">
    <xsl:attribute name="Id">xsl:value-of select="Id/text()" /></xsl:attribute>
    <xsl:element name="Name"><xsl:value-of select="Name/text()" /></xsl:element>
   </xsl:if>
  </xsl:for-each>
  <xsl:for-each select="//ElementInfo">
   <xsl:if test="$Id=$param1">
    <xsl:element name="Mail"><xsl:value-of select="Mail/text()" /></xsl:element>
    <xsl:element name="Job"><xsl:value-of select="Job/text()" /></xsl:element>
    <xsl:element name="Phone"><xsl:value-of select="Phone/text()"/></xsl:element>
   </xsl:if>
  </xsl:for-each>
 </xsl:template>


And this is how it is called:

 <xsl:template match="/s0:Root">
  <ns0:Root>
   <xsl:for-each select="//ElementKey">
    <xsl:element name="Element">
     <xsl:call-template name="NameValueTemplate">
      <xsl:with-param name="param1"><xsl:value-of select="Id/text()"/></xsl:with-param>
     </xsl:call-template>
    </xsl:element>
   </xsl:for-each>
  </ns0:Root>
 </xsl:template>



This is it. It includes attributes and elements to include a broad range of situations. More complex cases can be made from this.

Friday, September 18, 2009

WCF service publishing wizard settings

Did you ever had to republish a web service over and over again? Is it fun to go through the wizard and add the methods one by one?

We were having that problem. The idea was to make a connection between SAP and Sharepoint through web services created by Biztalk. An RFC in SAP receives the request and returns the values to Sharepoint that will use them to create a page. To comunication was quick and stable, but I was losing my mind and time creating the services one by one. Let's see the process step by step with focus on Biztalk:

1. the new RFC is created in SAP (not my problem)
2. Biztalk imports reference with the SAP Adapter (easy)
3. build and deploy dll (too easy)

4. recreate service through Biztalk WCF Publishing Wizard
4.1 select Transport Type
4.2 enable Metadata endpoint
4.3 select Biztalk application
4.4 select "publish schemas"
4.5 rename Web Service
4.6 rename Web Method
4.7 define schema type for request and for response, enlarging both the columns to read the schema type
4.8 repeat 4.6 and 4.7 for every single RFC, old or new...
4.9 define namespace
4.10 define the same service location with overwrite
4.11 allowing anonymous access
4.12 press Create

5 update reference on client
6 do some new methods
7 test

The best way to reduce time on Biztalk is never to press the Finish button. Going back the settings are all there and you can deploy it again.

But there is a better way... I googled for this situation. On this blessed link I found the answers for all my problems. Well, at least for this one.
So, the deployment stores the configuration inside wwwroot. And more! It is understandable and can be edited!

I simply made a batch file to call the wizard with the parameter
cd C:\Program Files\Microsoft BizTalk Server 2006\
BtsWcfServicePublishingWizard -WcfServiceDescription=C:\Inetpub\wwwroot\BizTalkWcfService\App_Data\Temp\WcfServiceDescription.xml

and now my work is just with steps 4.3, 4.4, 4.6, 4.7, 4.9, 4.12. The annoying configuration of all old methods, and more than half the checkbox clicks are made for me.

Question: Shouldn't the wizard allow the loading of a xml file?

Registering adapters while publishing services

The Messaging Engine failed to register the adapter for "WCF-BasicHttp" for the receive location "*/*.svc". Please verify that the receive location exists, and that the isolated adapter runs under an account that has access to the BizTalk databases.


This time the problem is not on BizTalk but on IIS. The Application Pool for this website must be running not under a predefined service, but on an account with permissions over Biztalk.

Solution:


Create a new Application Pool for Biztalk, and on the Identity Tab select Configurable and insert the login. Associate the Web Site to this new app and refresh the svc page.

Thursday, March 19, 2009

"Registering multiple adapter types within the same process is not a supported scenario" error

From MSDN:

Setting Up HTTP and SOAP Receive

If it is required to run both HTTP and SOAP receive functions on the same Web server, additional configuration is required to avoid the following error:

"The Messaging Engine failed to register an adapter "SOAP". Details: "Registering multiple adapter types within the same process is not a supported scenario. For e.g. HTTP and SOAP receive adapters cannot co-exist in the same process"

To avoid this error, create two separate application pools (one for HTTP adapter and one for SOAP adapter).
Note
Both application pools may use the same BizTalk Server 2004 Isolated Host User identity.

Note
The actual host configuration used should be dictated by security and isolation requirements of the production environment.

Friday, February 6, 2009

Business Rules deployment: «Database associated with deployment driver does not match the database ":" specified during product configuration»

If you ever see this dreaded error message, don't fear!
First, follow each and every step suggested here: SOLVED: The BizTalk Rules Engine Deployment Riddle.
If it still doesn't work, then find the following tables in your BizTalkMgmtDb: adm_Group, adm_OtherDatabases and adm_OtherBackupDatabases.
In the first, fill the columns RuleEngineDbServerName and RuleEngineDbName.
In the other two, add a new line with the DefaultDatabaseName = RuleEngine DB, and the other columns with your installation-specific information.
Et voilá!