Contact Us 1-800-596-4880

Microsoft .NET Connector 3.1 Examples - Mule 4

This use case executes the SumOfDigits(System.Int32 number) → System.Int32 method from the DemoDotNet.dll library. The method returns the sum of all digits in the input argument.

The following screenshot shows the Studio app flow for this example:

Studio Flow Diagram
  1. Create a new Mule project in Studio.

  2. In the Mule Palette view, search for http and select the Listener operation.

  3. Drag the Listener operation onto the Studio canvas.

  4. In the Listener configuration, click + next to the Connector configuration field to add a global element.

  5. Set the Host field to localhost.

  6. Click OK.

  7. In the Listener configuration, set the Path field to sumOfDigits.

  8. From the Mule palette view, drag a Transform Message component to right of Listener.

  9. Click Transform Message and set the output as follows:

    dw 2.0
    output application/json
    ---
    {number: payload.num
    }

    This code sets the input argument for the method to execute. It obtains the num param from the payload and assigns it to a new variable called number.

  10. In the Mule Palette view, search for dotnet and drag the Microsoft DotNet > Execute operation onto the Studio canvas, to the right of Transform Message.

  11. In the Execute operation configuration, click + next to the Connector configuration field to add a global element.

  12. In the Scope field, select Singleton.

  13. Click the Assembly tab and enter DemoDotNet.dll in the Path field.

  14. Click OK.

  15. In the Execute operation configuration, enter the following metadata in the Type field:

    DemoDotNet.NumberLibrary, DemoDotNet, Version=1.0.0.0, Culture=neutral, PublicKeyToken=PUBLIC_KEY_TOKEN

    This metadata specifies information about the .NET library to use. Once the connection is established, the connector retrieves the metadata and populates the Method info section, which contains all of the methods exposed by the DemoDotNet.dll library.

    This example shows the SumOfDigits method, which receives the number defined in the payload of the Transform Message component:

    DemoDotNet.NumberLibrary, DemoDotNet, Version=1.0.0.0, Culture=neutral, PublicKeyToken=PUBLIC_KEY_TOKEN | SumOfDigits(System.Int32 number) → System.Int32

  16. From the Mule palette view, drag a second Transform Message component to right of Execute.

  17. Click Transform Message and set the output as follows to transform the result of the Execute operation to Java:

    dw 2.0
    output application/json
    ---
    payload
  18. Save the project.

  19. Test the app by sending a REST request to localhost:8081/sumOfDigits.

Use Case XML

Paste this code into your Studio XML editor to quickly load the flow for this example into your Mule app:

<?xml version="1.0" encoding="UTF-8"?>

<mule xmlns:ee="http://www.mulesoft.org/schema/mule/ee/core"
xmlns:dotnet="http://www.mulesoft.org/schema/mule/dotnet"
xmlns:http="http://www.mulesoft.org/schema/mule/http"
xmlns="http://www.mulesoft.org/schema/mule/core"
xmlns:doc="http://www.mulesoft.org/schema/mule/documentation"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.mulesoft.org/schema/mule/core
http://www.mulesoft.org/schema/mule/core/current/mule.xsd
http://www.mulesoft.org/schema/mule/http
http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd
http://www.mulesoft.org/schema/mule/dotnet
http://www.mulesoft.org/schema/mule/dotnet/current/mule-dotnet.xsd
http://www.mulesoft.org/schema/mule/ee/core
http://www.mulesoft.org/schema/mule/ee/core/current/mule-ee.xsd">
	<http:listener-config name="HTTP_Listener_config"
	doc:name="HTTP Listener config">
	<http:listener-connection host="localhost" port="8081" />
	</http:listener-config>
	<dotnet:dot-net-config name="Microsoft_DotNet" doc:name="Microsoft DotNet">
		<dotnet:resource-connection scope="Singleton" path="DemoDotNet.dll" />
	</dotnet:dot-net-config>
	<flow name="sum-of-digits">
		<http:listener doc:name="Listener"
		config-ref="HTTP_Listener_config"
		path="/sumOfDigits"/>
		<ee:transform doc:name="Transform Message">
			<ee:message >
				<ee:set-payload ><![CDATA[%dw 2.0
output application/json
---
{
	number: payload.num
}]]></ee:set-payload>
			</ee:message>
		</ee:transform>
		<dotnet:execute doc:name="Execute" config-ref="Microsoft_DotNet"
		type="DemoDotNet.NumberLibrary, DemoDotNet, Version=1.0.0.0,
		Culture=neutral, PublicKeyToken=PUBLIC_KEY_TOKEN"
		method="DemoDotNet.NumberLibrary, DemoDotNet, Version=1.0.0.0,
		Culture=neutral,
		PublicKeyToken=PUBLIC_KEY_TOKEN | SumOfDigits(System.Int32 number) -&gt; System.Int32"/>
		<ee:transform doc:name="Transform Message">
			<ee:message >
				<ee:set-payload ><![CDATA[%dw 2.0
output application/json
---
payload]]></ee:set-payload>
			</ee:message>
		</ee:transform>
	</flow>

</mule>
View on GitHub