How to turn a basic class library into a WCF Servi

2019-08-18 17:25发布

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.

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) If I go into the project properties, the "WCF Options" section does not appear, as it does in my original WCF service library.

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".

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?

1条回答
我想做一个坏孩纸
2楼-- · 2019-08-18 17:57

You are missing the ProjectExtensions section from your project file

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>

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

EDIT:

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>

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

Debug->Start New Instance

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

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.

查看更多
登录 后发表回答