如何在 .net Framework 3 中从代码调用 WCF 服务

发布于 2024-10-02 22:15:10 字数 1457 浏览 0 评论 0原文

我正在 VB.Net 中工作,我正在尝试使一段代码更通用。

事实上,有一个很大的 Select Case 语句,它根据参数中传递的值(字符串)构建 ProxyServer。

 Select Case _strNteraHL7
        Case Constantes.NomPRPMIN306010
            strUrl = ObtenirUrl("ProviderDetailsQuery", _strVersion, _strEnvir, True, _blnSimulCAIS, _blnSimulPDS, _blnSimulPDSSIIR, _blnSimulPDSInteg)
            objWsHL7 = New wsProviderDetailsQuery.ProviderDetailsQueryClient(objBinding, New EndpointAddress(strUrl))
        Case Constantes.NomPRPMIN301010
            strUrl = ObtenirUrl("AddProvider", _strVersion, _strEnvir, True, _blnSimulCAIS, _blnSimulPDS, _blnSimulPDSSIIR, _blnSimulPDSInteg)
            objWsHL7 = New wsAddProvider.AddProviderClient(objBinding, New EndpointAddress(strUrl))

前面示例中的“wsAddProvider”和“wsProviderDetailsQuery”等对象是通过 Visual Studio 的 GUI 添加的服务引用...

我想知道的是,基本上,我是否可以从包含以下内容的某个池中调用此构造函数:服务引用,类似于当我想调用控件容器中的控件时......

例如:

objWsHL7 = new wcfServicesContainer("serviceNameHere", paramArray())

或类似的东西,所以我可以删除所有那些大的开关案例,重复相同的事情 30 次。

objWsHL7 是编译时的对象或类型“对象”。

抱歉,如果我没有提到足够的细节,如果您需要更多信息,请随时告诉我,我真的不知道我必须为此提供哪些信息。

编辑:我在这里发现了另一段使用类似调用的代码,也许它会帮助理解...

再次,在另一个 switch case 语句中,

objMsgHL7Out = _objWsHL7.ProviderDetailsQuery(_objMsgIn)

objMsgHL7Out 是 System.ServiceModel.Channels.Message _objMsgIn 是一个 System.ServiceModel.Channels.Message _objWsHL7 是一个对象

I'm working in VB.Net and I'm trying to make a piece of code more generic.

In fact, there's a big Select Case statement that build a ProxyServer based on a value passed in parameter (a string).

 Select Case _strNteraHL7
        Case Constantes.NomPRPMIN306010
            strUrl = ObtenirUrl("ProviderDetailsQuery", _strVersion, _strEnvir, True, _blnSimulCAIS, _blnSimulPDS, _blnSimulPDSSIIR, _blnSimulPDSInteg)
            objWsHL7 = New wsProviderDetailsQuery.ProviderDetailsQueryClient(objBinding, New EndpointAddress(strUrl))
        Case Constantes.NomPRPMIN301010
            strUrl = ObtenirUrl("AddProvider", _strVersion, _strEnvir, True, _blnSimulCAIS, _blnSimulPDS, _blnSimulPDSSIIR, _blnSimulPDSInteg)
            objWsHL7 = New wsAddProvider.AddProviderClient(objBinding, New EndpointAddress(strUrl))

The objects like "wsAddProvider" and "wsProviderDetailsQuery" in the previous example are service references that have been added through the GUI of Visual Studio...

What I want to know, is basically, if I can call this constructor from a certain pool containing service references, similar as when I want to call a control in a controls container...

for example:

objWsHL7 = new wcfServicesContainer("serviceNameHere", paramArray())

or something similar, so I can remove all those big switch cases, that repeat the same thing 30 times.

objWsHL7 being an object or type "object" at compiling.

Sorry if I didn't mention enough detail, feel free to let me know if you need more, I don't really know what information I have to provide for this.

Edit: I've spotted another piece of code here that uses similar calls, maybe it'll help understanding...

Again, in another switch case statement,

objMsgHL7Out = _objWsHL7.ProviderDetailsQuery(_objMsgIn)

objMsgHL7Out is a System.ServiceModel.Channels.Message
_objMsgIn is a System.ServiceModel.Channels.Message
_objWsHL7 is an Object

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

赴月观长安 2024-10-09 22:15:10

试试这个:

  • 创建 HashMap 的哈希映射,
  • 添加 Constantes.NomPRPMIN306010, ... 作为键和 "AddProvider", 。 ..作为价值。
  • 调用 ObtenirUrl(hashmap[_strNteraHL7], ...

Try this:

  • Create a hashmap of HashMap<string, string>
  • Add Constantes.NomPRPMIN306010, ... as key and "AddProvider", ... as value.
  • call ObtenirUrl(hashmap[_strNteraHL7], ...
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文