Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6868157
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T03:23:58+00:00 2026-05-27T03:23:58+00:00

i am working on a project that need to upload files from iphone to

  • 0

i am working on a project that need to upload files from iphone to wcf service. i dont have experience on both wcf and afnetworking. i’ve stuck on this step for days and heres the progress that i’ve made:

WCF Service for uploading files: note that i’ve copied this code from Codeproject website.

public interface ITransferService
{
[OperationContract]
RemoteFileInfo DownloadFile(DownloadRequest request);

[OperationContract]
 void UploadFile(RemoteFileInfo request); 
}

    public void UploadFile(RemoteFileInfo request)
{
    FileStream targetStream = null;
    Stream sourceStream =  request.FileByteStream;

    string uploadFolder = @"C:\upload\";

    string filePath = Path.Combine(uploadFolder, request.FileName);

    using (targetStream = new FileStream(filePath, FileMode.Create, 
                          FileAccess.Write, FileShare.None))
    {
        //read from the input stream in 65000 byte chunks

        const int bufferLen = 65000;
        byte[] buffer = new byte[bufferLen];
        int count = 0;
        while ((count = sourceStream.Read(buffer, 0, bufferLen)) > 0)
        {
            // save to output stream
            targetStream.Write(buffer, 0, count);
        }
        targetStream.Close();
        sourceStream.Close();
    }

}

The upload code works good on the client program came with the sourcode, i can upload any size and any type or files through the wcf service.

I’ve also found that AFNetworking framework is quite popular on ios, so i’ve decided to use it. heres my code for uploading file:

i’ve come this far, please help me in this situation. thanks for helping

OK, heres the new information:

Fırst of all, the c# code to upload file to the wcf service (which is working)

protected void Button1_Click(object sender, EventArgs e)
{ 
if (FileUpload1.HasFile)
{
    System.IO.FileInfo fileInfo = 
           new System.IO.FileInfo(FileUpload1.PostedFile.FileName);
    FileTransferServiceReference.ITransferService clientUpload = 
           new FileTransferServiceReference.TransferServiceClient();
    FileTransferServiceReference.RemoteFileInfo 
           uploadRequestInfo = new RemoteFileInfo();

    using (System.IO.FileStream stream = 
           new System.IO.FileStream(FileUpload1.PostedFile.FileName, 
           System.IO.FileMode.Open, System.IO.FileAccess.Read))
    {
        uploadRequestInfo.FileName = FileUpload1.FileName;
        uploadRequestInfo.Length = fileInfo.Length;
        uploadRequestInfo.FileByteStream = stream;
        clientUpload.UploadFile(uploadRequestInfo);
        //clientUpload.UploadFile(stream);
    }
}
}

Second: The remotefileinfo class that used to upload file to server:

  public class RemoteFileInfo : IDisposable
  {
    [MessageHeader(MustUnderstand = true)]
     public string **FileName**;

    [MessageHeader(MustUnderstand = true)]
    public long **Length**;

    [MessageBodyMember(Order = 1)]
    public System.IO.Stream **FileByteStream**;

    public void Dispose()
    { 
        if (FileByteStream != null)
       {
        FileByteStream.Close();
        FileByteStream = null;
       }
    }   
  }

From all those code i understand that i need to create a request that contains “Filename” “FileLength” and the filedata “FileByteStream”. i tried something in the codes but the server gives error 415 when i try to upload image with this code:

   AFHTTPClient *client= [AFHTTPClient clientWithBaseURL:[NSURL URLWithString:@"http://192.168.2.121:85"]];

UIImage *image = [UIImage imageNamed:@"test.jpg"];
NSData *data = UIImageJPEGRepresentation(image, 0.2);

NSMutableDictionary *parameters = [NSMutableDictionary dictionary];
[parameters setObject:@"test.jpg" forKey:@"FileName"];
[parameters setObject:[NSString stringWithFormat:@"%i",data.length] forKey:@"Length"];

NSMutableURLRequest *myRequest = [client multipartFormRequestWithMethod:@"POST" path:@"/webservice/Transferservice.svc/UploadFile" parameters:parameters constructingBodyWithBlock: ^(id <AFMultipartFormData>formData) {
    [formData appendPartWithFileData:data name:@"RemoteFileInfo" fileName:@"test.jpg" mimeType:@"image/jpeg"];
}];

AFHTTPRequestOperation *operation = [[AFHTTPRequestOperation alloc]initWithRequest:myRequest];
[operation 
 setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) {
     NSLog(@"success: %@", operation.responseString);
 } 
 failure:^(AFHTTPRequestOperation *operation, NSError *error) {
     NSLog(@"error: %@", operation.error);
 }
 ];

[[[NSOperationQueue alloc] init] addOperation:operation];

also here is the WSDL Link for the service :

WSDL Link

i really need to do this, thanks for helping again…

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T03:23:59+00:00Added an answer on May 27, 2026 at 3:23 am

    Finally, i’ve succeded on uploading a file to WCF via filestream. The problem was the previous code was expecting a header and a stream in the body which i couldnt find a way to do that. instead, i’ve found that i need to write a code that only acceps a stream as parameter, nothing much, and then the filename and other stuff will be done at the serverside.

    i’ve got that upload code for wcf service from this question: WCF service to accept a post encoded multipart/form-data

    did exactly whats written in the answer. and in the iphone side, i’ve setup an inputstream for my operation. heres the code for the AFNetworking for uploading files to the wcf service:

    AFHTTPClient *client= [AFHTTPClient clientWithBaseURL:[NSURL URLWithString:@"http://192.168.2.121:85"]];
    
    UIImage *image = [UIImage imageNamed:@"test.jpg"];
    NSData *data = UIImageJPEGRepresentation(image, 0.2);
    NSInputStream *stream = [[[NSInputStream alloc]initWithData:data] retain];
    NSDictionary *parameters = nil;
    
    NSMutableURLRequest *myRequest = [client requestWithMethod:@"POST" path:@"/uploadservice/service1.svc/Upload" parameters:nil];
    AFHTTPRequestOperation *operation = [[AFHTTPRequestOperation alloc]initWithRequest:myRequest];
    
     [
     operation 
     setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) {
         NSLog(@"success: %@", operation.responseString);
     } 
     failure:^(AFHTTPRequestOperation *operation, NSError *error) {
         NSLog(@"error: %@", operation.error);
     }
     ];
    
    operation.inputStream = stream; //Thats where you put your stream!
    
    [[[NSOperationQueue alloc] init] addOperation:operation];
    

    Thanks everyone for their patience, even your replies wasnt the complete answer, your replies led me to the correct answers…

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i am working on an iphone project that i need to upload relatively large
I'm working on a project where I have 2 web services that need the
I have a project that I'm working on and I need to be able
I need to have an at-home project now that I'm working on Python/Django at
Im working on a Java project that needs to upload files using either REST
i am working on a small project that i need the ability to let
I am working with asp.net website project that some of pages need authentication. I
I am working a project that does not have a trunk / branches /
I´m working on a project that basically will show some data collected from hardware
Im currently working on a project that requires the following. I need to be

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.