Лучший отвечающий
Template для WCF сервиса

Вопрос
-
Здравствуйте,
возникла необходимосьть написать template для проекта на основании WCF service для visual studio 2010.
Тип проектов для темплейтов добавил с помощью visual studio 2010 sdk.
С помощью проекта project template сгенерил специальный zip архив, на основании которого с помощью проекта vsix project создал темплейт для visual studio (vsix).
После установки темплейта при выборе нового проекта добавился мой тип проекта, солюшен которого я создал.
Проект билдится, однака при попытке просмотра сервиса в браузере (view in browser), возникает exception:
"The type 'Services.WcfServiceSample', provided as the Service attribute value in the ServiceHost directive, or provided in the configuration element system.serviceModel/serviceHostingEnvironment/serviceActivations could not be found."
Однако, если поменять в свойствах созданного проекта build output path (build\output path) с "bin\Debug\" на "bin\", код отрабатывает без ошибок, если удалить содержимое папки bin и вернуть путь "bin\Debug\" ошибка снова повторяется.
Project template для создоваемого проекта:
<?xml version="1.0" encoding="utf-8"?> <Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> <PropertyGroup> <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> <ProductVersion>8.0.30703</ProductVersion> <SchemaVersion>2.0</SchemaVersion> <ProjectGuid>$guid1$</ProjectGuid> <ProjectTypeGuids>{349c5851-65df-11da-9384-00065b846f21};{fae04ec0-301f-11d3-bf4b-00c04f79efbc}</ProjectTypeGuids> <OutputType>Library</OutputType> <AppDesignerFolder>Properties</AppDesignerFolder> <RootNamespace>$safeprojectname$</RootNamespace> <AssemblyName>$safeprojectname$</AssemblyName> <TargetFrameworkVersion>v$targetframeworkversion$</TargetFrameworkVersion> <FileAlignment>512</FileAlignment> </PropertyGroup> <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> <DebugSymbols>true</DebugSymbols> <DebugType>full</DebugType> <Optimize>false</Optimize> <OutputPath>bin\Debug\</OutputPath> <DefineConstants>DEBUG;TRACE</DefineConstants> <ErrorReport>prompt</ErrorReport> <WarningLevel>4</WarningLevel> </PropertyGroup> <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "> <DebugType>pdbonly</DebugType> <Optimize>true</Optimize> <OutputPath>bin\Release\</OutputPath> <DefineConstants>TRACE</DefineConstants> <ErrorReport>prompt</ErrorReport> <WarningLevel>4</WarningLevel> </PropertyGroup> <ItemGroup> $if$ ($targetframeworkversion$ >= 4.0) <Reference Include="Microsoft.CSharp"/> $endif$ <Reference Include="System"/> <Reference Include="System.Xml"/> <Reference Include="System.Xml.Linq"/> <Reference Include="System.Core"/> <Reference Include="System.Data"/> <Reference Include="System.Configuration" /> <Reference Include="System.Runtime.Serialization"/> <Reference Include="System.Web" /> <Reference Include="System.Web.ApplicationServices" /> <Reference Include="System.Web.DynamicData" /> <Reference Include="System.Web.Entity" /> <Reference Include="System.Web.Extensions" /> <Reference Include="System.Web.Services" /> <Reference Include="System.ServiceModel" /> <Reference Include="System.ServiceModel.Web" /> </ItemGroup> <ItemGroup> <Compile Include="Properties\AssemblyInfo.cs" /> <Compile Include="Services\WcfServiceSample.cs" /> <Compile Include="IWcfServiceSample.cs" /> </ItemGroup> <ItemGroup> <Content Include="Services\WcfServiceSample.svc" > <CopyToOutputDirectory>Always</CopyToOutputDirectory> </Content> <Content Include="Web.config" > <CopyToOutputDirectory>Always</CopyToOutputDirectory> </Content> <Content Include="Dependencies\Microsoft.Practices.EnterpriseLibrary.Common.dll" /> <Content Include="Dependencies\Microsoft.Practices.EnterpriseLibrary.Common.xml" /> <Content Include="Dependencies\Microsoft.Practices.EnterpriseLibrary.Logging.dll" /> <Content Include="Dependencies\Microsoft.Practices.EnterpriseLibrary.Logging.xml" /> <Content Include="Dependencies\Microsoft.Practices.ServiceLocation.dll" /> <Content Include="Dependencies\Microsoft.Practices.Unity.dll" /> <Content Include="Dependencies\Microsoft.Practices.Unity.Interception.dll" /> </ItemGroup> <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> <Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v10.0\WebApplications\Microsoft.WebApplication.targets" /> <ProjectExtensions> <VisualStudio> <FlavorProperties GUID="{349c5851-65df-11da-9384-00065b846f21}"> <WebProjectProperties> <UseIIS>False</UseIIS> <AutoAssignPort>True</AutoAssignPort> <DevelopmentServerVPath>/</DevelopmentServerVPath> <IISUrl> </IISUrl> <NTLMAuthentication>False</NTLMAuthentication> <UseCustomServer>False</UseCustomServer> <CustomServerUrl> </CustomServerUrl> <SaveServerSettingsInUserFile>False</SaveServerSettingsInUserFile> </WebProjectProperties> </FlavorProperties> </VisualStudio> </ProjectExtensions> </Project>
VStemplate для создоваемого проекта:
<?xml version="1.0" encoding="utf-8"?> <VSTemplate Version="3.0.0" Type="Project" xmlns="http://schemas.microsoft.com/developer/vstemplate/2005"> <TemplateData> <Name>WCF Service Application</Name> <Description>WCF Service Application</Description> <Icon>WcfServiceApp.ico</Icon> <ProjectType>CSharp</ProjectType> <RequiredFrameworkVersion>2.0</RequiredFrameworkVersion> <SortOrder>1000</SortOrder> <TemplateID>b3f4a112-e710-4851-be5b-8142d7390faf</TemplateID> <CreateNewFolder>true</CreateNewFolder> <DefaultName>WcfServiceApplication</DefaultName> <ProvideDefaultName>true</ProvideDefaultName> </TemplateData> <TemplateContent> <Project File="ProjectTemplate.csproj" ReplaceParameters="true"> <ProjectItem ReplaceParameters="true" TargetFileName="Properties\AssemblyInfo.cs">AssemblyInfo.cs</ProjectItem> <ProjectItem ReplaceParameters="true">Services\WcfServiceSample.cs</ProjectItem> <ProjectItem ReplaceParameters="true">Services\WcfServiceSample.svc</ProjectItem> <ProjectItem ReplaceParameters="true">IWcfServiceSample.cs</ProjectItem> <ProjectItem ReplaceParameters="true">Web.config</ProjectItem> <ProjectItem ReplaceParameters="false">Dependencies\Microsoft.Practices.EnterpriseLibrary.Common.dll</ProjectItem> <ProjectItem ReplaceParameters="false">Dependencies\Microsoft.Practices.EnterpriseLibrary.Common.xml</ProjectItem> <ProjectItem ReplaceParameters="false">Dependencies\Microsoft.Practices.EnterpriseLibrary.Logging.dll</ProjectItem> <ProjectItem ReplaceParameters="false">Dependencies\Microsoft.Practices.EnterpriseLibrary.Logging.xml</ProjectItem> <ProjectItem ReplaceParameters="false">Dependencies\Microsoft.Practices.ServiceLocation.dll</ProjectItem> <ProjectItem ReplaceParameters="false">Dependencies\Microsoft.Practices.Unity.dll</ProjectItem> <ProjectItem ReplaceParameters="false">Dependencies\Microsoft.Practices.Unity.Interception.dll</ProjectItem> </Project> </TemplateContent> </VSTemplate>
VSIX код для проекта который создает vsix файл:
<?xml version="1.0" encoding="utf-8"?> <Vsix xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" Version="1.0.0" xmlns="http://schemas.microsoft.com/developer/vsx-schema/2010"> <Identifier Id="WcfServiceApp"> <Name>WcfServiceApplication</Name> <Author>user</Author> <Version>2.6</Version> <Description xml:space="preserve">WcfServiceApplication</Description> <Locale>1033</Locale> <SupportedProducts> <VisualStudio Version="10.0"> <Edition>Pro</Edition> </VisualStudio> </SupportedProducts> <SupportedFrameworkRuntimeEdition MinVersion="4.0" MaxVersion="4.0" /> </Identifier> <References /> <Content> <ProjectTemplate>ProjectTemplates</ProjectTemplate> </Content> </Vsix>
В чем может быть проблема?
Заранее спасибо.
8 февраля 2013 г. 7:42
Ответы
-
Привет
Если вы создадите в Visual Studio обычный проект WCF Application и зайдете в его свойства - то увидите, что по умолчанию для проекта установлена Output path в bin папку, но не в bin\Debug или bin\Release. Это важно для работы WCF, т.к. IIS, ищет файлы сборок именно в этой директории и соотвественно в другой папке он их не найдет - WCF Service without bin Folder
Для связи [mail]
- Помечено в качестве ответа Abolmasov Dmitry 18 февраля 2013 г. 9:32
11 февраля 2013 г. 12:22