---
schema_version: "1"
id: 799e73041fdc1453722327e0145f148d0b7e104538d5468191c15802b5f7ec34
title: Web サービスコンシューマー - 例 1
collection: mulesoft
version: current
locale: ja-jp
portal_url: https://docs.salesforce.com/mulesoft/current/ja-jp/web-service-consumer-connector/1.9/web-service-example-1.md
canonical_url: https://docs.mulesoft.com/jp/web-service-consumer-connector/1.9/web-service-example-1
source_site: docs.mulesoft.com
content_type: documentation
content_hash: 52e8cf72eed54c37ad2abc6ff7ac0ed33c885f0aacd301f12cca4baeb4fb453b
description: MuleSoft Documentation Site
release: "1.9"
latest: false
---
# Web サービスコンシューマー - 例 1

次の例では、変数値を XML に変換し、以後 Web サービスをコンシュームする Web サービスコンシューマー用 Anypoint Connector (Web Service Consumer Connector) にその値を渡す方法を示しています。

![Studio キャンバスの Web サービスコンシューマーサンプルフロー](/mulesoft/current/ja-jp/web-service-consumer-connector/1.9/_images/web-service-consumer-example1.png)

## [](#anypoint-studio-で-mule-アプリケーションを作成する)Anypoint Studio で Mule アプリケーションを作成する

Anypoint Studio でフローを作成する手順は、次のとおりです。

1. **\[Mule Palette (Mule パレット)\]**​ ビューで、​**\[Core (コア)\]**​ > ​**\[Scheduler\]**​ を選択します。
2. **Scheduler**​ コンポーネントを Studio キャンバスにドラッグします。  
    **Scheduler**​ コンポーネントは時間ベースの条件が成立した時点でフローを開始します。
3. **\[Display Name (表示名)\]**​ 項目を ​`Scheduler`​ に設定します。
4. **\[Scheduling Strategy (スケジュール戦略)\]**​ を ​`Fixed Frequency`​ に、​**\[Frequency (頻度)\]**​ を ​`1000`​ に、​**\[Start delay (開始遅延)\]**​ を ​`0`​ に、​**\[Time unit (時間単位)\]**​ を ​`MILLISECONDS (Default)`​ に設定します。

Studio での ​**Scheduler**​ 設定は次のようになります。

![Scheduler 設定](/mulesoft/current/ja-jp/web-service-consumer-connector/1.9/_images/web-service-consumer-example2.png)

Figure 1. Scheduler 設定

1. **Set Variable**​ コンポーネントをキャンバスの ​**Scheduler**​ コンポーネントの右にドラッグします。  
    **Set Variable**​ コンポーネントは、フローの公判で XML に変換される変数を作成します。
2. **\[Display Name (表示名)\]**​ 項目を ​`Set Variable`​ に設定します。
3. **\[Name (名前)\]**​ を ​`variableSample`​ に、​**\[Value (値)\]**​ を ​`test`​ に設定します。

Studio での ​**Set Variable**​ 設定は次のようになります。

![Set Variable の設定](/mulesoft/current/ja-jp/web-service-consumer-connector/1.9/_images/web-service-consumer-example3.png)

Figure 2. Set Variable の設定

1. **Transform Message**​ コンポーネントをキャンバスの ​**Set Variable**​ コンポーネントの右にドラッグします。  
    **Transform Message**​ コンポーネントは変数値を XML に変換します。
2. **Transform Message**​ コンポーネント設定の ​**\[Output (出力)\]**​ 項目で、次の DataWeave 式を設定します。
    
    - 変数値の出力を ​`application/xml`​ に変換する。
    - Web Service Consumer Connector が ​`attachOperation`​ で呼び出そうとしている Web サービス操作の名前を定義する。

DataWeave 式

```xml
%dw 2.0
output application/xml
ns con http://service.soap.service.mule.org/
---
con#attachOperation: {
   text: vars.variableSample
}
```

Studio での ​**Transform Message**​ 設定は次のようになります。

![Transform Message の設定](/mulesoft/current/ja-jp/web-service-consumer-connector/1.9/_images/web-service-consumer-example4.png)

Figure 3. Transform Message の設定

1. **\[Consume\]**​ 操作をキャンバスの ​**Transform Message**​ コンポーネントの右にドラッグします。
2. **\[Display Name (表示名)\]**​ 項目を ​`Consume`​ に設定します。
3. **\[Operation (操作)\]**​ を ​`attachOperation`​ に、​**\[Body (本文)\]**​ メッセージを ​`payload`​ に設定します。
4. **\[Advanced (詳細)\]**​ タブの ​**\[Message Customization (メッセージのカスタマイズ)\]**​ セクションで、​**\[Force XML Prolog into body (XML Prolog を本文に強制)\]**​ オプションを有効にして XML prolog をエンベロープの本文 XML のコンテンツに追加します。

Studio での ​**Consume**​ 操作設定は次のようになります。

![Consume 操作設定](/mulesoft/current/ja-jp/web-service-consumer-connector/1.9/_images/web-service-consumer-example5.png)

Figure 4. Consume 操作設定

Studio での ​**XML Prolog**​ 設定は次のようになります。

![本文への XML Prolog の設定](/mulesoft/current/ja-jp/web-service-consumer-connector/1.9/_images/web-service-consumer-xmlprolog.png)

Figure 5. 本文への XML Prolog の設定

1. **\[General (一般)\]**​ タブで、​**\[Connector configuration (コネクタ設定)\]**​ 項目の横にあるプラス記号 (+) をクリックして、​**\[Global Element Properties (グローバル要素のプロパティ)\]**​ 設定にアクセスします。
2. **\[General (一般)\]**​ タブの ​**\[Connection (接続)\]**​ セクションで、次のパラメーターを設定します。
    
    - **WSDL location (WSDL の場所)**​  
        リモートまたはローカル WSDL ファイル URL。
    - **Service (サービス)**​  
        サービス名。
    - **Port (ポート)**​  
        ポート名。
    - **Address (住所)**​  
        要求をディスパッチする Web サーバーのアドレス。ただし、​**\[Service (サービス)\]**​ パラメーターと ​**\[Port (ポート)\]**​ パラメーターで Web サーバーアドレスが自動的に入力されない場合、手動で正しい ​**\[Address (アドレス)\]**​ を指定する必要があります。
3. **\[OK\]**​ をクリックします。

Studio での ​**\[Global Element Properties (グローバル要素のプロパティ)\]**​ 設定は次のようになります。

![Web サービスコンシューマー設定](/mulesoft/current/ja-jp/web-service-consumer-connector/1.9/_images/web-service-consumer-example6.png)

Figure 6. Web サービスコンシューマー設定

1. Studio で変更を保存します。
2. アプリケーションをデプロイします。

## [](#web-サービスのコンシュームの-xml)Web サービスのコンシュームの XML

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

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

<mule xmlns:ee="http://www.mulesoft.org/schema/mule/ee/core" xmlns:wsc="http://www.mulesoft.org/schema/mule/wsc"
	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/wsc http://www.mulesoft.org/schema/mule/wsc/current/mule-wsc.xsd
http://www.mulesoft.org/schema/mule/ee/core http://www.mulesoft.org/schema/mule/ee/core/current/mule-ee.xsd">
	<wsc:config name="Web_Service_Consumer_Config">
		<wsc:connection wsdlLocation="api/attach-demo.wsdl" service="AttachDemo" port="AttachDemoSOAP" address="http://localhost:8085/AttachDemo/AttachDemoSOAP" />
	</wsc:config>
	<flow name="WSC-Example">
		<scheduler>
			<scheduling-strategy >
				<fixed-frequency />
			</scheduling-strategy>
		</scheduler>
		<set-variable value="test" variableName="variableSample"/>
		<ee:transform>
			<ee:message >
				<ee:set-payload ><![CDATA[ %dw 2.0
output application/xml
ns con http://service.soap.service.mule.org/
---
con#attachOperation: {
    text: vars.variableSample
}]]></ee:set-payload>
			</ee:message>
		</ee:transform>
		<wsc:consume config-ref="Web_Service_Consumer_Config" operation="attachOperation">
			<wsc:message-customizations forceXMLProlog="true"/>
		</wsc:consume>
	</flow>
</mule>
```