如何在 .net Framework 3 中从代码调用 WCF 服务
我正在 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
试试这个:
HashMap
的哈希映射,Constantes.NomPRPMIN306010
, ... 作为键和"AddProvider"
, 。 ..作为价值。Try this:
HashMap<string, string>
Constantes.NomPRPMIN306010
, ... as key and"AddProvider"
, ... as value.ObtenirUrl(hashmap[_strNteraHL7], ...