How can I call a WCF service from code, in the .net framework 3

吃可爱长大的小学妹 提交于 2019-12-24 10:51:31

问题


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


回答1:


Try this:

  • Create a hashmap of HashMap<string, string>
  • Add Constantes.NomPRPMIN306010, ... as key and "AddProvider", ... as value.
  • call ObtenirUrl(hashmap[_strNteraHL7], ...


来源:https://stackoverflow.com/questions/4194498/how-can-i-call-a-wcf-service-from-code-in-the-net-framework-3

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!