如何在.net Framework 3中从代码调用WCF服务 [英] How can I call a WCF service from code, in the .net framework 3

查看:182
本文介绍了如何在.net Framework 3中从代码调用WCF服务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在VB.Net中工作,并且试图使一段代码更通用.

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

实际上,有一个很大的Select Case语句,它根据传入的参数(字符串)的值来构建ProxyServer.

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))

上一个示例中的诸如"wsAddProvider"和"wsProviderDetailsQuery"之类的对象是已通过Visual Studio的GUI添加的服务引用...

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

例如:

objWsHL7 =新的wcfServicesContainer("serviceNameHere",paramArray())

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

或类似的东西,所以我可以删除所有重复30次的大开关盒.

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

objWsHL7是对象,或者在编译时键入对象".

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.

我在这里发现了另一段使用类似调用的代码,也许会有助于理解...

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

同样,在另一个switch case语句中,

Again, in another switch case statement,

objMsgHL7Out = _objWsHL7.ProviderDetailsQuery(_objMsgIn)

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

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

推荐答案

尝试一下:

  • 创建HashMap<string, string>
  • 的哈希图
  • 添加Constantes.NomPRPMIN306010,...作为键,"AddProvider",...作为值.
  • 致电ObtenirUrl(hashmap[_strNteraHL7], ...
  • Create a hashmap of HashMap<string, string>
  • Add Constantes.NomPRPMIN306010, ... as key and "AddProvider", ... as value.
  • call ObtenirUrl(hashmap[_strNteraHL7], ...

这篇关于如何在.net Framework 3中从代码调用WCF服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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