追加の Web サービス・パラメーターを指定してから、これらのパラメーターの値を渡すことによって、追加の制御情報または監査情報を Web サービスに渡すことができます。 プロジェクトの「プロパティー」ウィンドウの「Web サービス」ページまたは「Web サービスのデプロイ」ウィザードに表示される、「パラメーター」表でパラメーターを指定します。
渡される値は、メッセージが要求する操作に対してのみ適用されます。 これらは、複数のメッセージあるいは操作にまたがることはありません。
Web サービスにパラメーターを追加するには、次のようにします。
データ開発プロジェクト内のすべての Web サービスについて、データベース接続プロパティー clientUser を設定するとします。プロジェクト・ノードを右クリックし、「プロパティー」を選択します。 「プロパティー」ウィンドウで、「Web サービス」を選択します。「パラメーター」表の隣にある「Web サービス (Web Services)」ページで、「新規」をクリックして行を表に追加します。新規の行の「名前」列で、connection.jcc.clientUser と入力します。
SOAP ヘッダーを使用した Apache Axis2 生成コードの例
package myClientTest;
import example.WebService2Stub;
public class getEmployee {
public static void main(String args[]) {
try {
// create the stub
WebService2Stub stub = new WebService2Stub("http://localhost:8000/WebService2/services/WebService2");
// create the request elment for SOAP body
WebService2Stub.GetEmployee empRequest = new WebService2Stub.GetEmployee();
// fill request with employee number
empRequest.setEmpno("000130");
// create the Header for the request element
WebService2Stub.ConnectionProperties properties = new WebService2Stub.ConnectionProperties();
WebService2Stub.ConnectionPropertiesType propertiesType = new WebService2Stub.ConnectionPropertiesType();
properties.setConnectionProperties(propertiesType);
// fill the header with properties
WebService2Stub.Property_type0 property1 = new WebService2Stub.Property_type0();
property1.setName("connection.jcc.clientUser");
property1.setValue("heathr");
propertiesType.addProperty(property1);
WebService2Stub.GetEmployeeResponse response = stub.getEmployee(empRequest, properties);
//...
} catch (Exception e) {
System.err.println(e.toString());
}
}
}
以下は、コードによって生成される SOAP 要求です。
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Header>
<ns1:connectionProperties xmlns:ns1="urn:example">
<property name="connection.jcc.clientUser" value="heathr"/>
</ns1:connectionProperties>
</soapenv:Header>
<soapenv:Body>
<ns1:getEmployee xmlns:ns1="urn:example">
<empno>000130</empno>
</ns1:getEmployee>
</soapenv:Body>
</soapenv:Envelope>
以下は、REST に類似した HTTP GET (URL エンコード) を使用する入力メッセージの例です。
GET /Project1WebService2/rest/WebService2/getEmployee?empno=000130&_connection.jcc.clientUser=heathr HTTP/1.1
User-Agent: Java/1.5.0
Host: localhost:8070
Accept: text/html, image/gif, image/jpeg, *; q=.2, */*; q=.2
Connection: keep-alive
Content-type: application/x-www-form-urlencoded
要求の結果の URL は次のようになります。 この URL は、すべての HTTP バインディングで使用できます。
http://localhost:8080/Project1WebService2/rest/WebService2/getEmployee?empno=000130&_connection.jcc.clientUser=heathr