Как получить рабочий тракт wcf приложения?

Вы можете использовать сначала видимость ul скрытый и li: hover ul видимость: видимый для отображения при наведении списка родителей.

li:hover ul {
   visibility: visible;
} 

ul {
   visibility: hidden;
} 
<div>
     <li>Add Rows</li>
     <li>DeleteRows</li>
     <li>View Rows
       <ul>
         <li>View New Records</li>
         <li>View Old Records</li>
       </ul>
     </li>
    </div>

68
задан BoltClock 28 January 2015 в 10:23
поделиться

5 ответов

Мне нужна была та же информация для моего приложения WCF, размещенного в IIS6, и я обнаружил, что это сработало для меня:

string apPath = System.Web.Hosting.HostingEnvironment.ApplicationPhysicalPath;

Как всегда, YMMV.

171
ответ дан 24 November 2019 в 13:58
поделиться

Please see ongle's answer below. It is much better than this one.

Updated after more information

The following worked for me. I tested it with a new WCF Service I hosted on IIS through a Service1.svc.

  1. Add to web config. .. existed already.
  2. Add AspNetCompatibilityRequirementsAttribute to the service with Mode Allowed.
  3. Use HttpContext.Current.Server.MapPath("."); to get the root directory.

Below is the full code for the service class. I made no changes in the IService1 interface.

[AspNetCompatibilityRequirements(RequirementsMode=AspNetCompatibilityRequirementsMode.Allowed)]
public class Service1 : IService1
{
    public void DoWork()
    {
        HttpContext.Current.Server.MapPath(".");
    }
}

And below is an excerpt from the web.config.

<system.serviceModel>
    <!-- Added only the one line below -->
    <serviceHostingEnvironment aspNetCompatibilityEnabled="true"/>

    <!-- Everything else was left intact -->
    <behaviors>
        <!-- ... -->
    </behaviors>
    <services>
        <!-- ... -->
    </services>
</system.serviceModel>

Old answer

What do you mean by the Working Folder? WCF services can be hosted in several different ways and with different endpoints so working folder is slightly ambiguous.

You can retrieve the normal "Working folder" with a call to Directory.GetCurrentDirectory().

HttpContext is an ASP.Net object. Even if WCF can be hosted on IIS, it's still not ASP.Net and for that reason most of the ASP.Net techniques do not work by default. OperationContext is the WCF's equivalent of HttpContext. The OperationContext contains information on the incoming request, outgoing response among other things.

Though the easiest way might be to run the service in ASP.Net compatibility mode by toggling it in the web.config. This should give you access to the ASP.Net HttpContext. It will limit you to the *HttpBindings and IIS hosting though. To toggle the compatibility mode, add the following to the web.config.

<system.serviceModel>
    <serviceHostingEnvironment aspNetCompatibilityEnabled="true"/>
</system.serviceModel>
31
ответ дан 24 November 2019 в 13:58
поделиться

aspNetCompatibilityEnabled = "true" должно было решить мою проблему, но я получил эту ошибку:

Сервер не предоставил значимого ответа; это может быть вызвано несоответствием контракта, преждевременным завершением сеанса или внутренней ошибкой сервера.

Я решил проблему с получением физического пути к моей работающей службе WCF, получив его из моего текущего домена приложения:

AppDomain.CurrentDomain.BaseDirectory
12
ответ дан 24 November 2019 в 13:58
поделиться

Для ссылки на такие функции ASP.NET, как объект HttpContext, необходимо запустить приложение WCF в режиме совместимости с ASP.NET. Эта статья объясняет, как это сделать.

3
ответ дан 24 November 2019 в 13:58
поделиться

В зависимости от того, что вы хотите. Обычно я хочу разрешить URL-адрес типа «~ / folder / file». Вот что сработало.

System.Web.Hosting.HostingEnvironment.MapPath("~/folder/file");
20
ответ дан 24 November 2019 в 13:58
поделиться
Другие вопросы по тегам:

Похожие вопросы: