AzureGames

With a couple of colleagues, I have started a new project: AzureGames.  I was inspired by the Microsoft Windows Azure Toolkit for Social Games, and was started as a CodePlex site.

We are currently flushing out the bugs for the basic platform.  As we don’t have time to also write the games to host, we are looking for submissions so if you have a html5 game you don’t mind us hosting, let me know!

There is a WordPress AzureGames website that has the latest status of the site including some game related articles and information about the project.

Running Weltmeister in IIS 7

The Impact Javascript Game Engine comes with level editor: Weltmeister.  This is primarily built with javascript but does include some php scripting. 

This post will hopefully save some windows developers some time getting started.

There is also an open-source project available that accomplishes this without installing PHP.  This accomplishes this by introducing ASPX pages which mimic the PHP scripts.

I am running a basic install of IIS 7.0 on Windows 7.  In summary, the steps I took to get the level editor to function were to install PHP in IIS and to run the site with windows authentication.

Installing PHP

Setting up PHP in IIS is as a simple as using the web installer via the PHP in IIS site and then performing some configuration of PHP in IIS.  There is a video regarding the steps required after the installation.

image

Security

Because the Weltmeister must interact with the file system, sufficient access rights must be given.  The easiest way is to enable Windows Authentication on the site. 

 image

HRESULT: 0×80131942 Microsoft.XLANGs.Core.XlangSoapException: An error occurred while processing the message

In case this helps someone track down a silly little defect…

I have an orchestration that uses an outbound map on a send port.  The map had a script shape that had incorrect xslt.  Simply running the Test Map would have caught this one and saved me some time. 

The full detail of the Exception Message (tracked via the Orchestation Debugger –> Show Tracked Exceptions):

Microsoft.XLANGs.Core.XlangSoapException: An error occurred while processing the message, refer to the details section for more information
Message ID: {4C5A6C53-46B7-46FA-9501-86F6462374B0}
Instance ID: {46EF83ED-3DDD-4B33-972E-93C80FE4D06A}
Error Description: Exception from HRESULT: 0×80131942
   at Microsoft.BizTalk.XLANGs.BTXEngine.BTXPortBase.VerifyTransport(Envelope env, Int32 operationId, Context ctx)
   at Microsoft.XLANGs.Core.Subscription.Receive(Segment s, Context ctx, Envelope& env, Boolean topOnly)
   at Microsoft.XLANGs.Core.PortBase.GetMessageIdForSubscription(Subscription subscription, Segment currentSegment, Context cxt, Envelope& env, CachedObject location)
   at MyOrchestration.WithAMap.segment1(StopConditions stopOn)
   at Microsoft.XLANGs.Core.SegmentScheduler.RunASegment(Segment s, StopConditions stopCond, Exception& exp)
Microsoft.XLANGs.Core.XlangSoapException

Windows Workflow 4.0 Correlation Example Continued…

Using the sequential workflow built in the previous post, we will continue the correlation example using Windows Workflow 4.0.

The following illustrates the current workflow so far:

image

The concept is the workflow instance will now wait until either an OrderApproval for the same order is received or a specified amount of time elapses.  This is done by using a Pick shape with two branches.  In the screenshot below, note the altered display name properties:

 image

To capture the OrderApproval message, drop a ReceiveAndSendReply shape into the Trigger section of the ApprovalReceived shape.  Set the receive shape’s DisplayName and OperationName to ReceiveApproval and SubmitApproval.  Set the DisplayName of the SendReply shape to AcknowledgeApproval:

image

Next specify the approval message to be received.  This will contain two parameters: the orderNumber to be used to correlate and an OrderApproval object.  Note: specify the Assign To value for the approval parameter.

image

The reply will contain a string to acknowledge the approval was received.  This is specified in the SendReply shape’s Content property:

System.String.Format("Order {0} approval was set to {1} on {2}.", order.OrderNumber, order.Approval.WasApproved, order.Approval.DateApproved)

image

In the ApprovalNotReceived branch, drop a Delay shape in the Trigger section and a TerminateWorkflow shape in the Action section:

image

Change the Delay shape’s properties as follows (for this example, 30 seconds will be the duration to wait until an approval is received):

image

The TerminateWorkflow shape will need an Exception specified and a Reason entered:

System.String.Format("Order {0} was not approved within the Timeout period.", order.OrderNumber)

image

Now to correlate the two messages so the OrderApproval is associated with the initial Order.

First define a new CorrelationHandle variable with the scope of the entire Sequential Service:

image

In the ReceiveNewOrder shape, set the CorrelatesWith property to the corr variable:

image

Initialize the CorrelationHandle by adding the variable in the CorrelationInitializers property:

image

In the XPath Queries section specify to use the value of the Order.OrderNumber received in the message:

image

To associate the OrderApproval message, set the ReceiveApproval’s CorrelatesWith property to use the corr variable:

image

Instead of initializing a new CorrelationHandle, we are going to use the existing handle so set the CorrelatesOn property (note the Query specifies the orderNumber parameter):

image

That’s it.  So run the project to verify the correlation works.

Notice the project now has two endpoints: one for submitting the initial order and one for submitting the approval:

image

Invoke a 101 order and verify the result:

image

Within 30 seconds submit an approval for order 101 (in my example, I did not approve the order):

image

To test the timeout, submit another order and wait 30 seconds.  Now check the Tracked Events in the AppFabric dashboard (it might take a little while before the event is added to monitoring):

image

In the screenshot above, note the Reason is specified in the Errors tab.

Windows Workflow 4.0 Correlation Example

The following is an example of performing correlation using Windows Workflow 4.0.

First create a new project based on the WCF Workflow Service Application template:

image

Because I am interested in tracking the events in AppFabric during development, I will change the projects Web properties to host the service IIS instead of the Visual Studio Development Server:

image

When the settings are saved, create the virtual directory:

image

I renamed the file to be ApprovalService

image

and updated the WorkflowService properties ConfigurationName and Name to ApprovalService. 

image

In this example, I will use two datacontracts: Order and OrderApproval.  The process flow will be as follows:

  1. Order submitted for approval
  2. Workflow waits until either a subsequent OrderApproval is received or the service times out

A new folder named Contracts is created to organise the new contracts:

image

Add two classes: Order and OrderApproval

Note: if your template does not have a reference to System.Runtime.Serialization, then add reference.  You will be able to tell if the DataContract attribute does not resolve with the System.Runtime.Serialization:

image

The Order contract

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Runtime.Serialization;
 
namespace Spike.OrderApproval.Contracts
{
    [DataContract]
    public class OrderApproval
    {
        [DataMember]
        public bool WasApproved { get; set; }
        [DataMember]
        public DateTime DateApproved { get; set; }
    }
}

The OrderApproval contract

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Runtime.Serialization;
 
namespace Spike.OrderApproval.Contracts
{
    [DataContract]
    public class Order
    {
        [DataMember]
        public int OrderNumber { get; set; }
        [DataMember]
        public OrderApproval Approval { get; set; }
    }
}

In the workflow service, add the following variable to represent a received order:

image

On the receive shape, update the DisplayName, OperationName and ServiceContractName as shown below:

image

Set the content of the receive shape to set the order variable to the received payload:

image

Set the content of the SendReply shape to return a string response:

image

To test the service so far, set the ApprovalService.xamlx as the Start Page

image

Run the project by pressing F5, the WCF Test Client should start:

image

Set the payload of the SubmitOrder method and click Invoke

image

The Response should be displayed:

image

Inside of the AppFabric Dashboard, the following events have been tracked:

image

Notice how the Workflow Service properties influence the tracked events.

Continued…

BizTalk 2010 Upgrade Issue

In a BizTalk 2006r2 solution, we encountered a build issue with BizTalk where a map that referenced a particular schema was causing BizTalk to fail to build.  The symptom was that Visual Studio would continually build until it ran out of memory.  The cause of the issue was tracked down to a particular service that was generated from the Entity Framework and contained inter-referencing classes.  Normally this would not cause the issue but EF decorated the contracts in manner that confused the BizTalk build process only if the referenced schema was the source schema. 

At the time, I found a workaround that I thought was clever…

In the map, I set the message type of the source schema to the XLANG Any message.  This would build, and using custom xslt I could achieve what was required.

xsanymap

The upgrade of these maps from 2006r2 to 2009 did not display any issue.  I did notice that a Schema referenced by Map has been deleted error would be displayed if the map was selected in a Receive Location’s Inbound or Outbound Map.  The map would still work in BizTalk 2009.

schemamissing

After upgrading to BizTalk 2010, the Admin Console displays the message on the initial refresh of the BizTalk Group applications and no applications are displayed.  I did find that if I restarted a host instance, the applications would then display in the console. 

The error message in BizTalk 2009 is a annoying but would not affect functionality.  The maps would work at runtime. 

In BizTalk 2010, the maps still work at runtime but the issue in the Admin Console is more severe and prevents functionality from being run.  For instance, if the library with the map is removed from resources, the error message is displayed and no action is applied.  Once a map is deployed with the issue there is not a way to remove it (without hacking the databases). 

The upgrade procedure was reviewed and the issue confirmed by a Microsoft consultant.  The issue is being submitted to the product group to review.

Note: I did try to remove the group and re-connect.
Note: I did try to remove the library via powershell but the same issue was encountered:
schemamissing

SharePoint: Lists.asmx integration and Schema reference “” is not a valid reference

BizTalk integration with SharePoint is … interesting.

Using the Add Generated Items… Consume WCF service might result in a proxy that will not build due to a bad reference. 

errorlist

The proxy file Lists_schemas_microsoft_com_sharepoint_soap.xsd contains the bad reference.

solutionexplorere

The reference in particular is shown below:

remove line

To fix the build, open the file with an XML Editor by right clicking the xsd in solution explorer:

openwith

xmleditor

The edited file should look like the following:

newfile

Calling SharePoint Lists.asmx via BizTalk

Just some notes on connecting BizTalk to SharePoint’s /_vti_bin/lists.asmx”>http://<site>/_vti_bin/lists.asmx webservice.  After using Add Generated Items –> Consume WCF Service to create the proxy and binding you might find that when calling the service a transport level error is returned.

The following illustrates a sample call to a list called Behaviour List for all items:

<MessageLogTraceRecord>

<Addressing xmlns=”http://schemas.microsoft.com/2004/06/ServiceModel/Management/MessageTrace“>

<Action>http://schemas.microsoft.com/sharepoint/soap/GetListItems</Action>

<To>http://<list>/_vti_bin/lists.asmx</To>

</Addressing>

<s:Envelope xmlns:s=”http://schemas.xmlsoap.org/soap/envelope/“>

<s:Header>

<ActivityId CorrelationId=”169ba7fc-dd92-4ba7-9659-b128b63f0e4dxmlns=”http://schemas.microsoft.com/2004/09/ServiceModel/Diagnostics“>2798162c-3223-4ff1-ab14-360c8fa538ab</ActivityId>

</s:Header>

<s:Body>

<soap1:GetListItems xmlns:soap1=”http://schemas.microsoft.com/sharepoint/soap/“>

<soap1:listName>Behaviour List</soap1:listName>

</soap1:GetListItems>

</s:Body>

</s:Envelope>

</MessageLogTraceRecord>

With the generated binding, the following is returned indicating the client bindings are not correct in regards to the security settings:

<MessageLogTraceRecord>

<HttpResponse xmlns=”http://schemas.microsoft.com/2004/06/ServiceModel/Management/MessageTrace“>

<StatusCode>InternalServerError</StatusCode>

<StatusDescription>Internal Server Error</StatusDescription>

<WebHeaders>

<MicrosoftSharePointTeamServices>12.0.0.6318</MicrosoftSharePointTeamServices>

<Content-Length>740</Content-Length>

<Cache-Control>private</Cache-Control>

<Content-Type>text/xml; charset=utf-8</Content-Type>

<Date>Mon, 20 Sep 2010 20:57:03 GMT</Date>

<Server>Microsoft-IIS/6.0</Server>

<X-AspNet-Version>2.0.50727</X-AspNet-Version>

<X-Powered-By>ASP.NET</X-Powered-By>

</WebHeaders>

</HttpResponse>

<soap:Envelope xmlns:soap=”http://schemas.xmlsoap.org/soap/envelope/xmlns:xsi=”http://www.w3.org/2001/XMLSchema-instancexmlns:xsd=”http://www.w3.org/2001/XMLSchema“>

<s:Header xmlns:s=”http://schemas.xmlsoap.org/soap/envelope/“></s:Header>

<soap:Body>

<soap:Fault>

<faultcode xmlns=”">soap:Server</faultcode>

<faultstring xmlns=”">Exception of type ‘Microsoft.SharePoint.SoapServer.SoapServerException’ was thrown.</faultstring>

<detail xmlns=”">

<errorstring xmlns=”http://schemas.microsoft.com/sharepoint/soap/“>A transport-level error has occurred when sending the request to the server. (provider: Shared Memory Provider, error: 0 – Either a required impersonation level was not provided, or the provided impersonation level is invalid.)</errorstring>

</detail>

</soap:Fault>

</soap:Body>

</soap:Envelope>

</MessageLogTraceRecord>

BizTalk logs the following error to the Application eventlog:

The adapter failed to transmit message going to send port “WcfSendPort_Lists_ListsSoap_Custom” with URL “http://<list>/_vti_bin/lists.asmx”. It will be retransmitted after the retry interval specified for this Send Port. Details:”System.ServiceModel.Security.MessageSecurityException: The HTTP request is unauthorized with client authentication scheme ‘Anonymous’. The authentication header received from the server was ‘NTLM’. —> System.Net.WebException: The remote server returned an error: (401) Unauthorized.
   at System.Net.HttpWebRequest.EndGetResponse(IAsyncResult asyncResult)
   at System.ServiceModel.Channels.HttpChannelFactory.HttpRequestChannel.HttpChannelAsyncRequest.CompleteGetResponse(IAsyncResult result)
The adapter failed to transmit message going to send port “WcfSendPort_Lists_ListsSoap_Custom” with URL “http://secure.gen-i.co.nzpublishing/_vti_bin/lists.asmx”. It will be retransmitted after the retry interval specified for this Send Port. Details:”System.InvalidOperationException: An action mapping was defined but BTS.Operation was not found in the message context.
   at Microsoft.BizTalk.Adapter.Wcf.Runtime.WcfClient`2.LookupAction(IBaseMessageContext messageContext)
   at Microsoft.BizTalk.Adapter.Wcf.Runtime.WcfClient`2.SendRequestMessage(IBaseMessage bizTalkMessage, IRequestChannel channel)
   at Microsoft.BizTalk.Adapter.Wcf.Runtime.WcfClient`2.SendMessage(IBaseMessage bizTalkMessage)”.

The solution was to simply set the Impersonation correctly to allow the host instance:

wcf1

wcf2

wcf3

Business Rules Engine: Samples

I recently presented at the Auckland Connected Systems User Group.  In order to prepare, I created several examples of methods of using the rules engine. 

The sample solution is here

Included in the sample solution are:

  • Various Vocabulary definitions including using a function in XPath Field (TotalCostOfOrder)
  • Various Rules definitions including retrieving from a database, using classes, adding XML Nodes to a document, forward chaining and priority
  • Examples implementations of IFactRetriever
  • BizTalk Application showing calling rules with both XML Document and objects
  • BizTalk Application showing an example of using the BRE for routing
  • A WCF Service and Client including an example tracking interceptor

The WCF Service was my focus of the talk and what I wanted to discuss most of all.  I have found using the BRE very beneficial and now that I have spent time understanding it, I believe it helps to make more maintainable solutions by separating the business rules from the application framework.  This allows for the business logic to more accessible and readable than embedded in BizTalk expressions, maps or custom classes. 

Because of this I wanted to illustrate how a WCF service could be strongly typed but not require costly rebuilds when the facts or rules change.  Though I believe strongly in SOA, I am not a fan of the un-typed XML in/XML out design.  To achieve this, I took advantage of the KnownTypes attribute to allow WCF to serialize the payloads and to present metadata.  In the example service, the specific classes are retrieved from the web.config, but there is not any reason why this could not have been retrieved from a more dynamic resource.

Cheers and feedback appreciated.

ACSUG Meeting Thursday November 19th – A Practical exploration of the Business Rules Engine in BizTalk Server

I decided it was about time I presented something at the Auckland Connected User Group

Recently I have been involved with two projects where the Business Rules Engine was exposed as a WCF web service.  Though this is the basis for the presentation, most of the examples will be applicable to using the BRE within BizTalk or externally.

Slides and examples to follow when ready… I better get to work on them…