Включить кэширование WCF с помощью VB. NET пример - PullRequest
0 голосов
/ 23 февраля 2020

Я пытаюсь перевести этот код sanple, который позволяет кэшировать службу WCF с C# до VB. NET на основе кода здесь Реализация кэша в службе WCF и здесь https://docs.microsoft.com/en-us/previous-versions/dotnet/netframework-4.0/ee230443 (v = vs.100)? Redirectedfrom = MSDN

[ServiceContract] AspNetCompatibilityRequirements(RequirementsMode=AspNetCompatibilityRequirementsMode.Allowed)]
    public class Service
    { 
        [WebGet(UriTemplate = "{id}")]
        [AspNetCacheProfile("CacheFor60Seconds")]
        public Customer GetCustomer(string id)
        {
             // ...
        }
}

Вот мой существующий метод:

<ServiceContract()>
Public Interface Iservice

    <OperationContract()>
    <Web.WebInvoke(Method:="GET", ResponseFormat:=Web.WebMessageFormat.Json, BodyStyle:=Web.WebMessageBodyStyle.Bare, 
   UriTemplate:="countriespercategory/?lan={lang}&t={t}")>
    Function GetCountriesPerCategory(ByVal lang As String, ByVal t As Integer) As Stream

End Interface

Я добавил в свой web.config file:

<caching>
  <outputCacheSettings>
    <outputCacheProfiles>
      <add name="CacheFor600Seconds" duration="600" varyByParam="format" varyByHeader="Accept" />
    </outputCacheProfiles>
  </outputCacheSettings>
</caching>

Я пытался

<ServiceContract()>
<AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)>

Но это вызывает синтаксическую ошибку. Затем я безуспешно пытался применить его к элементу OperationContract, например так:

    <OperationContract()>
    <Web.WebInvoke(Method:="GET", ResponseFormat:=Web.WebMessageFormat.Json, BodyStyle:=Web.WebMessageBodyStyle.Bare, System.ServiceModel.Web.AspNetCacheProfileAttribute("CacheFor600Seconds"),        
   UriTemplate:="countriespercategory/?lan={lang}&t={t}")>
    Function GetCountriesPerCategory(ByVal lang As String, ByVal t As Integer) As Stream

Нужно ли применять кэширование на уровне ServiceContract (и, следовательно, ко всем методам) или я могу указать кэширование на одна операцияКонтракт?

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...