portType 的 operation 支持4种传输原语:
- in(One-way) 客户端请求
- in-out(Request-response) 客户端请求-服务器端响应
- out-in(Solicit-response) 服务器端向客户端发起请求-客户端给服务器端响应
- out(Notification) 服务器端通知客户端
尽管 WSDL 规范能够支持这四种 operation,但实际上只定义了前两种。
<wsdl:definitions …. >
<wsdl:portType …. > *
<wsdl:operation name=”nmtoken”>
<wsdl:input name=”nmtoken”? message=”qname”/>
</wsdl:operation>
</wsdl:portType >
</wsdl:definitions>
- Request-response Operation
<wsdl:portType …. >
<wsdl:operation name=”nmtoken” parameterOrder=”nmtokens”>
<wsdl:input name=”nmtoken”? message=”qname”/>
<wsdl:output name=”nmtoken”? message=”qname”/>
<wsdl:fault name=”nmtoken” message=”qname”/>*
</wsdl:operation>
</wsdl:portType >
(注意:在 xml 中,?表示该项可以出现一次或者根本不出现)
fault 则用于在服务发生异常时,返回给客户端
request-response operation 需要具体的 binding 来说明消息是怎样被发送的:是一次通信(如http request/response)还是两次独立的通信(即两次request/response)
- Solicit-response Operation
<wsdl:definitions …. >
<wsdl:portType …. > * <!– *表示可以出现0次或多次 –>
<wsdl:operation name=”nmtoken” parameterOrder=”nmtokens”>
<wsdl:output name=”nmtoken”? message=”qname”/>
<wsdl:input name=”nmtoken”? message=”qname”/>
<wsdl:fault name=”nmtoken” message=”qname”/>*
</wsdl:operation>
</wsdl:portType >
</wsdl:definitions>
同样需要具体的 binding 来说明消息是怎样被发送的:是一次通信(如http request/response)还是两次独立的通信(即两次request/response)
<wsdl:definitions …. >
<wsdl:portType …. > * <!– *表示可出现0次或多次 –>
<wsdl:operation name=”nmtoken”>
<wsdl:output name=”nmtoken”? message=”qname”/>
</wsdl:operation>
</wsdl:portType >
</wsdl:definitions>
Operation 的名字
operation 中的 input 或者 output 可以不设置 name,WSLD 将使用默认命名规则:
如果只有 input 或者只有 output,那么这个 input 或者 output 的名称就是它的 operation 的名称;
如果是既有 input 又有 output 或者 既有 output 又有 input,那么input 、output 的名称是 operation 名称加上 Request、Solicit 或者 Response;
fault element 必须自己命名.
Operation 中的参数顺序
Operations 不会说明是否会用于 RPC 样式的 binding. 但是, 如果操作是使用 RPC-binding, 那么(请求的接收方)能够获得原始 RPC 方法签名是非常有用处的. 所以, request-response or solicit-response operation 可以通过 parameterOrder attribute 指定参数名称列表. 在这个列表中, 以一个空白符分隔各 message part 的名字. parameterOrder attribute 必须遵循以下规则:
- 各 part 名称的顺序反映了 RPC 方法签名的参数的顺序
- 在这个列表中并不指定 return 值
- If a part name appears in both the input and output message, it is an in/out parameter
- If a part name appears in only the input message, it is an in parameter
- If a part name appears in only the output message, it is an out parameter
注意: parameterOrder 属性只是一个建议,并不是强制性的,因此有可能被忽略掉,即使使用 RPC-like binding
另外,本篇的例子中, portType只定义了一个operation, 其实是可以定义多个的, 切不可被误导.