---
schema_version: "1"
id: aa72142cc34e04cf7ef68e0e0888a13a9266e670f9e827ceefdc2ebd46cc4189
title: SOAP ヘッダーの設定
collection: mulesoft
version: current
locale: ja-jp
portal_url: https://docs.salesforce.com/mulesoft/current/ja-jp/apikit/latest/apikit-4-set-header-task.md
canonical_url: https://docs.mulesoft.com/jp/apikit/latest/apikit-4-set-header-task
source_site: docs.mulesoft.com
content_type: documentation
content_hash: f178eaacd5a1c8eed0af239aa59a38cfe6fb019519934523927874794966a5a8
description: MuleSoft Documentation Site
release: 4.x
latest: true
---
# SOAP ヘッダーの設定

APIkit を使用して、WSDL 宣言に基づいて、アプリケーションの応答にヘッダーを追加します。

この例を実行するには、​`tshirt2.wsdl`​ API 定義をダウンロードして、それに基づいて Mule アプリケーションを作成する必要があります。  
詳細は、​[「APIkit for SOAP を使用する場合の前提条件」](https://docs.mulesoft.com/jp/apikit/latest/apikit-4-soap-prerequisites-task)​と​[「APIkit for SOAP プロジェクトの作成」](https://docs.mulesoft.com/jp/apikit/latest/apikit-4-soap-project-task)​を参照してください。

次の例では、アプリケーションの応答に ​`APIUsageInformation`​ ヘッダーを追加しています。

1. Anypoint Studio で、​`src/main/resources/api`​ の ​`tshirt2.wsdl`​ を開き、コントラクトで必要な ​`APIUsageInformation`​ 要素までスクロールします。
2. キャンバスで、​`OrderTshirt:/soapkit-config`​ フローの ​`Transform Message`​ コンポーネントを選択します。
    
    次の DataWeave コードを使用できます。
    
    ```linenums
    {
    	body : {
    		ns0#OrderTshirtResponse: {
    			orderId: "I got a request from "
    			++ payload.body.ns0#OrderTshirt.name
    			++ " using the following auth header "
    			++ (payload.headers["AuthenticationHeader"].ns0#AuthenticationHeader.apiKey default "")
    		}
    	} write "application/xml"
    }
    ```
3. `APIUsageInformation`​ ヘッダー宣言を追加します。
    
    ```linenums
    {
    	body : {
    		ns0#OrderTshirtResponse: {
    			orderId: "I got a request from "
    			++ payload.body.ns0#OrderTshirt.name
    			++ " using the following auth header "
    			++ (payload.headers["AuthenticationHeader"].ns0#AuthenticationHeader.apiKey default "")
    		}
    	} write "application/xml",
    
    	headers: { (1)
    		header: {
    			ns0#APIUsageInformation: {
    			}
    		} write "application/xml"
    	}
    
    }
    ```
    
    <table><tbody><tr><td><i class="conum" data-value="1"></i><b>1</b></td><td>この DataWeave コードは、​<code>Transform Message</code>​ コンポーネントで生成される出力にヘッダーを追加します。</td></tr></tbody></table>
4. `apiCallsRemaining`​ ヘッダーを ​`APIUsageInformation`​ 要素に追加します。
    
    {
    	body : {
    		ns0#OrderTshirtResponse: {
    			orderId: "I got a request from "
    			++ payload.body.ns0#OrderTshirt.name
    			++ " using the following auth header "
    			++ (payload.headers\["AuthenticationHeader"\].ns0#AuthenticationHeader.apiKey default "")
    		}
    	} write "application/xml",
    
    	headers: {
    		header: {
    			ns0#APIUsageInformation: {
    				apiCallsRemaining: 10 **(1)**
    			}
    		} write "application/xml"
    	}
    
    }
    
    <table><tbody><tr><td><i class="conum" data-value="1"></i><b>1</b></td><td><code>apiCallsRemaining</code>​ を ​<code>10</code>​ に設定します。</td></tr></tbody></table>
5. 保存してプロジェクトをもう一度実行します。
6. SoapUI で、​`OrderTshirt`​ 要求をもう一度実行します。
    
    APIkit for SOAP の応答エンベロープは次のようになります。

```xml
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
   <soap:Header>
      <ns0:APIUsageInformation xmlns:ns0="http://mulesoft.org/tshirt-service">
         <apiCallsRemaining>10</apiCallsRemaining>
      </ns0:APIUsageInformation>
   </soap:Header>
   <soap:Body>
      <ns0:OrderTshirtResponse xmlns:ns0="http://mulesoft.org/tshirt-service">
         <orderId>I got a request from John, using the following auth header 987654321</orderId>
      </ns0:OrderTshirtResponse>
   </soap:Body>
</soap:Envelope>
```

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

- [APIkit for SOAP Module リファレンス](https://docs.mulesoft.com/jp/apikit/latest/apikit-for-soap-module-reference)