如何在WPF应用程序中通过WCF访问静态类? [英] How to access static class over WCF in WPF application?

查看:102
本文介绍了如何在WPF应用程序中通过WCF访问静态类?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何通过WCF服务访问客户端ui(WPF-usercontrol)中的以下静态类/变量。



 命名空间 MySolution.Model 
{
public static class SysAppParam
{
public static string EmpCodeGenInActionForm = EmpCodeGenInActionForm;
public static string AutoEmpTempSeqCode = AutoEmpTempSeqCode;
public static string EmpEmail = EmpEmail;
..........
..........
...........
... .......

}
}





如何制作上述课程所有层面都可用?我将它包含在模型项目中以便从所有层获取访问权限...是否可以实现这一目标?

Plz help ....

解决方案

为什么不将它放在所有层引用的Common类库项目中,这样它在所有点上都可用?


这里你似乎缺少的是服务提供商和服务客户​​端是两个完全独立的应用程序。在服务器端分层不会在客户端提供类,你需要直接在客户端项目中包含这些类。



这是一个可以理解的错误,因为在Visual Studio中'make WCF client'进程自动生成一大堆代理类,使得它看起来像你的服务类在客户端中,但它们实际上不是(如果你深入研究客户端解决方案中的那些类)你会发现它们只是代理)这就是你改变服务时必须重新生成它们的原因。


你可以在客户端包含这个常量集合应用程序要么将其放在双方引用的公共项目中,要么将.cs文件包含在双方的模型层项目中(添加现有项目,然后使用文件选择器中的下拉箭头添加链路)。

How to access the following static class/variables in client side ui (WPF-usercontrol) through WCF service.

namespace MySolution.Model
{
    public static class SysAppParam
    {
        public static string EmpCodeGenInActionForm = "EmpCodeGenInActionForm";
        public static string AutoEmpTempSeqCode = "AutoEmpTempSeqCode";
        public static string EmpEmail = "EmpEmail";
        ..........
          ..........
       ...........
       ..........
  
    }
}



How to make the above class avilable in all tiers?? i included it in Model project to get access from all tiers... Is it the way to make it?
Plz help....

解决方案

Why not put it in a "Common" class library project that all your tiers reference, that way it is available at all points?


What you seem to be missing here is that a service provider and a service client are two completely separate applications. Layering on the server side won't make classes available on the client side, you need to include those classes directly in the client project.

It's an understandable mistake as the 'make WCF client' process in Visual Studio auto-generates a whole bunch of proxy classes that make it look like your service classes are in the client as well, but they really aren't (if you dig into those classes in the client solution you'll see that they are just proxies) which is why you have to regenerate them when you change the service.

You can include this collection of constants in the client application either by having it in a common project which is referred to in both sides, or by including the .cs file in the model-tier project on both sides (Add Existing Item and then use the dropdown arrow in the file picker to add a link).


这篇关于如何在WPF应用程序中通过WCF访问静态类?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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