473,394 Members | 1,693 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Duplicate class definitions

Disclaimer: I am extremely new to Web services and may very well be doing
the wrong thing!

Background: I have a Web service and a Windows Forms client app (VS 2005).
The Web service exposes a method to accept a ScheduleEntry object, which is
a class I have written. I felt doing this would be cleaner than passing 7 or
8 parameters, but I've run into some problems.

First, I learned that declaring classes in Web services isn't such a great
idea because the proxy class you get in your client app when you make a Web
reference only has properties and not methods.

So I decided that I'd move my class definition to a separate assembly that
I'd then reference in both the Web service and my app. This sort of works,
but now I'm getting a separate definition of the class through the Web
service. This is hard to explain so I'll give an example.

---------------
1. Assembly which contains my class (we'll call it "Scheduling.dll.")

namespace Main.Name.Space
{
public class ScheduleEntry
{
// Stuff
}
}
---------------
---------------
2. Web service

[WebService(Namespace = http://www.mycompany.com/schedulerservice)]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
public class SchedulerService : System.Web.Services.WebService
{
[WebMethod]
public int AddScheduleEntry(ScheduleEntry schedule)
{
// Stuff
}
}
---------------
---------------
3. Client app

This app contains a Web reference which I named "Scheduler" and a regular
reference to Scheduling.dll. It uses the same namespace as Scheduling.dll
(i.e., Main.Name.Space). I can see that this namespace contains a class
known as Main.Name.Space.ScheduleEntry. However, when I create an instance
of Scheduler.ScheduleService and look at the signature of the
AddScheduleEntry() method, the parameter is identified as
Main.Name.Space.Scheduler.ScheduleEntry and I can't pass a
Main.Name.Space.ScheduleEntry object because the compiler complains that it
can't cast between those types.

Is there any kind of decoration I need to do in the Web service so that when
the WSDL is interrogated and the proxy built in my client the ScheduleEntry
class comes out with the proper namespace?
Jan 12 '07 #1
2 2593
I think the way services are developed in WCF might help gain some insight
into this:

[DataContract]
class ScheduleEntry
{
public string EntryTitle;
public DateTime Timestamp;
}

[ServiceContract]
class Scheduler
{
[OperationContract]
public void AddEntry(ScheduleEntry entry)
{
}
}

The point is that the data (ScheduleEntry) is separate from the
operations/behaviors/methods that act on that data (Scheduler).

Your web service is the "point of contact" to communicate with when your
client app wants operations performed on some ScheduleEntry data. So, other
than any local processing, your client doesn't need a ScheduleEntry object
that has behavior, because the service is the behavior.

That being said, there's no need to reference the Scheduler.dll in your
client application.

Your 100% correct in wrapping a group of parameters into a single object
(ScheduleEntry) and even factoring that and other similiar objects into a
separate assembly.

Your service references that assembly, because that contains the information
it exchanges and accepts.

In essence, your service says "give me a schedule ID, and I'll send you back
a ScheduleEntry for that ID", and "give me some ScheduleEntry data, and I'll
insert it, update it".

Does that make any sense? What I want to get at here, is I think your
approach is incorrect in as far as the client app referencing an assembly in
order to use the behaviors of objects in that assembly and where those
objects are types being used in the service.

For instance:

MyMath.dll

class Math
{
public int X, Y;
public void Add(){ return X + Y; }
}

Service.dll
[WebService]
public MyMath.Math GetMath()
{
return new MyMath.Math();
}

You know what the client will get, a Math object with X and Y fields. If you
wanted to get a Math object hat had behavior, you'd have to do .NET Remoting
and have Math derive from MarshalByRefObject, and then your still not
getting a Math object that can Add() locally. When Add() is called on that
remoted object, the call will go across the network to the instance of Math
that the remoting server created and is keeping alive for you.

The following would more accurately represent a "math" service:

DataTypes.dll
class Numbers
{
public int X, Y;
}

BusinessComponent.dll
class Math
{
public int Add(Numbers numbers){ return numbers.X + numbers.Y; }
}

MathService.dll
class MathService
{
public int Add(Numbers numbers)
{
return new Math().Add(numbers);
}
}

The MathService is a wrapper around existing functionality so that the
functionality can be reachable over network protocols.

Well, I won't go on, but will point out some things that may help:
http://www.thinktecture.com/Resource...t/default.html
- scroll down to the "walkthrough" link. It may also address sharing data
definitions among projects (which is different that sharing objects with
behavior).

I highly suggest downloading that tool, going through the walkthrough a
couple times, then try applying it to your project. I'm almost 100% certain
it will change the way you think about services, for the better.

Ron

"Jeff Johnson" <i.***@enough.spamwrote in message
news:O5**************@TK2MSFTNGP02.phx.gbl...
Disclaimer: I am extremely new to Web services and may very well be doing
the wrong thing!

Background: I have a Web service and a Windows Forms client app (VS 2005).
The Web service exposes a method to accept a ScheduleEntry object, which
is a class I have written. I felt doing this would be cleaner than passing
7 or 8 parameters, but I've run into some problems.

First, I learned that declaring classes in Web services isn't such a great
idea because the proxy class you get in your client app when you make a
Web reference only has properties and not methods.

So I decided that I'd move my class definition to a separate assembly that
I'd then reference in both the Web service and my app. This sort of works,
but now I'm getting a separate definition of the class through the Web
service. This is hard to explain so I'll give an example.

---------------
1. Assembly which contains my class (we'll call it "Scheduling.dll.")

namespace Main.Name.Space
{
public class ScheduleEntry
{
// Stuff
}
}
---------------
---------------
2. Web service

[WebService(Namespace = http://www.mycompany.com/schedulerservice)]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
public class SchedulerService : System.Web.Services.WebService
{
[WebMethod]
public int AddScheduleEntry(ScheduleEntry schedule)
{
// Stuff
}
}
---------------
---------------
3. Client app

This app contains a Web reference which I named "Scheduler" and a regular
reference to Scheduling.dll. It uses the same namespace as Scheduling.dll
(i.e., Main.Name.Space). I can see that this namespace contains a class
known as Main.Name.Space.ScheduleEntry. However, when I create an instance
of Scheduler.ScheduleService and look at the signature of the
AddScheduleEntry() method, the parameter is identified as
Main.Name.Space.Scheduler.ScheduleEntry and I can't pass a
Main.Name.Space.ScheduleEntry object because the compiler complains that
it can't cast between those types.

Is there any kind of decoration I need to do in the Web service so that
when the WSDL is interrogated and the proxy built in my client the
ScheduleEntry class comes out with the proper namespace?

Jan 13 '07 #2
Well the *correct* way to do this is to extend the proxy generator behaviour
to recognize your types when the proxy code is generated.

This is not as straightforward as it could be and the easier way to do this
would be to edit the proxt class code after generation and manually point
the business object to yours. However, keep in mind that this code will get
overwritten everytime the proxy generator is invoked.

The correct way to do it would be:

1. Create a type that inherits from SchemaImporterExtension
2. Override the ImportSchemaType method
3. Write code to check the name and namespace of the type described in the
WSDL document and replace with your own type and return the generated code.
4. Give your type a strong name and put it in the GAC (alternatively put it
in the bin folder)
5. Register the extension to the proxy generator in the machine.config
6. Use Add Web Reference or wsdl.exe to generate the proxy.

HTH.

--
With Regards
Shailen Sukul
..Net Architect
(MCPD: Ent Apps, MCSD.Net MCSD MCAD)
Ashlen Consulting Services
http://www.ashlen.net.au
"Jeff Johnson" <i.***@enough.spamwrote in message
news:O5**************@TK2MSFTNGP02.phx.gbl...
Disclaimer: I am extremely new to Web services and may very well be doing
the wrong thing!

Background: I have a Web service and a Windows Forms client app (VS 2005).
The Web service exposes a method to accept a ScheduleEntry object, which
is a class I have written. I felt doing this would be cleaner than passing
7 or 8 parameters, but I've run into some problems.

First, I learned that declaring classes in Web services isn't such a great
idea because the proxy class you get in your client app when you make a
Web reference only has properties and not methods.

So I decided that I'd move my class definition to a separate assembly that
I'd then reference in both the Web service and my app. This sort of works,
but now I'm getting a separate definition of the class through the Web
service. This is hard to explain so I'll give an example.

---------------
1. Assembly which contains my class (we'll call it "Scheduling.dll.")

namespace Main.Name.Space
{
public class ScheduleEntry
{
// Stuff
}
}
---------------
---------------
2. Web service

[WebService(Namespace = http://www.mycompany.com/schedulerservice)]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
public class SchedulerService : System.Web.Services.WebService
{
[WebMethod]
public int AddScheduleEntry(ScheduleEntry schedule)
{
// Stuff
}
}
---------------
---------------
3. Client app

This app contains a Web reference which I named "Scheduler" and a regular
reference to Scheduling.dll. It uses the same namespace as Scheduling.dll
(i.e., Main.Name.Space). I can see that this namespace contains a class
known as Main.Name.Space.ScheduleEntry. However, when I create an instance
of Scheduler.ScheduleService and look at the signature of the
AddScheduleEntry() method, the parameter is identified as
Main.Name.Space.Scheduler.ScheduleEntry and I can't pass a
Main.Name.Space.ScheduleEntry object because the compiler complains that
it can't cast between those types.

Is there any kind of decoration I need to do in the Web service so that
when the WSDL is interrogated and the proxy built in my client the
ScheduleEntry class comes out with the proper namespace?

Jan 15 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: OKB (not okblacke) | last post by:
For a variety of reasons, I'm interested in putting together some code that will allow me to created structures out of nested classes, something like: class class1: def methA(self): print...
7
by: Carlos Ribeiro | last post by:
I'm looking for ways to load new class definitions at runtime (I'm not talking about object instances here, so a persistent object database isn't what I am looking for ). I'm aware of a few...
7
by: Lowell Kirsh | last post by:
I have a script which I use to find all duplicates of files within a given directory and all its subdirectories. It seems like it's longer than it needs to be but I can't figure out how to shorten...
1
by: Oplec | last post by:
Hi, I'm learning C++ as a hobby using The C++ Programming Language : Special Edition by Bjarne Stroustrup. I'm working on chpater 13 exercises that deal with templates. Exercise 13.9 asks for me...
7
by: Srini | last post by:
Hello, Rules for inline functions say that they have to be defined in the same compilation unit as their declarations. For class member functions this means that the inline member functions must...
9
by: Markus Kern | last post by:
Hi! I've been messing around with a template class. As usual, I do not want to make the definition of my functions public, but only its declaration. This was the concept of seperating...
9
by: jerry.upstatenyguy | last post by:
I am really stuck on this. I am trying to write a string array containing a "word" and a "definition" to a class called Entry. Ultimately this will end up in another class called dictionary. No,...
4
by: mathieu | last post by:
Why is the following code causing duplicate definitions (gcc 4.2) when including swapper.h in multiple files ? Thanks -Mathieu --------swapper.h----------- #ifndef swapper_h #define...
11
by: mdh | last post by:
I decided to make a single file containing all the repetitive functions in K&R so that I could concentrate on the new discussions. This went along just fine, and with each new function, added the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.