Rest 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>
クラス Products結果:
[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; }
}
クラス エラー結果:
[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/help/operations/Products ページを開くと、次のようになります。
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:
...
理由は何ですか?