Сообщение "Не удалось сгенерировать документ схемы" на странице справки WCF
У меня есть API отдыха (WCF Net 4.0):
[ServiceContract]
interface ISubscriptionService
{
[OperationContract]
[WebInvoke(Method = "GET", UriTemplate = Routing.ProductsRoute, BodyStyle = WebMessageBodyStyle.Bare, ResponseFormat = WebMessageFormat.Json)]
[Description("Получение информации о продуктах")]
ProductsResult Products(string timestamp, string transaction_id);
}
[ServiceBehavior(AddressFilterMode = AddressFilterMode.Any, InstanceContextMode = InstanceContextMode.Single, ConcurrencyMode = ConcurrencyMode.Single, IncludeExceptionDetailInFaults = true)]
[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
class SubscriptionService : ISubscriptionService
{
public ProductsResult Products(string timestamp, string transaction_id)
{
SubscriptionProcessing processing = new SubscriptionProcessing();
processing.SaveHistory(WebOperationContext.Current.IncomingRequest.UriTemplateMatch.RequestUri);
return processing.GetProducts(timestamp, transaction_id);
}
}
Web.config:
<?xml version="1.0"?>
<configuration>
<system.web>
<compilation debug="true" targetFramework="4.0"/>
</system.web>
<system.serviceModel>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true"/>
<behaviors>
<serviceBehaviors>
<behavior>
<serviceMetadata httpGetEnabled="false"/>
<serviceDebug includeExceptionDetailInFaults="false"/>
</behavior>
</serviceBehaviors>
<endpointBehaviors>
<behavior name="DefaultEndPointBehavior">
<webHttp helpEnabled="true" />
</behavior>
</endpointBehaviors>
</behaviors>
<services>
<service name="CloudWebAPI.SubscriptionService">
<endpoint address="" kind="webHttpEndpoint" behaviorConfiguration="DefaultEndPointBehavior" contract="CloudWebAPI.ISubscriptionService" />
</service>
</services>
</system.serviceModel>
<system.webServer>
<httpProtocol>
<customHeaders>
<add name="Access-Control-Allow-Methods" value="GET, POST, OPTIONS, PUT, DELETE"/>
<add name="Access-Control-Allow-Origin" value="*"/>
<add name="Access-Control-Allow-Headers" value="Content-Type"/>
</customHeaders>
</httpProtocol>
</system.webServer>
</configuration>
Класс ProductsResult:
[DataContract(Name = "result", Namespace = "")]
public class ProductsResult : CommonResult
{
public ProductsResult()
{
Products = new List<ProductResult>();
}
[DataMember(Name = "products", Order = 3)]
public List<ProductResult> Products { get; set; }
}
Класс CommonResult:
[DataContract(Name = "result", Namespace = "")]
public class CommonResult
{
public CommonResult()
{
TransactionId = string.Empty;
Error = new ErrorResult();
}
[DataMember(Name = "transaction_id", Order = 1)]
public string TransactionId { get; set; }
[DataMember(Name = "error", Order = 2)]
public ErrorResult Error { get; set; }
}
Класс ErrorResult:
[DataContract(Name = "error", Namespace = "")]
public class ErrorResult
{
public ErrorResult()
{
Code = 0;
Message = string.Empty;
}
[DataMember(Name = "error", Order = 1)]
public int Code { get; set; }
[DataMember(Name = "message", Order = 2)]
public string Message { get; set; }
}
Открыв страницу.../rest/SubscriptionService.svc/ помощь / операции / Продукты, я получаю:
Message direction Format Body
Request N/A The Request body is empty.
Response Unknown Could not generate schema document.
Но если вы измените атрибут класса ProductsResult [DataContract (Name = "blabla", Namespace = "")], все будет работать нормально:
Response Xml Example,Schema
Response Json Example
The following is an example response Xml body:
...
Какова причина?
1 ответ
Как говорится в комментарии выше ask125342, классы не могут иметь один и тот же декоратор Name класса, от которого они наследуются - это нарушит автоматическое создание страниц справки WCF.