Hi,

I'm building my own simple Messenger via Intranet using WCF...but i've a little problem with sending an attachment.

I attached the project to check it and here's the steps to follow in order to test the project:
1-Run the SimpleSvcHost( to run the service).
2-Run the SimpleClient.
3-choose one user from the lstbox at the right and click File-->Open then choose a file...no error will occur in this part of the code

if (openFileDialog.ShowDialog() == DialogResult.OK)
            {
                FileStream fs = new FileStream(openFileDialog.FileName, FileMode.Open, FileAccess.Read);
                proxy.Upload(openFileDialog.FileName,fs);

                this.AutoScroll = true;
                this.Invalidate();
            }

but the file will not be sent...

Thanks in Advance,

Mostafa Fouly

I modified the code to receive the attachment but i got the following error while debugging the SimpleSvcHost class...
The operation Upload either has a parameter or a return type that is attributed
with MessageContractAttribute.
In order to represent the request message using a Message Contract,
the operation must have a single parameter attributed with MessageContractAttribute.
In order to represent the response message using a Message Contract,
the operation's return value must be a type that is attributed with
MessageContractAttribute and the operation may not have any out or ref parameters.

N.B i attached the modified code.

I think this part of code will cause a runtime error

if (openFileDialog.ShowDialog() == DialogResult.OK)
            {
                FileStream fs = new FileStream(openFileDialog.FileName, FileMode.Open, FileAccess.Read);
                proxy.Uploading(lstContacts.SelectedItem.ToString(), openFileDialog.FileName,fs);

                this.AutoScroll = true;
                this.Invalidate();
            }

that's because i'm sending the the filestream as a parameter to the Upload function while filestream can be said to be a pointer to a file on the hard disk it's not the file itself...so i think i've to read the file at the client side then send it to the server...

well i solved sending the attachment problem by reading the data a byte array at the client side then passing it to proxy.Upload as show below:

System.Text.Encoding enc = System.Text.Encoding.GetEncoding(0);
 byte[] Data = System.IO.File.ReadAllBytes(openFileDialog.FileName);
                string s1 = enc.GetString(Data);
proxy.Upload(openFileDialog.FileName, lstContacts.SelectedItem.ToString(), Data);

and about the OperationContract Upload it can't take more than 1 parameter as FileTransferRequest is a MessageContract.

N.B: I attached the project to check it.

This question has already been answered. Start a new discussion instead.