Click here to Skip to main content
13,091,134 members (93,498 online)
Rate this:
Please Sign up or sign in to vote.
See more:
Here is what I am trying to do (unsuccessfully, I might add) and would appreciate any direction you can give me

From my HTML5 site, I want to upload a file to a cross domain WCF service that is hosted in IIS 7.5.

In addition to uploading the files, I need to send additional parameters to the upload fucntion on the server

Is this possible to do?

Here is what my operationContract looks like:

    [WebInvoke( Method = "POST",
    UriTemplate = "/uploadmodeldata/?id={Id}&customerdatatype={customerdatatype}&data={data}")]
    void UploadModelData(string Id, string customerdataType, byte[] data);

Here is what my jquery ajax request

function FileVisits() {

       var uid = checkCookie1();
       userid = uid.toString().replace(/"/g, '');
       var fileData = JSON.stringify({
      Id:userid ,customerdatatype:scanupload,
           data: $('#fileBinary').val()
           "use strict";
           var wcfServiceUrl = "http://xxxxx:1337/Service1.svc/XMLService/";
               cache: false,
               url: wcfServiceUrl + "uploadmodeldata/",
               data: fileData,
               type: "POST",
               processData: false,
               contentType: "application/json",
               timeout: 10000,
               dataType: "json",
               headers:    {
                           'User-agent': 'Mozilla/5.0 (compatible) Greasemonkey',
                           'Accept': 'application/atom+xml,application/xml,text/xml',
               beforeSend: function (xhr) {

                   xhr.setRequestHeader("Content-type", "application/x-www-form-urlencoded");

               complete: function () {

               success: function (data) {
                   var result = data;

               error: function (data) {


if file size is less then 100 kb this error occurred

> Method not allowed

but if file is greater then 100 kb this error occurred

> 413 Request entity to large

How can I upload a file from jquery ajax to cross domain wcf.
Posted 19-Mar-13 2:01am
Ankur\m/ 19-Mar-13 8:39am
These might also help -

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1


Add following line before $.ajax = true;
Then add setting parameter crossDomain: true, to your $.ajax call and finally change dataType to text. It should allow you to POST.

Please also have a look at this[^] CodeProject article as well to know more about ajax uploading without JQuery.

MindFresher 19-Mar-13 9:12am
thanks for reply. i have set = true; and crossDomain: true, dataType to text. But its not working. 400 Bad request error occurred.
Prasad Khandekar 19-Mar-13 10:21am

If you have firefox and HTTPFox plugin try to look at the request and see if it's well formed. The 400 Bad Request means that the data stream sent by the client (e.g. your Web browser or our CheckUpDown robot) was 'malformed'. Go through this ( article to see if anything applies to your service.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy |
Web01 | 2.8.170813.1 | Last Updated 19 Mar 2013
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100