简体   繁体   English

将WCF服务添加到网站项目

[英]Add WCF service to website project

I have an asp.net Website that has access to database and has functions which I want to allow 3rd party users to use. 我有一个asp.net网站,该网站可以访问数据库,并且具有我希望允许第三方用户使用的功能。

Is it possible to add WCF project/ WCF service to my solution so i could let 3rd party member having access to my methods? 是否可以将WCF项目/ WCF服务添加到我的解决方案中,以便让第三方成员可以访问我的方法?

We tried myWebsite->Add New Item-> Wcf service/wcf data service but that doesn't seem to work. 我们尝试了myWebsite-> Add New Item-> Wcf服务/ wcf数据服务,但这似乎不起作用。

Any help would be great. 任何帮助都会很棒。

It's not working because you are trying to add a reference to an existing service for consuming it. 它不起作用,因为您尝试添加对现有服务的引用以使用它。 You want the exact opposite. 您要完全相反。

For this, you will have to create a separete project of type WCF Service in your solution. 为此,您将必须在解决方案中创建WCF服务类型的单独项目。

More info on creating WCF Services can be found on MSDN . MSDN上可以找到有关创建WCF服务的更多信息。

Keep in mind that if you want to expose certain features through the service, you will have to factor the functionally out of the website to another project that both the WCF Service and the website can consume. 请记住,如果要通过服务公开某些功能,则必须将功能从网站中排除到WCF服务和网站都可以使用的另一个项目中。

You should be able to add a new WCF service project from the solution root in Solution Explorer... 您应该能够从解决方案资源管理器中的解决方案根目录添加新的WCF服务项目...

Right-Click >> Add >> New Project 右键单击>>添加>>新项目

It's not clear from your question what 'doesn't work' though. 从您的问题尚不清楚什么“无效”。

Your newly added project will need to reference the existing project that contains the methods that you want to access. 您新添加的项目将需要引用包含您要访问的方法的现有项目。 You should perhaps consider if your current design is appropriate - ensure that you have separated out your presentation code (this should be your website project) from the common business functions that you want to share (I would have this as a separate class library project in the solution). 您也许应该考虑当前的设计是否合适-确保已将演示文稿代码(这应该是您的网站项目)与要共享的常见业务功能(我将其作为单独的类库项目)分开解决方案)。 Your WCF project can then reference the common 'business logic' project. 然后,您的WCF项目可以引用通用的“业务逻辑”项目。

To reference your 'business logic' project from the WCF project... 要从WCF项目引用您的“业务逻辑”项目...

Right-Click (on WCF project) >> Add Reference 右键单击(在WCF项目上)>>添加参考

Not sure what "doesn't work", but MSDN providers a walkthrough for adding a WCF service to a website here: 不知道什么“无效”,但是MSDN提供了一个在此处向网站添加WCF服务的演练:

How to: Host a WCF Service in IIS 如何:在IIS中托管WCF服务

This has the step-by-step of creating a WCF (both markup and code) and adding the relevant web.config entries by hand rather than using the "Add Service" dialog. 这一步一步地创建了WCF(标记和代码)并手动添加了相关的web.config条目,而不是使用“添加服务”对话框。

If you create a separate project in your solution to run your services, you will need to reference your existing website project using the Add Reference option on the new service project. 如果您在解决方案中创建一个单独的项目来运行服务,则需要使用新服务项目上的“ Add Reference选项来引用现有的网站项目。 This will allow you to use the classes and functions defined in the existing project inside your new service project. 这将允许您使用新服务项目中现有项目中定义的类和函数。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM