2

I'm working with the eBay Large Merchant Services. I have successfully gotten the basic AddFixedPriceItem job to work using .NET HttpClient (finally). However, depending on the content of my AddFixedPriceItem XML file, the response to the uploadFile job would return:

Please specify a File with Valid Format

I'm not able to pinpoint what is causing this error.

Example #1:

I have a file with 2 AddFixedPriceItemRequest requests, which would go up successfully, and a file with 3 AddFixedPriceItemRequest requests which would not. When I would remove some NameValueList tags from the 3rd request, it would work. I don't see anything wrong or different with those NameValueList tags that I removed. If I send up the 3rd request by itself, without removing any tags it works perfectly.

Example #2:

I have 1 AddFixedPriceItemRequest request in a file that contains CDATA information for the Description tag (for HTML values), which would go up successfully, and another file with 2 AddFixedPriceItemRequest requests also containing almost identical CDATA values but would not work. If I remove the CDATA from the added second request, it still does not work. If I also remove the CDATA from the 1st request as well ( which went up successfully by itself the first time around) then it does work.

I'm really confused by this. There seems to be no rhyme and reason as to which a file is considered "valid".

Below is an example of a request that failed: (Stack Overflow doesn't seem to be taking the Content-IDs - but they are there.)

POST http://storage.sandbox.ebay.com/FileTransferService HTTP/1.1
X-EBAY-SOA-SECURITY-TOKEN: xxx
X-EBAY-SOA-SERVICE-NAME: FileTransferService
X-EBAY-SOA-SERVICE-VERSION: 1.0.0
X-EBAY-SOA-OPERATION-NAME: uploadFile
X-EBAY-SOA-OPERATION-FORMAT: XML
Content-Type: multipart/related; boundary="MIME_boundary"; type="application/xop+xml"; start="<0.urn:uuid:9ce221c2-659d-4852-a166-51dcbccf68d9>"; start-info="text/xml"
Host: storage.sandbox.ebay.com
Content-Length: 3041
Expect: 100-continue

--MIME_boundary
Content-Type: application/xop+xml
Content-ID: <0.urn:uuid:9ce221c2-659d-4852-a166-51dcbccf68d9>
Content-Transfer-Encoding: binary

<?xml version="1.0" encoding="utf-8"?><uploadFileRequest xmlns="http://www.ebay.com/marketplace/services"><fileAttachment><Data><xop:Include href="cid:urn:uuid:c6f7fc4d-352b-414f-8638-6c9bdf40519e"  xmlns:xop="http://www.w3.org/2004/08/xop/include"/></Data><Size>1710</Size></fileAttachment><fileFormat>zip</fileFormat><fileReferenceId>50008675134</fileReferenceId><taskReferenceId>50008489744</taskReferenceId></uploadFileRequest>
--MIME_boundary
Content-Type: application/octet-stream
Content-Transfer-Encoding: base64
Content-ID: <urn:uuid:c6f7fc4d-352b-414f-8638-6c9bdf40519e>

UEsDBBQAAAAIAMZZ9UhnranV5gUAADYmAAAPACQAYWRkbGlzdGluZ3MueG1sCgAgAAAAAAABABgA4roeimLj0QE1N5fd4t3RAex2PDlG3dEB7Vptc9o4EP4rmny59kOxDZiXjOoZXppL5kjDxaG5+9QR9gJqbcsny2m4X38rgwEbmJ57zDWd8inSrvaRdq1dPRKh/TT4PGSKvXv2Fiyawz38lUKiEvIcBlHy9iKV0SVM2fKSxTy5hP6ozxIYiDAWEUQquXDoNTAfpEM/gEy4iJxuy6ZG3qEuV3AzdExqrFvUyA16vn/Fn8EfS+7BjYJwPfe/n/qdlEKOcNkpm4MD0ceJS42ikD4yGfFoPoInCJxrPl9QoyA6sm69HocOmIK5kMtbFsdo0QsC8QV8R8kUqHFESQci8rlCFPTWMk10fVeC6jRScunoteZtOkilhMjT0iGK8x4dQuJJHmtbZ8h4JAKMIhmhGwqnJMPRda9lN6/e3PX7xP2Cojc9GRJrNYJcBUJIMmJhTHhE7nhA+jJNFuDjXxH9jT7s4tMhT2KmvMUDD+GWPTsYj7KI3kRPGHz0+kEy7zNOeAtqIXzH/W1CjWNKOhIey+YwO23Tosamn8XZjcHjM+4lDn3PQvjAghRGPFGrrtOXLPKpkbVpptyGAr9YJlipS5ZloNvx+xLMTviqIQkfghNhYQZOycMyhiLeNQvEHKLKUP8dZQBS6c+RfaEi3MDtEYNMRpXwrnjEk0UR6NBerBJ/9kwemVKY4UVczLcvlZDep+EUJBEzooOXlNAqQd09gWRBQIaYK5GuIiU0u0luohq5Jn8Qq5M1H3XTzJrHQ2qUUkRLMbX0jnGK9RPzakdHx9xTqYQhKMaDZNOf3I+chVLxpWHwcF6bCzQIa54IjZsQ45k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CA28LdfOpEsoRBx+rgXBfLXAzDDn2VNm7zvHK8J3fDXJS8WM8HGwp0Et5OcAV1a3zb1znl4Of+OWg2dh/Oai36xVeDr7pmrn3I5fZsVseXortrj1tWp1Wt9Xw/DbzZzbmadOr8COXcex/w5x/AFBLAQItABQAAAAIAMZZ9UhnranV5gUAADYmAAAPACQAAAAAAAAAIAAAAAAAAABhZGRsaXN0aW5ncy54bWwKACAAAAAAAAEAGADiuh6KYuPRATU3l93i3dEB7HY8OUbd0QFQSwUGAAAAAAEAAQBhAAAANwYAAAAA
--MIME_boundary--

Here's how I send the request with HttpClient:

    byte[] data;
long fileLength;
var uuidRequest = Guid.NewGuid().ToString();
var uuidAttachment = Guid.NewGuid().ToString();

using (FileStream fs = File.OpenRead(filePath))
{
    data = new byte[fs.Length];
    fs.Read(data, 0, data.Length);
    fileLength = fs.Length;
}

var xml =
    "<?xml version=\"1.0\" encoding=\"utf-8\"?>" +
    "<uploadFileRequest xmlns=\"http://www.ebay.com/marketplace/services\">" +
        "<fileAttachment>" +
            "<Data><xop:Include href=\"cid:urn:uuid:" + uuidAttachment + "\"  xmlns:xop=\"http://www.w3.org/2004/08/xop/include\"/></Data>" +
            "<Size>" + fileLength + "</Size>" +
        "</fileAttachment>" +
        "<fileFormat>zip</fileFormat>" +
        "<fileReferenceId>" + fileReferenceID + "</fileReferenceId>" +
        "<taskReferenceId>" + jobID + "</taskReferenceId>" +
    "</uploadFileRequest>";

var multippartcontent = new MultipartContent("related", "MIME_boundary");
multippartcontent.Headers.Remove("Content-Type");
multippartcontent.Headers.TryAddWithoutValidation("Content-Type", string.Format("multipart/related; boundary=\"MIME_boundary\"; type=\"application/xop+xml\";start=\"<0.urn:uuid:{0}>\";start-info=\"text/xml\"", uuidRequest));

var content = new StringContent(xml);
content.Headers.ContentType = new MediaTypeHeaderValue("application/xop+xml");
content.Headers.Add("Content-ID", string.Format("<0.urn:uuid:{0}>", uuidRequest));
content.Headers.TryAddWithoutValidation("Content-Transfer-Encoding", "binary");
multippartcontent.Add(content);

var attachmentContent = new StringContent(Convert.ToBase64String(data));
attachmentContent.Headers.ContentType = new MediaTypeHeaderValue("application/octet-stream");
attachmentContent.Headers.TryAddWithoutValidation("Content-Transfer-Encoding", "base64");
attachmentContent.Headers.Add("Content-ID", string.Format("<urn:uuid:{0}>", uuidAttachment));
multippartcontent.Add(attachmentContent);


var uploadFileResp = httpclient.PostAsync(ftServiceUrl, multippartcontent).Result.Content.ReadAsStringAsync().Result;

I would note, when I upload this same file that doesn't work for me with the LMS project from eBay (https://ebaydts.com/eBayKBDetails?KBid=1338). That leads me me to think I'm doing something wrong in my code - perhaps something to do with how I'm encoding?

HTTP Response

HTTP/1.1 200 OK
Server: Apache-Coyote/1.1
X-EBAY-SOA-SERVICE-METRICS: 455075973
X-EBAY-SOA-REQUEST-ID: 15613449-f630-a471-d2d4-ec64ffff71c7!FileTransferService!10.71.29.45!v3apibulksandboxcore[]
X-EBAY-SOA-SERVICE-VERSION: 1.1.0
X-EBAY-SOA-MESSAGE-PROTOCOL: NONE
X-EBAY-SOA-RESPONSE-DATA-FORMAT: XML
X-EBAY-SOA-OPERATION-NAME: uploadFile
X-EBAY-SOA-SERVICE-NAME: {http://www.ebay.com/marketplace/services}FileTransferService
Content-Type: text/xml;charset=UTF-8
Transfer-Encoding: chunked
Date: Fri, 22 Jul 2016 15:41:19 GMT

1cd
<?xml version='1.0' encoding='UTF-8'?><uploadFileResponse xmlns="http://www.ebay.com/marketplace/services"><ack>Failure</ack><errorMessage><error><errorId>11</errorId><domain>Marketplace</domain><severity>Error</severity><category>Application</category><message>Please specify a File with Valid Format</message><subdomain>FileTransfer</subdomain></error></errorMessage><version>1.1.0</version><timestamp>2016-07-22T15:41:20.118Z</timestamp></uploadFileResponse>
0
double-beep
  • 5,031
  • 17
  • 33
  • 41
Rivka
  • 2,172
  • 10
  • 45
  • 74
  • I usually use fiddler in these cases. I first would capture fiddler results with LMS project. Then compare results with c# application. I would check the headers in fiddler captures to see what is different. – jdweng Jul 21 '16 at 01:47
  • There are differences in LMS project request. 1. it's using SOAP 2. the file contents seem to be sent differently binary vs base64 -, although what I've found is that base64 is recommended (ebay forum threads / blog posts). The content looks more like: " ➏W addlistings.xml YY 0 + ^ I уcE -d ! d 8 Ҁ  T / = g = Qi/ > f ތESx PZ yD DF " – Rivka Jul 21 '16 at 15:36
  • Change your header "Content-Transfer-Encoding" to match what is being used in the LMS project. You know that works, why use something different. It is probably GZIP. See : http://stackoverflow.com/questions/19006997/c-sharp-httpwebrequest-using-gzip-compression – jdweng Jul 21 '16 at 16:23
  • LMS has "Content-Transfer-Encoding: binary". I changed mine as well to the same format, changed the header value, and i'm getting the same error - now also for the requests that worked with my original method. Zip should work just as well. Let's remember I have this *working*. It's in certain random cases depending on the XML data where I'm getting this error. – Rivka Jul 21 '16 at 16:39
  • When it failed in original case did the any of the binary convert to readable ascii? I don't like the method you are using to read the file : File.OpenRead(filePath). It defaults to ASCII encoding that removes non-printable characters. I prefer to use UTF8 encoding which doesn't modify data. – jdweng Jul 21 '16 at 17:46

1 Answers1

0

I finally got the answers. The "100 continue" message gave me the needed clues. I was spending too much time trying to understand the intermittent operation.

1) Your code never really works. When you run the LMS project a cookie is establish which is setting up default setting for you request. So your code will always work after running the LMS. If you delete cookies from your IE history your code will never work.

2) The "100 continue message" is used for "Chunk Mode" (not stream). The Net library defaults to HTTP 1.1 and most server these days when the see 1.1 will default to chunk mode. The server sends one chunk , but there is no way in the Net library to request a 2nd chunk from server. So the connection times out and fails. The only way around this issue is to set the HTTP request to HTTP 1.0 which doesn't support chunk mode the server will send the response back as a stream.

Try this

            HttpWebRequest request = (HttpWebRequest)WebRequest.Create("URL");
            request.ProtocolVersion = HttpVersion.Version10;

See also : Set HTTP protocol version in HttpClient

Look at 1st line of request that failed which has 1.1

Community
  • 1
  • 1
jdweng
  • 33,250
  • 2
  • 15
  • 20
  • I appreciate your answer, but: 1. *So your code will always work after running the LMS.* - this statement is incorrect. Even after running LMS it doesn't work, and the files that did work, work even if I don't run LMS before. I also don't see what this has to do with IE cookies. 2. I'm not using HttpWebRequest, and LMS project also has Expect: 100-continue header. Any other ideas? – Rivka Jul 21 '16 at 21:30
  • Did you look at the link I provided for HttpClient? Did you try the fix? When does you code work and when does it fail? When a cookies exists between a client and server the Net Library uses previous setting instead of default settings. So once a Http Connection has been established betwee a client and server using 1.0 the next new connection will also use 1.0. You will always fail with Net Library if the Http header contains 1.1. – jdweng Jul 21 '16 at 22:07
  • The 2 lines of code didn't seem to make it work. So far I came across 2 scenarios where the code doesn't work : as I mentioned in my OP: CDATA issue and the NameValueLists scenarios but I'm sure there are more inconsistencies - I'm only getting started here. The goal here is to upload in *bulk* as in thousands of requests at a time; at this rate, and based on the amount of API issues I've come across already, I can't see it happening. Regarding cookies: looking at fiddler, I don't see any cookies being returned from eBay responses. – Rivka Jul 22 '16 at 15:12
  • First check to see if you are getting 1.0 instead of 1.1 and that you are no longer getting "100 continue". You may be getting a different set of errors. If you are still getting 1.1 then I think you should delete the cookies in your IE history and try again. Net library will not work in chunk mode so we must first solve this issue. Did your request send a cookie with to the server. The server wouldn't of returned a cookie if the sent cookie was still valid? The active cookie would of been for 1.1. So deleting cookie and requesting 1.0 should fix issue. – jdweng Jul 22 '16 at 15:23
  • Let's be clear: 1. There are no cookies being sent or received. 2. LMS has the same header and HTTP version of 1.1. 3. Removing Expect 100 Continue request header doesn't help. 4. I'm getting the same error as before. See my edited OP for raw HTTP response. Also it would be nice if some API support would be available from eBay . There are hardly any resources available out there. – Rivka Jul 22 '16 at 15:45
  • Is you first request going out with an HTTP 1.0 (not 1.1)? If the code change was made properly the request should of been made with 1.0 and the server should of responded with a 1.0. Removing "Expect 100" is also needed. You are now getting "200 ok" which is good but it is still chunk. If you are sending 1.0 and the server is responding with 1.1 Then the server has an error or doesn't support 1.0. Net library doesn't support chunk. LMS is using a different library which supports chunk/http 1.1. – jdweng Jul 22 '16 at 16:34
  • The code change didn't make a difference because I'm not using HttpRequestMessage and SendAsync. I'm constructing the request with HttpClient only. What I don't understand from your explanation is: if .Net library is the one that doesn't support chunk, the error should be on my end upon retrieving the response. So if, as you've said, LMS supports a library with chunk/HTTP 1.1 then they should have no problem processing my chunk/1.1 request and there should not be any errors being sent back from them. – Rivka Jul 25 '16 at 14:04
  • I also don't understand how this can be the issue if there are cases where it works fine, depending on the XML content. Do you mind explaining? – Rivka Jul 25 '16 at 14:05