1
나는 휴식 API (WCF 닷넷 4.0)이 있습니다메시지 WCF 도움말 페이지에서 "스키마 문서를 생성 할 수 없습니다"
[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; }
}
클래스 일반 결과 :
[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; }
}
페이지 열기 .../휴식/SubscriptionService.svc/도움말/운영/제품, 내가 얻을 : 당신이 속성에 변경하면
Message direction Format Body
Request N/A The Request body is empty.
Response Unknown Could not generate schema document.
을하지만, 클래스 ProductsResult [DataContract (이름 = "blabla"는, 네임 스페이스 = "")]를, 모든 작동합니다 :
Response Xml Example,Schema
Response Json Example
The following is an example response Xml body:
...
이유는 무엇입니까?
거기에 많은 코드가 포함되어있어 관련성이없는 것처럼 보였습니다 (문제는 제품 결과에 거의 있음). 불필요한 질문의 구성 요소를 제거해야합니다. – Sayse
을 클릭하면 무서워 보이지 않으므로 고맙습니다. 코드를 정리하려고 할 때 문제가 발생했습니다. 문제는 Name = "result"클래스 상속의 반복입니다. – ask125342