WCF 服务中的业务逻辑层公开
我们的应用程序中已经提供了业务逻辑层。它有很多课程。这是在单独的库(.Dll)中。现在我们想将其用于我们的 WCF 服务。为此,我们创建新项目并引用该 .Dll。但我们看不到我们的课程..我验证该课程是公开的..
您能让我知道我应该做什么吗?
在这里,我附加了我需要执行的代码
我的业务层类
namespace BusinessLayer
{
public class MessageContext : Dictionary<string, object>
{ ....}
}
现在我将此项目引用到我的 WCF 项目,并尝试将此类公开到 WCF 客户端。因此,我创建一个继承自 MessageContext 的 MessageContextHelper 类,代码如下
namespace WCFService
{
public class MessageContextHelper : MessageContext
{ ...... }
}
在客户端上,我无法获取 MessageContextHelper 类。
谢谢 杰康
We have already Business logic layer available in our application. It has lots of classes. and this is in separate library(.Dll). Now we want to use this in to our WCF Service. For that We create new project and gave reference to that .Dll. But we are not able to see our class .. I verify that class is public..
Could you please let me know what should I do?
Here I am attaching my code what I need to do
My Business Layer class
namespace BusinessLayer
{
public class MessageContext : Dictionary<string, object>
{ ....}
}
Now I am reference this Project to my WCF project and tried to expose this class into WCF client. So I Create one MessageContextHelper class which inherit from MessageContext the code is following
namespace WCFService
{
public class MessageContextHelper : MessageContext
{ ...... }
}
On client I am not able to get MessageContextHelper class.
Thanks
JK
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
WCF 不向客户端发送业务逻辑类。如果您使用 WCF 的 SOAP 版本(例如 BasicHttpBinding),那么 WCF 将公开您的服务契约中的方法。您的客户可以致电这些。
因此,如果您希望公开业务逻辑类中的方法,请在 WCF 服务中创建方法,该方法将依次调用业务层方法。
一个非常初级(且不完整)的版本看起来像这样:
namespace WCFService
{
}
WCF doesn't send business logic classes to the client. If you're using the SOAP version of WCF (BasicHttpBinding for example) then what WCF will expose is methods that are in your service contract. Your client can call those.
So if you have methods in a business logic class that you want exposed, create methods in your WCF service that will in turn call the business layer methods.
A very rudimentary (and not complete) version would look something like this:
namespace WCFService
{
}
您绝对不能(也不应该)从客户端代码使用业务层。正如前面的回复消息一样,WCF 不会将您的业务类发送给客户端。想想发送需要多长时间。业务层(您的 dll)应该仅在服务器上使用。您的 WCF 应该只接受来自客户端的修改/新数据,将数据传递到业务层,然后将结果返回给客户端。
You absolutely cannot (and should not) use your business layer from your client code. As the previous reply message, WCF does not send your business class to the client. Think about how long it will take to send. The business layer (your dll) should be used on the server only. Your WCF should only accept modified/new data from the client, pass the data to the business layer, and then return the results to the client.