从2个类创建泛型类 [英] Creating Generic Class from 2 classes

查看:51
本文介绍了从2个类创建泛型类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

解释起来有点复杂,但我在一台机器上运行的网络服务很棒。


问题是我已经运行了在我需要设置我的

程序来访问一个或另一个(也可能是3个)不同的Web服务器来使用这些Web服务的情况下。
使用这些Web服务。所有机器上的Web服务都是相同的。

我只是尝试更改Web服务的URL而无法使其工作。

然后我决定创建2个相同的Web服务(每台机器一个)和

然后使用通用类型在我的代码中使用。


2个Web服务器是地球和土星。 />

我最初有一个名为RemoteUserService的Web服务,它有一个方法

fetchRemoteUserInfo。


为了完成这项工作我创建了2个Web服务并称之为RemoteUserEarth

和RemoteUserSaturn。两个服务都是相同的,除了它们指向的URL和它们的命名空间(ClassLibrary4.RemoteUserEarth和

ClassLibrary4.RemoteUserEarth)。


然后我尝试了所有定义组合,以使这项工作继续下去

up with compiler错误 - 主要是不能隐式分配错误。


我最接近:


ClassLibrary4.RemoteUserEarth.RemoteUserServiceSer副门

remoteUserServiceEarth = new

ClassLibrary4.RemoteUserEarth.RemoteUserServiceSer vice();

ClassLibrary4.RemoteUserSaturn.RemoteUserServiceSe rvice

remoteUserServiceSaturn = new

ClassLibrary4.RemoteUserSaturn.RemoteUserServiceSe rvice();


object remoteUserService;


remoteUserService =

(ClassLibrary4 .RemoteUserSaturn.RemoteUserServiceS ervice)remoteUserServiceTfs;


这个编译很好,但我不能在我的代码中使用remoteUserService,因为它是一个对象。
是一个对象。


ruDataBean = remoteUserService.fetchRemoteUserInfo(

userID,

" swpays",

" ; 10.0.0.25",

" C",//客户(雇主)​​

sessionID);


这个给我一个错误''' object''不包含

''fetchRemoteUserInfo''的定义。


我要做的是让remoteUserService成为泛型类我可以在整个代码中使用
。当我唯一的区别是我指向的机器时,我不想创建相同代码的多个

实例。如果我那么

必须设置第三台机器,我会再次为第三台机器重新创建我的所有代码

。我宁愿只设置另一个变量,例如

remoteUserServiceMars,当我指向该机器时,我只是分配给remoteUserService




可以这样做吗?


谢谢,


Tom

This is a little complicated to explain but I have some web services on a
machine that work great.

The problem is that I have run into a situation where I need to set up my
program to access one or another (could also be 3) different web servers to
use these Web Services. The Web Services are identical on all the machines.
I tried just changing the URL of the Web Services and cannot make it work.
I then decided to create 2 identical web services (one for each machine) and
then use a generic type to use in my code.

The 2 web Servers are Earth and Saturn.

I originally had a Web Service called RemoteUserService, which has a method
fetchRemoteUserInfo.

To make this work I created 2 web services and called them RemoteUserEarth
and RemoteUserSaturn. Both Services are identical except for the URL they
point to and their Namespaces (ClassLibrary4.RemoteUserEarth and
ClassLibrary4.RemoteUserEarth).

I then tried all combinations of defines to make this work and kept coming
up with compiler errors - mainly "Cannot Implicitly assign" errors.

I came closest with:

ClassLibrary4.RemoteUserEarth.RemoteUserServiceSer vice
remoteUserServiceEarth = new
ClassLibrary4.RemoteUserEarth.RemoteUserServiceSer vice();

ClassLibrary4.RemoteUserSaturn.RemoteUserServiceSe rvice
remoteUserServiceSaturn = new
ClassLibrary4.RemoteUserSaturn.RemoteUserServiceSe rvice();

object remoteUserService;

remoteUserService =
(ClassLibrary4.RemoteUserSaturn.RemoteUserServiceS ervice)remoteUserServiceTfs;

This compiles fine, but I can''t use the remoteUserService in my code as it
is an object.

ruDataBean = remoteUserService.fetchRemoteUserInfo(
userID,
"swpays",
"10.0.0.25",
"C", //Client (employer)
sessionID);

This gives me an error "''object'' does not contain a definition for
''fetchRemoteUserInfo''".

What I am trying to do is get remoteUserService be the generic class that I
can using throughout my code. I don''t want to create multiple instances of
the same code when the only difference is the machine I point to. If I then
have to set up a 3rd machine, I would have recreate all my code again for
the 3rd machine. I would much rather just set up another variable, such as
remoteUserServiceMars which I just assign to remoteUserService when I point
to that machine.

Can this be done?

Thanks,

Tom

推荐答案

Tshad,


更改URL以连接到不同的Web服务是最好和最简单的方法..我

一直这样做它工作得很好,我们连接到不同的服务器

也..你可以发布一个问题样本,能够连接到

不同的URL。


Vijay


" tshad" < TS ********** @ ftsolutions.com>在留言中写道

news:u7 ************** @ TK2MSFTNGP14.phx.gbl ...
Tshad,

Changing URL to connect to different webservices is the best and easy way..I
do it all the time and it works great, we connect to different servers
also.. Could you post a sample of your problem in ability to connect to
different URL.

Vijay

"tshad" <ts**********@ftsolutions.com> wrote in message
news:u7**************@TK2MSFTNGP14.phx.gbl...
这有点复杂解释但我在
机器上有一些很好的网络服务。

问题是我遇到了需要设置我的
程序的情况访问一个或另一个(也可能是3个)不同的Web服务器以使用这些Web服务。所有
机器上的Web服务都是相同的。我尝试过更改Web服务的URL,但无法使其正常工作。然后我决定创建2个相同的Web服务(每个机器一个用于
),然后在我的代码中使用泛型类型。

2个Web服务器是地球和土星。 />
我最初有一个名为RemoteUserService的Web服务,它有一个方法fetchRemoteUserInfo。

为了完成这项工作,我创建了2个Web服务,称之为RemoteUserEarth
和RemoteUserSaturn。两个服务都是相同的,除了它们指向的URL和它们的命名空间(ClassLibrary4.RemoteUserEarth和
ClassLibrary4.RemoteUserEarth)。

然后我尝试了所有的定义组合来实现这个目的工作并继续使用编译器错误 - 主要是不能隐式分配错误。

我最接近的是:

ClassLibrary4.RemoteUserEarth.RemoteUserServiceSer副
remoteUserServiceEarth = new
ClassLibrary4.RemoteUserEarth.RemoteUserServiceSer vice();

ClassLibrary4.RemoteUserSaturn.RemoteUserServiceSe rvice
remoteUserServiceSaturn = new
ClassLibrary4.RemoteUserSaturn.RemoteUserServiceSe rvice();

对象remoteUserService;

remoteUserService =
(ClassLibrary4.RemoteUserSaturn.RemoteUserServiceS ervice)remoteUserServiceTfs;

这个编译很好,但我不能在我的代码中使用remoteUserService,因为它是一个
对象。

ruDataBean = remoteUserService.fetchRemoteUserInfo(
userID,
" swpays",
" 10.0.0.25",
" C" ;,//客户(雇主)​​
sessionID);

这给了我一个错误'''对象''不包含
''fetchRemoteUserInfo'的定义'"

我想要做的是让remoteUserService成为我可以在整个代码中使用的通用类。我不想创建相同代码的多个实例,唯一的区别是我指向的机器。如果我必须设置第3台机器,我会再次为第3台机器重新创建所有代码。我宁愿只设置另一个变量,例如remoteUserServiceMars,当我指向那台机器时,我只分配给remoteUserService


这可以吗?
谢谢,

Tom
This is a little complicated to explain but I have some web services on a
machine that work great.

The problem is that I have run into a situation where I need to set up my
program to access one or another (could also be 3) different web servers
to use these Web Services. The Web Services are identical on all the
machines. I tried just changing the URL of the Web Services and cannot
make it work. I then decided to create 2 identical web services (one for
each machine) and then use a generic type to use in my code.

The 2 web Servers are Earth and Saturn.

I originally had a Web Service called RemoteUserService, which has a
method fetchRemoteUserInfo.

To make this work I created 2 web services and called them RemoteUserEarth
and RemoteUserSaturn. Both Services are identical except for the URL they
point to and their Namespaces (ClassLibrary4.RemoteUserEarth and
ClassLibrary4.RemoteUserEarth).

I then tried all combinations of defines to make this work and kept coming
up with compiler errors - mainly "Cannot Implicitly assign" errors.

I came closest with:

ClassLibrary4.RemoteUserEarth.RemoteUserServiceSer vice
remoteUserServiceEarth = new
ClassLibrary4.RemoteUserEarth.RemoteUserServiceSer vice();

ClassLibrary4.RemoteUserSaturn.RemoteUserServiceSe rvice
remoteUserServiceSaturn = new
ClassLibrary4.RemoteUserSaturn.RemoteUserServiceSe rvice();

object remoteUserService;

remoteUserService =
(ClassLibrary4.RemoteUserSaturn.RemoteUserServiceS ervice)remoteUserServiceTfs;

This compiles fine, but I can''t use the remoteUserService in my code as it
is an object.

ruDataBean = remoteUserService.fetchRemoteUserInfo(
userID,
"swpays",
"10.0.0.25",
"C", //Client (employer)
sessionID);

This gives me an error "''object'' does not contain a definition for
''fetchRemoteUserInfo''".

What I am trying to do is get remoteUserService be the generic class that
I can using throughout my code. I don''t want to create multiple instances
of the same code when the only difference is the machine I point to. If I
then have to set up a 3rd machine, I would have recreate all my code again
for the 3rd machine. I would much rather just set up another variable,
such as remoteUserServiceMars which I just assign to remoteUserService
when I point to that machine.

Can this be done?

Thanks,

Tom



" Vijay" < 6 *** @ msdiscussions.com>在消息中写道

新闻:Oy ************** @ TK2MSFTNGP12.phx.gbl ...
"Vijay" <vi***@msdiscussions.com> wrote in message
news:Oy**************@TK2MSFTNGP12.phx.gbl...
Tshad,
更改URL以连接到不同的Web服务是最好和最简单的方式..我一直这样做它工作得很好,我们也连接到不同的服务器..你能发帖吗?您有能力连接到不同网址的问题示例。


我尝试使用以下内容:


remoteUserService.Url =
http://10.0.0.25:8080/data/services/RemoteUserService;

newHireService.Url = http://10.0.0.25:8080/data/services/newHireService;

employeeTaxService.Url =
http://10.0.0.25:8080/data/services/employeeTaxService;

这适用于第一个,但不适用于第二个。这些都是用Java写的
,在使用

多维字符串([] [])时我们确实遇到创建代理的问题。


我不知道是不是这样,但我想要做的只是创建

所有的Web服务对象,然后创建我更改的通用对象

无论我需要访问哪种服务。


我只知道如何让它工作。我以为我最终设置了

作为对象的通用服务,我似乎能够为它分配实际的

服务,但我不能似乎访问方法(我假设

属性)。


有没有办法让这个方法有效?

谢谢,


Tom
Vijay

tshad < TS ********** @ ftsolutions.com>在消息中写道
新闻:u7 ************** @ TK2MSFTNGP14.phx.gbl ...
Tshad,

Changing URL to connect to different webservices is the best and easy
way..I do it all the time and it works great, we connect to different
servers also.. Could you post a sample of your problem in ability to
connect to different URL.
I tried that using the following:

remoteUserService.Url =
http://10.0.0.25:8080/data/services/RemoteUserService;

newHireService.Url = http://10.0.0.25:8080/data/services/newHireService;

employeeTaxService.Url =
http://10.0.0.25:8080/data/services/employeeTaxService;

This worked for the first one, but not the second one. These were written
in Java, and we do have a problem with creating the proxy when using
multi-dimensional strings ([][]).

I don''t know if this is the case, but what I am trying to do is just create
all the web service Object and then create generic object that I change to
whichever service I need to access.

I just know how to get this to work. I thought I had it finally setting up
the generic service as an object and I seem to be able to assign the actual
service to it, but I can''t seem to access the methods (and I assume the
properties).

Is there a way to make this method work?

Thanks,

Tom
Vijay

"tshad" <ts**********@ftsolutions.com> wrote in message
news:u7**************@TK2MSFTNGP14.phx.gbl...
这个解释有点复杂但是我在一台运行良好的机器上有一些网络服务。

我遇到的问题是我需要设置我的
程序来访问一个或另一个(也可能是3个)不同的Web服务器使用这些Web服务。所有
机器上的Web服务都是相同的。我尝试过更改Web服务的URL,但无法使其正常工作。然后我决定创建2个相同的Web服务(每个机器一个用于
),然后在我的代码中使用泛型类型。

2个Web服务器是地球和土星。 />
我最初有一个名为RemoteUserService的Web服务,它有一个方法fetchRemoteUserInfo。

为了完成这项工作,我创建了2个Web服务并称之为
RemoteUserEarth和RemoteUserSaturn。两个服务都是相同的,除了它们指向的URL及其命名空间
(ClassLibrary4.RemoteUserEarth和ClassLibrary4.RemoteUserEarth)。

然后我尝试了所有定义组合来实现这一点工作并保持编码错误 - 主要是无法隐式分配错误。

我最接近:

ClassLibrary4.RemoteUserEarth .RemoteUserServiceSer副
remoteUserServiceEarth = new
ClassLibrary4.RemoteUserEarth.RemoteUserServiceSer vice();

ClassLibrary4.RemoteUserSaturn.RemoteUserServiceSe rvice
remoteUserServiceSaturn = new
ClassLibrary4。 RemoteUserSaturn.RemoteUserServiceSe rvice();

对象remoteUserService;

remoteUserService =
(ClassLibrary4.RemoteUserSaturn.RemoteUserServiceS服务)remoteUserServiceTfs;

编译得很好,但我不能在我的代码中使用remoteUserService,因为它是一个对象。

ruDataBean = remoteUserService.fetchRemoteUserInfo(
userID,
" swpays",
" 10.0.0.25",
" C",// Client(雇主)
sessionID);

这给了我一个错误"'''object''不包含
''fetchRemoteUserInfo''的定义。

我要做的是让remoteUserService成为我可以在整个代码中使用的通用类。当唯一的区别是我指向的机器时,我不想创建相同代码的多个
实例。如果我必须设置第3台机器,我会再次为第3台机器重新创建我的所有代码。我宁愿只设置另一个变量,例如我指向那台机器时只分配给remoteUserService的remoteUserServiceMars。

可以这样做吗?
谢谢,

Tom
This is a little complicated to explain but I have some web services on a
machine that work great.

The problem is that I have run into a situation where I need to set up my
program to access one or another (could also be 3) different web servers
to use these Web Services. The Web Services are identical on all the
machines. I tried just changing the URL of the Web Services and cannot
make it work. I then decided to create 2 identical web services (one for
each machine) and then use a generic type to use in my code.

The 2 web Servers are Earth and Saturn.

I originally had a Web Service called RemoteUserService, which has a
method fetchRemoteUserInfo.

To make this work I created 2 web services and called them
RemoteUserEarth and RemoteUserSaturn. Both Services are identical except
for the URL they point to and their Namespaces
(ClassLibrary4.RemoteUserEarth and ClassLibrary4.RemoteUserEarth).

I then tried all combinations of defines to make this work and kept
coming up with compiler errors - mainly "Cannot Implicitly assign"
errors.

I came closest with:

ClassLibrary4.RemoteUserEarth.RemoteUserServiceSer vice
remoteUserServiceEarth = new
ClassLibrary4.RemoteUserEarth.RemoteUserServiceSer vice();

ClassLibrary4.RemoteUserSaturn.RemoteUserServiceSe rvice
remoteUserServiceSaturn = new
ClassLibrary4.RemoteUserSaturn.RemoteUserServiceSe rvice();

object remoteUserService;

remoteUserService =
(ClassLibrary4.RemoteUserSaturn.RemoteUserServiceS ervice)remoteUserServiceTfs;

This compiles fine, but I can''t use the remoteUserService in my code as
it is an object.

ruDataBean = remoteUserService.fetchRemoteUserInfo(
userID,
"swpays",
"10.0.0.25",
"C", //Client (employer)
sessionID);

This gives me an error "''object'' does not contain a definition for
''fetchRemoteUserInfo''".

What I am trying to do is get remoteUserService be the generic class that
I can using throughout my code. I don''t want to create multiple
instances of the same code when the only difference is the machine I
point to. If I then have to set up a 3rd machine, I would have recreate
all my code again for the 3rd machine. I would much rather just set up
another variable, such as remoteUserServiceMars which I just assign to
remoteUserService when I point to that machine.

Can this be done?

Thanks,

Tom




网络服务我正在使用1.1或并行运行...

某些数据类型无法理解..就像我不能发送

a DataTable as一个参数,必须将它包装在一个DataSet中并发送它...

也许字符串[] []是一个问题..我没有尝试过那个参数..如果你

在添加或创建对象时出错?什么是错误信息可以

你发布它?


Vijay


" tshad" < TS ********** @ ftsolutions.com>在消息中写道

news:uY ************** @ TK2MSFTNGP12.phx.gbl ...
The webservices that shipped with 1.1 or in parallel is what i am using...
There are certain datatypes that it will not understand.. like I can''t send
a DataTable as a parameter, have to wrap it in a DataSet and send it...
Maybe the string[][] is a problem.. I have not tried that parameter.. if you
get a error when adding or creating object? what is the error message can
you post it?

Vijay

"tshad" <ts**********@ftsolutions.com> wrote in message
news:uY**************@TK2MSFTNGP12.phx.gbl...
" Vijay" < 6 *** @ msdiscussions.com>在消息中写道
新闻:Oy ************** @ TK2MSFTNGP12.phx.gbl ...
"Vijay" <vi***@msdiscussions.com> wrote in message
news:Oy**************@TK2MSFTNGP12.phx.gbl...
Tshad,
更改URL以连接到不同的Web服务是最好和最简单的方式..我一直这样做,它工作得很好,我们也连接到不同的服务器..你能发布你的样本吗?能够连接到不同的URL的问题。
Tshad,

Changing URL to connect to different webservices is the best and easy
way..I do it all the time and it works great, we connect to different
servers also.. Could you post a sample of your problem in ability to
connect to different URL.



我尝试使用以下方法:

remoteUserService.Url =
http://10.0.0.25:8080/data/services/RemoteUserService;

newHireService.Url = http://10.0.0.25:8080/data/services/newHireService;

employeeTaxService.Url =
http://10.0.0.25:8080/data/services/employeeTaxService;

这适用于第一个,但不适用于第二个。这些是用Java编写的,我们在使用多维字符串([] [])时创建代理时遇到了问题。

我不是知道是否是这种情况,但我想要做的只是创建所有的Web服务对象,然后创建我更改为我需要访问的任何服务的通用对象。

我只知道如何让它发挥作用。我以为我终于将通用服务设置为对象了,我似乎能够将
实际服务分配给它,但我似乎无法访问这些方法(而且我假设
属性)。

有没有办法使这个方法有效?

谢谢,

Tom



I tried that using the following:

remoteUserService.Url =
http://10.0.0.25:8080/data/services/RemoteUserService;

newHireService.Url = http://10.0.0.25:8080/data/services/newHireService;

employeeTaxService.Url =
http://10.0.0.25:8080/data/services/employeeTaxService;

This worked for the first one, but not the second one. These were written
in Java, and we do have a problem with creating the proxy when using
multi-dimensional strings ([][]).

I don''t know if this is the case, but what I am trying to do is just
create all the web service Object and then create generic object that I
change to whichever service I need to access.

I just know how to get this to work. I thought I had it finally setting
up the generic service as an object and I seem to be able to assign the
actual service to it, but I can''t seem to access the methods (and I assume
the properties).

Is there a way to make this method work?

Thanks,

Tom


Vijay

tshad < TS ********** @ ftsolutions.com>在消息中写道
新闻:u7 ************** @ TK2MSFTNGP14.phx.gbl ...

Vijay

"tshad" <ts**********@ftsolutions.com> wrote in message
news:u7**************@TK2MSFTNGP14.phx.gbl...
这个解释有点复杂但是我在一台运行良好的机器上有一些网络服务。

问题是我遇到了一种情况,我需要设置我的程序来访问一个或另一个(也可能是3)不同的web服务器使用这些Web服务。所有机器上的Web服务都是相同的。我尝试过更改Web服务的URL并且无法使其工作。然后我决定创建两个相同的Web服务
(每台机器一个)然后使用通用类型在我的代码中使用。

2个Web服务器是地球和土星。 />
我最初有一个名为RemoteUserService的Web服务,它有一个方法fetchRemoteUserInfo。

为了完成这项工作,我创建了2个Web服务并称之为
RemoteUserEarth和RemoteUserSaturn。两个服务是相同的
除了他们指向的URL和他们的命名空间
(ClassLibrary4.RemoteUserEarth和ClassLibrary4.RemoteUserEarth)。

然后我尝试了所有的定义组合来做这个工作并保持编码错误 - 主要是无法隐式分配错误。

我最接近:

ClassLibrary4.RemoteUserEarth .RemoteUserServiceSer副
remoteUserServiceEarth = new
ClassLibrary4.RemoteUserEarth.RemoteUserServiceSer vice();

ClassLibrary4.RemoteUserSaturn.RemoteUserServiceSe rvice
remoteUserServiceSaturn = new
ClassLibrary4。 RemoteUserSaturn.RemoteUserServiceSe rvice();

对象remoteUserService;

remoteUserService =
(ClassLibrary4.RemoteUserSaturn.RemoteUserServiceS服务)remoteUserServiceTfs;

编译得很好,但我不能在我的代码中使用remoteUserService,因为它是一个对象。

ruDataBean = remoteUserService.fetchRemoteUserInfo(
userID,
" swpays",
" 10.0.0.25",
" C",// Client(雇主)
sessionID);

这给了我一个错误"'''object''不包含
''fetchRemoteUserInfo''的定义。

我想要做的是让remoteUserService成为我可以在整个代码中使用的通用类
。当唯一的区别是我指向的机器时,我不想创建相同代码的多个
实例。如果我必须设置第3台机器,我会再次为第3台机器重新创建我的所有代码。我宁愿只设置另一个变量,例如我指向那台机器时只分配给remoteUserService的remoteUserServiceMars。

可以这样做吗?
谢谢,

Tom
This is a little complicated to explain but I have some web services on
a machine that work great.

The problem is that I have run into a situation where I need to set up
my program to access one or another (could also be 3) different web
servers to use these Web Services. The Web Services are identical on
all the machines. I tried just changing the URL of the Web Services and
cannot make it work. I then decided to create 2 identical web services
(one for each machine) and then use a generic type to use in my code.

The 2 web Servers are Earth and Saturn.

I originally had a Web Service called RemoteUserService, which has a
method fetchRemoteUserInfo.

To make this work I created 2 web services and called them
RemoteUserEarth and RemoteUserSaturn. Both Services are identical
except for the URL they point to and their Namespaces
(ClassLibrary4.RemoteUserEarth and ClassLibrary4.RemoteUserEarth).

I then tried all combinations of defines to make this work and kept
coming up with compiler errors - mainly "Cannot Implicitly assign"
errors.

I came closest with:

ClassLibrary4.RemoteUserEarth.RemoteUserServiceSer vice
remoteUserServiceEarth = new
ClassLibrary4.RemoteUserEarth.RemoteUserServiceSer vice();

ClassLibrary4.RemoteUserSaturn.RemoteUserServiceSe rvice
remoteUserServiceSaturn = new
ClassLibrary4.RemoteUserSaturn.RemoteUserServiceSe rvice();

object remoteUserService;

remoteUserService =
(ClassLibrary4.RemoteUserSaturn.RemoteUserServiceS ervice)remoteUserServiceTfs;

This compiles fine, but I can''t use the remoteUserService in my code as
it is an object.

ruDataBean = remoteUserService.fetchRemoteUserInfo(
userID,
"swpays",
"10.0.0.25",
"C", //Client (employer)
sessionID);

This gives me an error "''object'' does not contain a definition for
''fetchRemoteUserInfo''".

What I am trying to do is get remoteUserService be the generic class
that I can using throughout my code. I don''t want to create multiple
instances of the same code when the only difference is the machine I
point to. If I then have to set up a 3rd machine, I would have recreate
all my code again for the 3rd machine. I would much rather just set up
another variable, such as remoteUserServiceMars which I just assign to
remoteUserService when I point to that machine.

Can this be done?

Thanks,

Tom





这篇关于从2个类创建泛型类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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