Web-методы

Теперь давайте, наконец, создадим несколько Web-методов для тестирования, которое будет описано в следующем разделе. Для начала нужно создать одну хранимую процедуру с output-параметром и одну функцию (ну, не нашлось в базе данных Northwind таковых). Вот скрипт их создания:

Хранимая процедура:

create proc test_output @i int outasset @i = 10

UDF:

create function test_ret_func()returns intasbegin return 1010end

Теперь щелкните на кнопке с тремя точками (см. рисунок 2). Перед вами должно появится диалоговое окошко, изображенное на рисунке 3.


Рисунок 3. Хранимые процедуры и функции базы данных Northwind.

Выберите из списка: CustOrderHist, test_output и test_ret_func.

После нажатия кнопки ОК, в доселе пустом WSDL-файле, в разделе types схемы http://dcit06/srv/webserv должно появиться следующее:

<xsd:element name="CustOrderHist"> <xsd:complexType> <xsd:sequence> <xsd:element minOccurs="0" maxOccurs="1" name="CustomerID" type="xsd:string" nillable="true"/> </xsd:sequence> </xsd:complexType> </xsd:element> <xsd:element name="CustOrderHistResponse"> <xsd:complexType> <xsd:sequence> <xsd:element minOccurs="1" maxOccurs="1" name="CustOrderHistResult" type="sqlresultstream:SqlResultStream"/> </xsd:sequence> </xsd:complexType> </xsd:element> <xsd:element name="test_output"> <xsd:complexType> <xsd:sequence> <xsd:element minOccurs="0" maxOccurs="1" name="i" type="xsd:int" nillable="true"/> </xsd:sequence> </xsd:complexType> </xsd:element> <xsd:element name="test_outputResponse"> <xsd:complexType> <xsd:sequence> <xsd:element minOccurs="1" maxOccurs="1" name="test_outputResult" type="sqlresultstream:SqlResultStream"/> <xsd:element name="i" type="xsd:int" nillable="true"/> </xsd:sequence> </xsd:complexType> </xsd:element> <xsd:element name="test_ret_func"> <xsd:complexType> <xsd:sequence/> </xsd:complexType> </xsd:element> <xsd:element name="test_ret_funcResponse"> <xsd:complexType> <xsd:sequence> <xsd:element name="returnValue" type="xsd:int" nillable="true"/> </xsd:sequence> </xsd:complexType> </xsd:element>

Это описания используемых типов элементов, с помощью которых происходит формирование soap-конверта.

Описания параметров выбранных методов (CustOrderHist, test_output и test_ret_func) должны появиться в соответствующих секциях message wsdl-документа.

<wsdl:message name="CustOrderHistIn"> <wsdl:part name="parameters" element="tns:CustOrderHist"/></wsdl:message><wsdl:message name="CustOrderHistOut"> <wsdl:part name="parameters" element="tns:CustOrderHistResponse"/></wsdl:message><wsdl:message name="test_outputIn"> <wsdl:part name="parameters" element="tns:test_output"/></wsdl:message><wsdl:message name="test_outputOut"> <wsdl:part name="parameters" element="tns:test_outputResponse"/></wsdl:message><wsdl:message name="test_ret_funcIn"> <wsdl:part name="parameters" element="tns:test_ret_func"/></wsdl:message><wsdl:message name="test_ret_funcOut"> <wsdl:part name="parameters" element="tns:test_ret_funcResponse"/></wsdl:message>

И, наконец, сами методы появляются в секции portType.

<wsdl:portType name="SXSPort"> <wsdl:operation name="CustOrderHist"> <wsdl:input message="tns:CustOrderHistIn"/> <wsdl:output message="tns:CustOrderHistOut"/> </wsdl:operation> <wsdl:operation name="test_output"> <wsdl:input message="tns:test_outputIn"/> <wsdl:output message="tns:test_outputOut"/> </wsdl:operation> <wsdl:operation name="test_ret_func"> <wsdl:input message="tns:test_ret_funcIn"/> <wsdl:output message="tns:test_ret_funcOut"/> </wsdl:operation></wsdl:portType>

Как видите, SQLXML принял решение, что все операции будут идти по сценарию запрос/ответ, о чем свидетельствуют теги input/output каждой операции.

СОВЕТ Возможно, вас не устроят названия секций, которые выбирает SQLXML. SXS – это, скорее всего, акроним от SQL Server Xml Support. Вы вправе дать всем элементами WSDL-файла свои собственные названия. Это совершенно не повлияет на работоспособность Web-сервиса. Правда, после следующей настройки с помощью консоли, все имена будут исправлены на стандартные.

Что ж, теперь все готово к тестированию.