Share via


Contract

服務合約會攜帶元數據,定義服務如何處理通道訊息。

WS_SERVICE_CONTRACT會攜帶服務的元數據來處理WS_MESSAGE

Diagram showing WS_SERVICE_CONTRACT metadata in a message to a service endpoint.

它有WS_CONTRACT_DESCRIPTION和函式數據表。 應用程式可以選擇性地指定 WS_SERVICE_MESSAGE_RECEIVE_CALLBACK

如果未指定WS_CONTRACT_DESCRIPTION和函式數據表,則應用程式必須指定WS_SERVICE_MESSAGE_RECEIVE_CALLBACK

Diagram showing the Add and Subtract service operations in the ICalculator service contract.

static WS_SERVICE_CONTRACT calculatorContract = 
{
    &calculatorContractDescription, 
    NULL, 
    &calculatorFunctions, 
};

如需詳細資訊, 請參閱計算機 範例。

合約描述

WS_CONTRACT_DESCRIPTION是定義服務類型合約的元數據。 由 wsutil.exe 產生。

就 WSDL 而言, WS_CONTRACT_DESCRIPTION 會對應至 wsdl:portType。 針對 WSDL 檔中的每個 wsdl:portType,將會產生個別 的WS_CONTRACT_DESCRIPTION

合約描述是由一或多個 服務作業所組成。 這些作業會以WS_OPERATION_DESCRIPTION數位的形式提供。

Diagram showing a WS_CONTRACT_DESCRIPTION as an array of WS_OPERATION_DESCRIPTIONs.

<wsdl:definitions xmlns:soap="https://schemas.xmlsoap.org/wsdl/soap/" 
xmlns:wsu="https://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" 
xmlns:soapenc="https://schemas.xmlsoap.org/soap/encoding/" xmlns:tns="https://Example.org" 
xmlns:wsa="https://schemas.xmlsoap.org/ws/2004/08/addressing" xmlns:wsp="https://schemas.xmlsoap.org/ws/2004/09/policy" 
xmlns:wsap="https://schemas.xmlsoap.org/ws/2004/08/addressing/policy" xmlns:xsd="https://www.w3.org/2001/XMLSchema" 
xmlns:msc="http://schemas.microsoft.com/ws/2005/12/wsdl/contract" xmlns:wsaw="https://www.w3.org/2006/05/addressing/wsdl" 
xmlns:soap12="https://schemas.xmlsoap.org/wsdl/soap12/" xmlns:wsa10="https://www.w3.org/2005/08/addressing" 
xmlns:wsx="https://schemas.xmlsoap.org/ws/2004/09/mex" targetNamespace="https://Example.org" 
xmlns:wsdl="https://schemas.xmlsoap.org/wsdl/">
 <wsdl:portType name="ICalculator">
  <wsdl:operation name="Add">
   <wsdl:input wsaw:Action="https://Example.org/ICalculator/Add" 
   message="tns:ICalculator_Add_InputMessage" />
   <wsdl:output wsaw:Action="https://Example.org/ICalculator/AddResponse" 
   message="tns:ICalculator_Add_OutputMessage" />
  </wsdl:operation>
 </wsdl:portType>
</wsdl:definitions>

如需 wsdl:portType WS_CONTRACT_DESCRIPTION轉換的詳細數據,請參閱 WSDL 輸出一節。

範例: WS_CONTRACT_DESCRIPTION

static WS_CONTRACT_DESCRIPTION contractDescriptionICalculator =
{
    WsCountOf(serviceOperationsICalculator),
    serviceOperationsICalculator
};

函式數據表

函式數據表是函式指標的結構,代表 服務合約中的每個服務作業 。 函式數據表定義也由 wsutil.exe 產生。

範例:函式數據表

 // Function Table
struct CalculatorServiceFunctionTable
{
      AddOperation Add;
      SubtractOperation Subtract;
};

// Populate the Function Table
static const CalculatorServiceFunctionTable calculatorFunctions = {Add, Subtract};

使用 WS_SERVICE_MESSAGE_RECEIVE_CALLBACK

WS_SERVICE_MESSAGE_RECEIVE_CALLBACK具有雙重互斥角色。

如果在WS_SERVICE_CONTRACT指定WS_CONTRACT_DESCRIPTION,這會成為指定WS_CONTRACT_DESCRIPTION不支援的所有動作的預設訊息處理程式。 否則,如果未在WS_SERVICE_CONTRACT上指定WS_CONTRACT_DESCRIPTION,且WS_SERVICE_MESSAGE_RECEIVE_CALLBACK會在WS_SERVICE_CONTRACT上指定所有傳入的訊息都會傳遞至此回呼。

如需更多範例,請參閱

下列回呼是合約的一部分:

下列結構是合約的一部分: