Re: Creating Generic Class from 2 classes



Comments Inline
"tshad" <tscheiderich@xxxxxxxxxxxxxxx> wrote in message
news:uZGHZEpWGHA.1192@xxxxxxxxxxxxxxxxxxxxxxx
"Bill Butler" <qwerty@xxxxxxxx> wrote in message news:GHlZf.9895$lz3.5908@xxxxxxxxxxx

"tshad" <tscheiderich@xxxxxxxxxxxxxxx> wrote in message
news:%23uNNtXOWGHA.1192@xxxxxxxxxxxxxxxxxxxxxxx

Hi Tom,

First a few comments

Lets's step back for a second.
If the Web services on the 3 machines a identical, then you *should* be able to simply change the
URL in order to point to another identical service. You mentioned that you couldn't get this to
work, but you didn't elaborate.

Actually, this was what I originally tried to do.

The Web Services are written in Java and we just have access to them. But MS seems to have a
problem with the Proxy that it builds from the wsdl. We have another problem with multiple
defined arrays (string [][]), it only defines it as string[]. I need to manually change the proxy
wherever these show up. It may be related to the Java/MS problem.

In this case, I have 2 machines 10.0.0.3 and 10.0.0.25 both running apache tomcat. In my program,
I can add the web services from either machine with no problem. The first service it finds fine,
but the 2nd one gives us an error and all I do is change the URL. Following is how it is set up.

RemoteUserService works fine.

But when I call newHireService.readNewHire I get the following error:

System.Web.Services.Protocols.SoapException: The AXIS engine could not find a target service to
invoke! targetService is newHireService at
System.Web.Services.Protocols.SoapHttpClientProtocol.ReadResponse(SoapClientMessage message,
WebResponse response, Stream responseStream, Boolean asyncCall)
at System.Web.Services.Protocols.SoapHttpClientProtocol.Invoke(String methodName, Object[]
parameters)
at ClassLibrary4.NewHire.NewHireServiceService.readNewHire(String in0, String in1, String in2)
at MyFunctions.NewHire..ctor()
at TestDll.Class1.Main(String[] args) in c:\vsprojects\testdll\class1.cs:line 24

It can't seem to find the newHireService.

Here is the section of code that changes the URL and the code that calls the 2 services

*********************************************************************************************
RemoteUserServiceService remoteUserService = new RemoteUserServiceService();
NewHireServiceService newHireService = new NewHireServiceService();

RemoteUserDataBean ruDataBean;
NewHireDataBean nhDataBean;

public NewHire()
{
sessionID = "150";

remoteUserService.Url = "http://10.0.0.25:8080/data_connect/services/RemoteUserService";;
newHireService.Url = "http://10.0.0.25:8080/data_connect/services/newHireService";;

Shouldn't that be "NewHireService"? I am not sure if case matters???



NewHireLogon(sessionID);
if (errorCode == 0)
{
nhDataBean = newHireService.readNewHire(
companyNumber,
userID,
sessionID);


... other code.


private void NewHireLogon(string sessionID)
{
ruDataBean = remoteUserService.fetchRemoteUserInfo(
userID,
"sw",
"",
"C", //Client (employer)
sessionID);

errorCode = ruDataBean.errorCode;
errorMessage = ruDataBean.errorMessage;
}
**************************************************************************************
As you can see, I set the URL, then I call both services. 1st one works and 2nd one gives the
error.

I am not sure why one works and one doesn't. If I comment out the 2 lines that change the URLs,
it works fine. I assume the URLs are correct since it finds the first one (RemoteUserServer).

I would invest some effort in this direction, as it would make your code cleaner in the long run.
It also makes sense that if the only difference between 3 Web Services is their URL, then they
should be represented by the same class. I don't mean classes with identical structure in
different namespaces. I mean the *same* class.

I agree. It would be cleaner and would be the one I would prefer to use. I was hoping to wrap
the services in a generic one and just call the Generic functions (as you set up with the
interfaces). The only other way is to create copies of all the calls and call one function when I
need to hit one server and the other function when I need the other servers services. In essence,
what you did with the interfaces.

Absolutely, it would be much nicer.
The solution that I was presenting Is more approriate when you have Feeds from dissimilar sources.
When the Feeds are identical it makes more sense to simply have each feed be a different instance of
the same class.



However, if you wish to go forward
change this
public string GetNewsItem(string a,string b, string c)
{
return news.GetNewsItem(a,b,c);
}

to this
public string GetNewsItem(string a,string b, string c)
{
News3.NewsDataBean bean = news.GetNewsItem(a,b,c);
return bean.final;
}


I am a bit curious as to the reason for your inheritance structure
Why do you need a NewsItem and a NewsItemModules class?
Why do you need a NewsDataBean and a NewsDataBean2?

I did get the argument problem to work.

I was setting up 2 classes in one namespace just to have one class call another class in the same
namespace - as the web service does.

The DataBeans are non standard types (classes). The DataBean in Java is just a structure. In all
the examples I have seen, the returns are always strings or ints. There is only one string type
and one int type for everyone. The Databeans are also identical, but they aren't standard types.
When you create a proxy with a class, it recreates the class in each web service (it doesn't do
that for strings).

So you can return just NewsDataBean. It has to be class.NewsDataBean or
namespace.class.NewsDataBean (not sure which). But they are different (strings aren't - as in
your example).

If I was only going to use the newsDataBean inside the classes, there wouldn't be a problem (as in
the NewsItem). But I need to get access to the properties in the DataBean from the program that
calls the Services.

In our example I am doing:

Console.WriteLine(theHeadline.GetNewsItem("first","second","third"));

This works because I am returning a string frin GetNewsItem.

But I need to return a Structure (DataBean) which could have strings, ints, return values, error
codes, error messages, etc.

I need to be able to do something like

NewDataBean = theHeadline.GetNewsItem("first","second","third");
Console.WriteLine(NewDataBean.something)

Maybe this is getting too convoluted.

This is the problem with the path we were walking down.
You would have a family classes with exactly the same structure, but no intrinsic relation between
them.
You *could* create Conversion routines for each of the beans that return a "commonBean". This is NOT
the ideal solution as it is NOT very expandible. Each additional "Identical" service would require a
set of new conversion routines.

The fact that NewHireServiceService works with the default URL, but not the changed URL sounds
suspicious.
Hopefully it is just the Case if the service name.


Good luck
Bill


Thanks,

Tom


Bill






.


Loading