I'm trying to figure out if there is a better way to accomplish what I have below.
We have multiple(12) SOAP web services all from the same vendor. So all the calls are the same (ex. getclaim(), editclaim(), addclaim(), etc, etc)
ex. of two web service urls
https://trustonline.delawarecpf.com/tows/webservicefk.svc
https://trustonline.delawarecpf.com/tows/webservicepcc.svc
But we have all of the ws calls in separate files (super redundant), one for each web service.
So I'm trying to figure out how to combine them into a single file.
I think can do something like this below, where I have a switch or if statement that determines the web service and the User object from each service, but this seems a little non obj oriented, so I'm looking to see if there is a better way?
Here is what I'm currently doing, but looking for a better way.
// initializing the web services and fetching some data at the end
public void InitWebService(string webserviceUrl, int webServiceType)
{
BasicHttpBinding binding = new BasicHttpBinding(BasicHttpSecurityMode.Transport);
EndpointAddress endpoint = new EndpointAddress(webserviceUrl);
ChannelFactory channelFactory = null;
switch(webServiceType)
{
case 1:
channelFactory = new ChannelFactory<WebServiceAWI>(binding, endpoint);
break;
case 2:
channelFactory = new ChannelFactory<WebServiceBG>(binding, endpoint);
break;
etc.
}
var webservice = channelFactory.CreateChannel();
var user = null; // CAN'T HAVE NULL HERE
switch(webServiceType)
{
case 1:
user = WebservicereferenceA.User();
break;
case 2:
user = WebserviceReferenceB.User();
break;
etc.
}
user.UserName = webservice.EncryptValue("someone");
user.Password = webservice.EncryptValue("password");
// get some data
var result = webservice.AttorneysGet(user);
}
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…