如何将基本类库转变为 WCF 服务库 [英] How to turn a basic class library into a WCF Service Library

查看:34
本文介绍了如何将基本类库转变为 WCF 服务库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图复制现有 WCF 服务库的功能,以将其用作新 WCF 服务库的模板.由于我要剪切和粘贴我需要的所有代码,而且我不希望它创建默认的服务存根,因此我没有使用内置的WCF 服务库"项目模板来启动它.我刚刚使用空项目"模板向我的解决方案添加了一个新的空白项目.

I was trying to copy the functionality of an existing WCF service library to use it as a template for a new WCF service library. Since I was going to cut and paste all the code that I needed, and I didn't want it to create the default service stubs, I didn't start it by using the built-in "WCF Service Library" project template. I just added a new blank project to my solution, using the "Empty Project" template.

然后我为我的项目创建了两个新的空白 .cs 代码文件来保存我的服务的接口和类,并从我的原始 WCF 服务库项目中复制/粘贴接口和类代码,并进行了我需要的更改制作.

I then created two new blank .cs code files to my project to hold the interface and class for my service, and copied/pasted the Interface and Class code from my original WCF service library project, and made the alterations that I needed to make.

新项目编译得很好,但是...

The new project compiles fine, however...

1) 如果我进入项目属性,WCF 选项"部分不会出现,就像在我原来的 WCF 服务库中一样.

1) If I go into the project properties, the "WCF Options" section does not appear, as it does in my original WCF service library.

2) 使用原始的 WCF 服务库项目,我可以右键单击它并选择 Debug->Start New Instance,它会使用 WCF Service Host 自动启动它.对于新项目,如果我尝试这样做,它会说无法直接启动输出类型为类库的项目".

2) With the original WCF service libary project, I could right-click on it and select Debug->Start New Instance, and it would automatically start it using WCF Service Host. With the new project, if I try that, it says, "A project with an Output Type of Class Library cannot be started directly".

如何让 Visual Studio(我使用的是 2012 Professional)将此项目视为真正的 WCF 类库,而不是重新开始并使用WCF 服务库"项目模板?

How do I get Visual Studio (I'm using 2012 Professional) to see this project as a true WCF class library, short of starting over and using the "WCF Service Library" project template?

推荐答案

project 文件中缺少 ProjectExtensions 部分

You are missing the ProjectExtensions section from your project file

这是来自我的 VS2010 项目之一.

This is from one of my VS2010 projects.

  <ProjectExtensions>
      <VisualStudio>
      <FlavorProperties GUID="{3D9AD99F-2412-4246-B90B-4EAA41C64699}">
        <WcfProjectProperties>
          <AutoStart>True</AutoStart>
        </WcfProjectProperties>
      </FlavorProperties>
    </VisualStudio>
  </ProjectExtensions>

如果我删除它,WCF Options 属性部分就会消失.

If I remove it, the WCF Options properties section goes away.

我做了一个 Empty 项目和一个 WCF 服务库的比较,发现你还需要将这个添加到你的项目中,才能让 WCF 选项出现在项目属性中

I did a comparison of an Empty project to a WCF Service Library, and found that you also need to add this to your project to get the WCF Options to appear in the project properties

<ProjectTypeGuids>{3D9AD99F-2412-4246-B90B-4EAA41C64699};{F184B08F-C81C-45F6-A57F-5ABD9991F28F}</ProjectTypeGuids>

WCF 中有另一个条目(而不是在 Empty 项目中)

There is another entry in WCF (and not in the Empty project)

<StartArguments>/client:"WcfTestClient.exe"</StartArguments>

我假设在您执行此操作时需要它

which I'm assuming is needed when you do the

调试->启动新实例

但是,您还需要其他东西,例如对 System.ServiceModel 的引用.

There is other stuff that you will need however, such as a reference to System.ServiceModel.

老实说,我认为您最好使用适当的 WCF 服务库 模板并删除您不想要的东西,而不是试图弄清楚您确实需要什么.

To be honest, I think you'd be better off using the proper WCF Service Library template and cutting out stuff you don't want, rather than trying to figure out what you do need.

这篇关于如何将基本类库转变为 WCF 服务库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆