No Results
Search Tips:
- Please consider misspellings
- Try different search keywords
生成されるコードについて
次の例では、WSDL ドキュメントから Apex クラスがどのように作成されるかを示します。Apex クラスは、WSDL をインポートすると自動生成されます。次のコードは、サンプル WSDL ドキュメントを示します。
1swfobject.registerObject("clippy.codeblock-0", "9");<wsdl:definitions xmlns:http="http://schemas.xmlsoap.org/wsdl/http/"
2xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
3xmlns:s="http://www.w3.org/2001/XMLSchema"
4xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/"
5xmlns:tns="http://doc.sample.com/docSample"
6targetNamespace="http://doc.sample.com/docSample"
7xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/">
8
9<!-- Above, the schema targetNamespace maps to the Apex class name. -->
10
11
12<!-- Below, the type definitions for the parameters are listed.
13 Each complexType and simpleType parameteris mapped to an Apex class inside the parent class for the WSDL. Then, each element in the complexType is mapped to a public field inside the class. -->
14
15<wsdl:types>
16<s:schema elementFormDefault="qualified"
17targetNamespace="http://doc.sample.com/docSample">
18<s:element name="EchoString">
19<s:complexType>
20<s:sequence>
21<s:element minOccurs="0" maxOccurs="1" name="input" type="s:string" />
22</s:sequence>
23</s:complexType>
24</s:element>
25<s:element name="EchoStringResponse">
26<s:complexType>
27<s:sequence>
28<s:element minOccurs="0" maxOccurs="1" name="EchoStringResult"
29type="s:string" />
30</s:sequence>
31</s:complexType>
32</s:element>
33</s:schema>
34</wsdl:types>
35
36<!--The stub below defines operations. -->
37
38<wsdl:message name="EchoStringSoapIn">
39<wsdl:part name="parameters" element="tns:EchoString" />
40</wsdl:message>
41<wsdl:message name="EchoStringSoapOut">
42<wsdl:part name="parameters" element="tns:EchoStringResponse" />
43</wsdl:message>
44<wsdl:portType name="DocSamplePortType">
45<wsdl:operation name="EchoString">
46<wsdl:input message="tns:EchoStringSoapIn" />
47<wsdl:output message="tns:EchoStringSoapOut" />
48</wsdl:operation>
49</wsdl:portType>
50
51<!--The code below defines how the types map to SOAP. -->
52
53<wsdl:binding name="DocSampleBinding" type="tns:DocSamplePortType">
54<wsdl:operation name="EchoString">
55<soap:operation soapAction="urn:dotnet.callouttest.soap.sforce.com/EchoString"
56style="document" />
57<wsdl:input>
58<soap:body use="literal" />
59</wsdl:input>
60<wsdl:output>
61<soap:body use="literal" />
62</wsdl:output>
63</wsdl:operation>
64</wsdl:binding>
65
66<!-- Finally, the code below defines the endpoint, which maps to the endpoint in the class -->
67
68<wsdl:service name="DocSample">
69<wsdl:port name="DocSamplePort" binding="tns:DocSampleBinding">
70<soap:address location="http://YourServer/YourService" />
71</wsdl:port>
72</wsdl:service>
73</wsdl:definitions>
74
75この WSDL ドキュメントから、次の Apex クラスが自動生成されます。クラス名 docSample は、WSDL をインポートしたときに指定した名前です。
1swfobject.registerObject("clippy.codeblock-1", "9");//Generated by wsdl2apex
2
3public class docSample {
4
5 public class EchoStringResponse_element {
6
7 public String EchoStringResult;
8
9 private String[] EchoStringResult_type_info = new String[]{
10 'EchoStringResult',
11 'http://www.w3.org/2001/XMLSchema',
12 'string','0','1','false'};
13
14 private String[] apex_schema_type_info = new String[]{
15 'http://doc.sample.com/docSample',
16 'true'};
17
18 private String[] field_order_type_info = new String[]{
19 'EchoStringResult'};
20 }
21
22 public class DocSamplePort {
23
24 public String endpoint_x = 'http://YourServer/YourService';
25
26 private String[] ns_map_type_info = new String[]{
27 'http://doc.sample.com/docSample',
28 'docSample'};
29
30 public String EchoString(String input) {
31 docSample.EchoString_element request_x =
32 new docSample.EchoString_element();
33 docSample.EchoStringResponse_element response_x;
34 request_x.input = input;
35 Map<String, docSample.EchoStringResponse_element> response_map_x =
36 new Map<String, docSample.EchoStringResponse_element>();
37 response_map_x.put('response_x', response_x);
38 WebServiceCallout.invoke(
39 this,
40 request_x,
41 response_map_x,
42 new String[]{endpoint_x,
43 'urn:dotnet.callouttest.soap.sforce.com/EchoString',
44 'http://doc.sample.com/docSample',
45 'EchoString',
46 'http://doc.sample.com/docSample',
47 'EchoStringResponse',
48 'docSample.EchoStringResponse_element'}
49 );
50 response_x = response_map_x.get('response_x');
51 return response_x.EchoStringResult;
52 }
53 }
54
55 public class EchoString_element {
56
57 public String input;
58 private String[] input_type_info = new String[]{
59 'input',
60 'http://www.w3.org/2001/XMLSchema',
61 'string','0','1','false'};
62 private String[] apex_schema_type_info = new String[]{
63 'http://doc.sample.com/docSample',
64 'true'};
65 private String[] field_order_type_info = new String[]{'input'};
66 }
67}元の WSDL ドキュメントからの次の対応付けに注意してください。
- WSDL 対象名前空間は Apex クラス名に対応付けされます。
- 複雑なデータ型はクラスになります。データ型の各要素は、クラスの公開項目です。
- WSDL ポート名はスタブクラスに対応付けます。
- WSDL の各操作は、公開メソッドに対応付けます。
上記で生成されたクラスを使用して、外部 Web サービスを呼び出すことができます。次のコードは、外部サーバ上の echoString メソッドをコールする方法を示します。
1docSample.DocSamplePort stub = new docSample.DocSamplePort();
2String input = 'This is the input string';
3String output = stub.EchoString(input);