WCF 웹 HTTP 서비스 도움말 페이지
.NET Framework 4.6.1은 WCF WEB HTTP 서비스에 대한 자동 도움말 페이지를 제공합니다. 이 도움말 페이지에는 각 작업에 대한 설명, 요청 및 응답 형식, 스키마 등이 표시됩니다. 이 기능은 기본적으로 사용하지 않도록 설정되어 있습니다. 사용자가 WCF WEB HTTP 서비스를 탐색하고 URL 끝에 "/Help"를 추가하면(예: http://localhost:8000/Customers/Help
) 다음과 같은 도움말 페이지가 표시됩니다.
사용자가 이 도움말 페이지에 나열된 메서드를 클릭하면 메시지 형식과 예제 응답 등 메서드에 대한 자세한 내용을 보여 주는 해당 작업에 대한 상세 페이지가 표시됩니다. 다음 그림은 메서드에 대한 도움말 페이지의 예제입니다.
WCF 웹 HTTP 도움말 페이지 사용
WCF 웹 HTTP 도움말 페이지에는 DescriptionAttribute를 사용하여 지정한 작업에 대한 간략한 설명이 표시됩니다. 이 특성은 해당 특성이 적용되는 작업에 대한 간략한 설명이 포함된 문자열을 제공합니다. 예를 들어 다음 코드에서는 DescriptionAttribute를 사용하여 간략한 설명을 제공하는 방법을 보여 줍니다.
[OperationContract]
[WebGet(UriTemplate="/template1", BodyStyle = WebMessageBodyStyle.Bare)]
[Description("Description for GET /template1")]
SyndicationFeedFormatter GetTemplate1();
WCF 웹 HTTP 도움말 페이지를 사용하도록 설정하려면 서비스의 엔드포인트에 엔드포인트 동작을 추가해야 합니다. 이 작업은 구성 또는 코드에서 수행할 수 있습니다. 구성에서 WCF 웹 HTTP 도움말 페이지를 사용하도록 설정하려면 <webHttp>
요소를 사용하여 엔드포인트 동작을 추가하고 helpEnabled
를 true
로 설정합니다. 그런 다음 엔드포인트를 추가하고 방금 추가한 엔드포인트 동작을 사용하도록 구성합니다. 다음 구성 코드에서는 이 작업을 수행하는 방법을 보여 줍니다.
<endpointBehaviors>
<behavior name="RESTEndpointBehavior">
<webHttp helpEnabled="true"/>
</behavior>
</endpointBehaviors>
<!-- ... -->
<services>
<service behaviorConfiguration="RESTWebServiceBehavior" name="RESTWebService"> <endpoint address="" kind="webHttpEndpoint" behaviorConfiguration="RESTEndpointBehavior" contract="IHello" />
<!-- ... -->
</service>
</services>
코드에서 WCF 웹 HTTP 도움말 페이지를 사용하도록 설정하려면 서비스 엔드포인트를 추가하고 WebHttpBehavior를 HelpEnabled로 설정한 다음 서비스 엔드포인트에 true
를 추가합니다. 다음 코드에서는 이 작업을 수행하는 방법을 보여 줍니다.
using (WebServiceHost host = new WebServiceHost(typeof(Service), new Uri("http://localhost:8000/Customers")))
{
host.AddServiceEndpoint(typeof(ICustomerCollection), new WebHttpBinding(), "");
host.Description.Endpoints[0].Behaviors.Add(new WebHttpBehavior { EnableHelp = true });
// ...
}
도움말 페이지는 해당 페이지의 여러 부분을 식별하는 태그가 포함된 XHTML을 기반으로 하기 때문에 클라이언트에서 XElement 또는 다른 XLinq API를 사용하여 프로그래밍 방식으로 액세스할 수 있습니다.
WCF 웹 HTTP 서비스 도움말 페이지에 사용되는 스키마
다음은 WCF 웹 HTTP 서비스 도움말 페이지에 사용되는 스키마입니다.
<?xml version="1.0" encoding="utf-16"?>
<xs:schema xmlns:tns="http://schemas.microsoft.com/2003/10/Serialization/" attributeFormDefault="qualified" elementFormDefault="qualified" targetNamespace="http://schemas.microsoft.com/2003/10/Serialization/" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="anyType" nillable="true" type="xs:anyType" />
<xs:element name="anyURI" nillable="true" type="xs:anyURI" />
<xs:element name="base64Binary" nillable="true" type="xs:base64Binary" />
<xs:element name="boolean" nillable="true" type="xs:boolean" />
<xs:element name="byte" nillable="true" type="xs:byte" />
<xs:element name="dateTime" nillable="true" type="xs:dateTime" />
<xs:element name="decimal" nillable="true" type="xs:decimal" />
<xs:element name="double" nillable="true" type="xs:double" />
<xs:element name="float" nillable="true" type="xs:float" />
<xs:element name="int" nillable="true" type="xs:int" />
<xs:element name="long" nillable="true" type="xs:long" />
<xs:element name="QName" nillable="true" type="xs:QName" />
<xs:element name="short" nillable="true" type="xs:short" />
<xs:element name="string" nillable="true" type="xs:string" />
<xs:element name="unsignedByte" nillable="true" type="xs:unsignedByte" />
<xs:element name="unsignedInt" nillable="true" type="xs:unsignedInt" />
<xs:element name="unsignedLong" nillable="true" type="xs:unsignedLong" />
<xs:element name="unsignedShort" nillable="true" type="xs:unsignedShort" />
<xs:element name="char" nillable="true" type="tns:char" />
<xs:simpleType name="char">
<xs:restriction base="xs:int" />
</xs:simpleType>
<xs:element name="duration" nillable="true" type="tns:duration" />
<xs:simpleType name="duration">
<xs:restriction base="xs:duration">
<xs:pattern value="\-?P(\d*D)?(T(\d*H)?(\d*M)?(\d*(\.\d*)?S)?)?" />
<xs:minInclusive value="-P10675199DT2H48M5.4775808S" />
<xs:maxInclusive value="P10675199DT2H48M5.4775807S" />
</xs:restriction>
</xs:simpleType>
<xs:element name="guid" nillable="true" type="tns:guid" />
<xs:simpleType name="guid">
<xs:restriction base="xs:string">
<xs:pattern value="[\da-fA-F]{8}-[\da-fA-F]{4}-[\da-fA-F]{4}-[\da-fA-F]{4}-[\da-fA-F]{12}" />
</xs:restriction>
</xs:simpleType>
<xs:attribute name="FactoryType" type="xs:QName" />
<xs:attribute name="Id" type="xs:ID" />
<xs:attribute name="Ref" type="xs:IDREF" />
</xs:schema>
<?xml version="1.0" encoding="utf-16"?>
<xs:schema xmlns:tns="http://microsoft.com/wsdl/types/" elementFormDefault="qualified" targetNamespace="http://microsoft.com/wsdl/types/" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:simpleType name="guid">
<xs:restriction base="xs:string">
<xs:pattern value="[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}" />
</xs:restriction>
</xs:simpleType>
<xs:simpleType name="char">
<xs:restriction base="xs:unsignedShort" />
</xs:simpleType>
</xs:schema>
<?xml version="1.0" encoding="utf-16"?>
<xs:schema xmlns:tns="http://schemas.datacontract.org/2004/07/System" elementFormDefault="qualified" targetNamespace="http://schemas.datacontract.org/2004/07/System" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:import namespace="http://schemas.microsoft.com/2003/10/Serialization/" />
<xs:complexType name="DateTimeOffset">
<xs:annotation>
<xs:appinfo>
<IsValueType xmlns="http://schemas.microsoft.com/2003/10/Serialization/">true</IsValueType>
</xs:appinfo>
</xs:annotation>
<xs:sequence>
<xs:element name="DateTime" type="xs:dateTime" />
<xs:element name="OffsetMinutes" type="xs:short" />
</xs:sequence>
</xs:complexType>
<xs:element name="DateTimeOffset" nillable="true" type="tns:DateTimeOffset" />
<xs:complexType name="DBNull">
<xs:sequence />
</xs:complexType>
<xs:element name="DBNull" nillable="true" type="tns:DBNull" />
</xs:schema>
<?xml version="1.0" encoding="utf-16"?>
<xs:schema xmlns:tns="http://schemas.microsoft.com/2003/10/Serialization/Arrays" xmlns:ser="http://schemas.microsoft.com/2003/10/Serialization/" elementFormDefault="qualified" targetNamespace="http://schemas.microsoft.com/2003/10/Serialization/Arrays" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:import namespace="http://schemas.microsoft.com/2003/10/Serialization/" />
<xs:complexType name="ArrayOfboolean">
<xs:sequence>
<xs:element minOccurs="0" maxOccurs="unbounded" name="boolean" type="xs:boolean" />
</xs:sequence>
</xs:complexType>
<xs:element name="ArrayOfboolean" nillable="true" type="tns:ArrayOfboolean" />
<xs:complexType name="ArrayOfchar">
<xs:sequence>
<xs:element minOccurs="0" maxOccurs="unbounded" name="char" type="ser:char" />
</xs:sequence>
</xs:complexType>
<xs:element name="ArrayOfchar" nillable="true" type="tns:ArrayOfchar" />
<xs:complexType name="ArrayOfdateTime">
<xs:sequence>
<xs:element minOccurs="0" maxOccurs="unbounded" name="dateTime" type="xs:dateTime" />
</xs:sequence>
</xs:complexType>
<xs:element name="ArrayOfdateTime" nillable="true" type="tns:ArrayOfdateTime" />
<xs:complexType name="ArrayOfdecimal">
<xs:sequence>
<xs:element minOccurs="0" maxOccurs="unbounded" name="decimal" type="xs:decimal" />
</xs:sequence>
</xs:complexType>
<xs:element name="ArrayOfdecimal" nillable="true" type="tns:ArrayOfdecimal" />
<xs:complexType name="ArrayOfdouble">
<xs:sequence>
<xs:element minOccurs="0" maxOccurs="unbounded" name="double" type="xs:double" />
</xs:sequence>
</xs:complexType>
<xs:element name="ArrayOfdouble" nillable="true" type="tns:ArrayOfdouble" />
<xs:complexType name="ArrayOffloat">
<xs:sequence>
<xs:element minOccurs="0" maxOccurs="unbounded" name="float" type="xs:float" />
</xs:sequence>
</xs:complexType>
<xs:element name="ArrayOffloat" nillable="true" type="tns:ArrayOffloat" />
<xs:complexType name="ArrayOfguid">
<xs:sequence>
<xs:element minOccurs="0" maxOccurs="unbounded" name="guid" type="ser:guid" />
</xs:sequence>
</xs:complexType>
<xs:element name="ArrayOfguid" nillable="true" type="tns:ArrayOfguid" />
<xs:complexType name="ArrayOfint">
<xs:sequence>
<xs:element minOccurs="0" maxOccurs="unbounded" name="int" type="xs:int" />
</xs:sequence>
</xs:complexType>
<xs:element name="ArrayOfint" nillable="true" type="tns:ArrayOfint" />
<xs:complexType name="ArrayOflong">
<xs:sequence>
<xs:element minOccurs="0" maxOccurs="unbounded" name="long" type="xs:long" />
</xs:sequence>
</xs:complexType>
<xs:element name="ArrayOflong" nillable="true" type="tns:ArrayOflong" />
<xs:complexType name="ArrayOfshort">
<xs:sequence>
<xs:element minOccurs="0" maxOccurs="unbounded" name="short" type="xs:short" />
</xs:sequence>
</xs:complexType>
<xs:element name="ArrayOfshort" nillable="true" type="tns:ArrayOfshort" />
<xs:complexType name="ArrayOfstring">
<xs:sequence>
<xs:element minOccurs="0" maxOccurs="unbounded" name="string" nillable="true" type="xs:string" />
</xs:sequence>
</xs:complexType>
<xs:element name="ArrayOfstring" nillable="true" type="tns:ArrayOfstring" />
<xs:complexType name="ArrayOfduration">
<xs:sequence>
<xs:element minOccurs="0" maxOccurs="unbounded" name="duration" type="ser:duration" />
</xs:sequence>
</xs:complexType>
<xs:element name="ArrayOfduration" nillable="true" type="tns:ArrayOfduration" />
<xs:complexType name="ArrayOfunsignedInt">
<xs:sequence>
<xs:element minOccurs="0" maxOccurs="unbounded" name="unsignedInt" type="xs:unsignedInt" />
</xs:sequence>
</xs:complexType>
<xs:element name="ArrayOfunsignedInt" nillable="true" type="tns:ArrayOfunsignedInt" />
<xs:complexType name="ArrayOfunsignedLong">
<xs:sequence>
<xs:element minOccurs="0" maxOccurs="unbounded" name="unsignedLong" type="xs:unsignedLong" />
</xs:sequence>
</xs:complexType>
<xs:element name="ArrayOfunsignedLong" nillable="true" type="tns:ArrayOfunsignedLong" />
<xs:complexType name="ArrayOfunsignedShort">
<xs:sequence>
<xs:element minOccurs="0" maxOccurs="unbounded" name="unsignedShort" type="xs:unsignedShort" />
</xs:sequence>
</xs:complexType>
<xs:element name="ArrayOfunsignedShort" nillable="true" type="tns:ArrayOfunsignedShort" />
<xs:complexType name="ArrayOfQName">
<xs:sequence>
<xs:element minOccurs="0" maxOccurs="unbounded" name="QName" nillable="true" type="xs:QName" />
</xs:sequence>
</xs:complexType>
<xs:element name="ArrayOfQName" nillable="true" type="tns:ArrayOfQName" />
</xs:schema>
데이터 계약 serialization 스키마에 대한 자세한 내용은 데이터 계약 스키마 참조를 참조하세요.