views:

500

answers:

4

Hi.

I am designing a multi-file upload service that also shows upload progress for each file.

If I was to design my WCF method as a SOAP contract, I would do something like this:

var request = IService.UploadMethod(List<Upload> request);

But, how do I pass the parameter ""request"" of type "List<Upload>" when I am calling the method from the client (../upload.svc/ uploadpictures/""request"")?

Help appreciated, thanks.

A: 

You're using SOAP as you say yourself - which means, you cannot just invoke your service methods from the URL (REST-style), as the second part of your posting would imply (../upload.svc/ uploadpictures/"request").

What you need to do in SOAP is this (assuming you've created your client side proxy using Visual Studio or svcutil):

// create client side proxy, reading URI etc. from config
ServiceClient clientProxy = new ServiceClient();

List<Upload> _list = new List<Upload>();

// add your uploads - don't know what that is - just a filename? The actual
// contents of the file? That's up to you
_list.Add(..........);

var response = clientProxy.UploadMethod(_list);

Marc

marc_s
Marc - My response is in the above (or below) "Answer". Thanks for your thoughts.
Code Sherpa
A: 

Thanks for your answer.

I am using SOAP for part of my API, but I am also using webhttp endpoints for REST - style xhr calls and JSON responses. I have been able to do this elsewhere in the program:

var url = "trade.svc/GetCategoryChildren/" + parentID + "/json";
        var httpStatus;
        xmlhttp.open("GET", url, true);
        xmlhttp.send(null);

I am trying to do the same thing for my upload service but, as you point out, collecting List<Upload> request = new List<Upload>(); is C#, not JavaScript and I am not quite sure how to pass the parameter in a REST way. Is this possible? Thoughts appreciated?

<service behaviorConfiguration="Default" name="WebClient.UploadService">
        <endpoint address="json" behaviorConfiguration="WebHttpEPBehavior"
                  binding="webHttpBinding" name="MyJSONUploadEP" contract="WebClient.IJSONUploadService" />
        <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
        <host>
          <baseAddresses>
            <add baseAddress="http://localhost:2534/Web/upload.svc" />
          </baseAddresses>
        </host>
      </service>


IN RESPONSE TO SAHA -

The request should look similar to the xmlhttp request object I have outlined in my previous post. You want to pass your endpoint as the URL argument in xmlhttp.open("GET", url, true). Your parameters should follow the same convention: "service.svc/function/param1/param2/param3".

On the server, you want to design your service's binding as webHttpBinding - take a look at MyJSONUploadEP in my posted config file. Then, in your contract (In my example, WebClient.IJSONUploadService) you want to designate the WebGet attribute with a responeformat of JSON for your requested method. In my contract I have:

[WebGet(UriTemplate = "GetCategoryChildrenJSON/{parentID}/{format}", ResponseFormat = WebMessageFormat.Json)]
Tuple<string, int> GetCategoryChildren(string parentID, string format);

As an aside, I found it useful to have different contracts for different response formats (IJSONUploadService.cs, IPOXUploadService.cs, and ISOAPUploadService.cs which are then inherited as needed). So, for example, your WCF class would look something like:

public class UploadService : IJSONUploadService

If you want to return a number of integers in your JSON response, you should probably design a supporting class with get/set of type integer - something like:

 public class Items
     {
        public int PropA { get; set; }
        public int PropB { get; set; }
        public int PropC { get; set; }
        public int PropD { get; set; }
        public int PropE { get; set; }
        etc... 
     }

Then, after you retrieve your data from the DB, you will need to populate your List (of type Items in this case):

List<Items> categories = new List<Items>();

Next, you will need to serialize your List of type Items for sending back to the client. I am using a class called JSONHelper to do this but there are plenty examples on the Internet. You might start by looking up the
"System.Runtime.Serialization.Json" namespace. Here is what my object for serialization looks like:

string dtSerialized = JSONHelper.Serialize<List<Items>>(categories);
Tuple<int, int> retParam = new Tuple<int, int>(dtSerialized, errCode);
return retParam;

And finally, on the client you will need to handle the JSON response using some sort of JavaScript response handler. There are tons of examples of this online - you might want to try starting with http://json.org/js.html.

HTH, Peter

Code Sherpa
you should just edit your original question and extend it / clarify it, instead of adding your own answer
marc_s
A: 

Did you get answer to this question, I was having the same problem. I would like to call the WCF Rest service method which has a List of strings as input parameter and list of integers as output parameter. How do i give the request from my flex application, binding="webHttpBinding" data format is JSON

saha
Saha - see above for my response. Let me know if you need more clarification.
Code Sherpa
A: 

my url is http://dev1/ytd/StatusService.svc/GetAvailableLocationsListJSON

    [OperationContract]
    [WebInvoke(ResponseFormat = WebMessageFormat.Json)]
    List<int> GetAvailableLocationsListJSON(List<string> peoples);

I am not bothered on the WCF side, I do have the above contract given by a .NET team and need to call this service method from Flex. How do i call this method from Flex. The GetAvailableLocationsListJSON does not do any JSON serialization. This is a simple class which takes locations and displays the people numbers in thosel ocations. My job is to invoke this method from Flex. Please help

Saha
Sorry Saha, I don't know anything about flex. Try posting a question here (if you haven't already) with flex in the tag group. The question I posted in this thread has nothing to do with what we are discussing and you won't get any other responders except me - and I am not much help when it comes to flex... sorry :(.
Code Sherpa