I’m not sure exactly how to phrase this, but here goes:
I have a custom class called EmailAttachment which has 3 properties/attributes defined. An object of this class is passed to a method (in another class, of course) called UploadAttachment
void UploadAttachment(EmailAttachment attachment);
However, when I implement this using, for example,
client.UploadAttachment(emailAttachmentInstance)
Visual Studio tells me that UploadAttachment does not accept 1 argument instead it accepts 3 (ie the variables from the class definition).
This has me quite confused so any help is appreciated
To clarify a bit…
client is actually an instance of a WCF service. The service interface includes
[OperationContract]
void UploadAttachment(EmailAttachment attachment); //which is public.
Following is the class in question…
[MessageContract]
public class EmailAttachment
{
[MessageHeader(MustUnderstand = true)]
public int EmailID;
[MessageHeader(MustUnderstand = true)]
public string FileName;
[MessageBodyMember(Order = 1)]
public Stream AttachmentFile;
}
So here’s my answer (partially conjecture/hypothesis of a friend)…
I guess it has to do with the nature of the WCF service. In order to prevent complications client-side (i.e. being dependent on class(es) defined by the service), the client can pass the attributes/properties (the 3 mentioned previously) of the [service] class as the arguments of the method (in this case
UploadAttachment()). Therefore, it only needs to know the data types of those attributes/properties, and does not have to instantiate an object of its class. The same can be done for custom return types.For example, if
SomeClassis defined as such……and the service has a method that returns a value of
SomeClasslike so……the client can call
SomeMethod()like so…instead of having to instantiate
SomeClass.Hopefully that makes sense.