---
schema_version: "1"
id: 3d2851de3db5de5d107f90da0451b7ce9ae626eaed9cd194e26a78dd92166c52
title: Microsoft .NET Connector 3.1 の例
collection: mulesoft
version: current
locale: ja-jp
portal_url: https://docs.salesforce.com/mulesoft/current/ja-jp/microsoft-dotnet-connector/latest/microsoft-dotnet-connector-examples.md
canonical_url: https://docs.mulesoft.com/jp/microsoft-dotnet-connector/latest/microsoft-dotnet-connector-examples
source_site: docs.mulesoft.com
content_type: documentation
content_hash: 89b7e09ca7619ce647bcd0ecb782bc962f745aad91e611e815f280db25946976
description: MuleSoft Documentation Site
release: "3.1"
latest: true
---
# Microsoft .NET Connector 3.1 の例

このユースケースでは、​`DemoDotNet.dll`​ ライブラリから ​`SumOfDigits(System.Int32 number) → System.Int32`​ メソッドを実行します。このメソッドは、入力引数内のすべての桁の合計を返します。

次のスクリーンショットは、この例の Studio アプリケーションフローを示しています。

![Listener、Execute 操作、2 つの Transform Message コンポーネントを含む Studio フローの図](/mulesoft/current/ja-jp/microsoft-dotnet-connector/latest/_images/microsoft-dotnet-use-case.png)

1. Studio で新しい Mule プロジェクトを作成します。
2. **\[Mule Palette (Mule パレット)\]**​ ビューで「​`http`​」を検索し、​**\[Listener\]**​ 操作を選択します。
3. **\[Listener\]**​ 操作を Studio キャンバスにドラッグします。
4. **\[Listener\]**​ 設定で、​**\[Connector configuration (コネクタ設定)\]**​ 項目の横にある ​**\[+\]**​ をクリックしてグローバル要素を追加します。
5. **\[Host (ホスト)\]**​ 項目を ​`localhost`​ に設定します。
6. **\[OK\]**​ をクリックします。
7. **\[Listener\]**​ 設定で、​**\[Path (パス)\]**​ 項目を ​`sumOfDigits`​ に設定します。
8. **\[Mule Palette (Mule パレット)\]**​ ビューから、​**\[Transform Message\]**​ コンポーネントを ​**\[Listener\]**​ の右にドラッグします。
9. **\[Transform Message\]**​ をクリックして、出力を次のように設定します。
    
    ```dataweave
    dw 2.0
    output application/json
    ---
    {number: payload.num
    }
    ```
    
    このコードでは、実行するメソッドの入力引数を設定します。ペイロードから ​`num`​ パラメーターを取得して、​`number`​ という新しい変数に割り当てます。
10. **\[Mule Palette (Mule パレット)\]**​ ビューで、​`dotnet`​ を検索し、​**\[Microsoft DotNet\]**​ > ​**\[Execute\]**​ 操作を Studio キャンバスの ​**\[Transform Message\]**​ の右にドラッグします。
11. **Execute**​ 操作の設定で、​**\[Connector configuration (コネクタ設定)\]**​ 項目の横にある ​**\[+\]**​ をクリックしてグローバル要素を追加します。
12. **\[Scope (スコープ)\]**​ 項目で ​`Singleton`​ を選択します。
13. **\[Assembly (アセンブリ)\]**​ タブをクリックし、​**\[Path (パス)\]**​ 項目に「​`DemoDotNet.dll`​」と入力します。
14. **\[OK\]**​ をクリックします。
15. **Execute**​ 操作の設定で、​**\[Type (種別)\]**​ 項目に次のメタデータを入力します。
    
    `DemoDotNet.NumberLibrary, DemoDotNet, Version=1.0.0.0, Culture=neutral, PublicKeyToken=PUBLIC_KEY_TOKEN`
    
    このメタデータでは、使用する .NET ライブラリに関する情報を指定します。接続が確立されると、コネクタはメタデータを取得して、​**\[Method info (メソッド情報)\]**​ セクションに入力します。このセクションには、​`DemoDotNet.dll`​ ライブラリで公開されているすべてのメソッドが含まれます。
    
    この例では、​**Transform Message**​ コンポーネントのペイロードで定義されている数字を受け取る ​`SumOfDigits`​ メソッドが示されています。
    
    `DemoDotNet.NumberLibrary, DemoDotNet, Version=1.0.0.0, Culture=neutral, PublicKeyToken=​PUBLIC_KEY_TOKEN​ | SumOfDigits(System.Int32 number) → System.Int32`
16. **\[Mule palette (Mule パレット)\]**​ ビューから、2 番目の ​**\[Transform Message\]**​ コンポーネントを ​**\[Execute\]**​ の右にドラッグします。
17. **\[Transform Message\]**​ をクリックし、出力を次のように設定して、​**Execute**​ 操作の結果を Java に変換します。
    
    ```dataweave
    dw 2.0
    output application/json
    ---
    payload
    ```
18. プロジェクトを保存します。
19. REST 要求を ​`localhost:8081/sumOfDigits`​ に送信して、アプリケーションをテストします。

## [](#ユースケース-xml)ユースケース: XML

この例のフローをすばやく Mule アプリケーションに読み込むには、次のコードを Studio XML エディターに貼り付けます。

```xml
<?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>
```

## [](#関連情報)関連情報

- [Anypoint Connector の概要](https://docs.mulesoft.com/connectors/introduction/introduction-to-anypoint-connectors)
- [MuleSoft ヘルプセンター](https://help.mulesoft.com)