Returning a file from a custom web service

Can you help me on this below query?

I have and data file in folder in c:/ drive, can i expose that file through AX web service so that end user can download it.

Regards

Rahul

You can create a custom service and call any arbitrary code there, including reading from a file.

(Rahul also asked for an example; unfortunately the post wasn’t moved when I split the thread).

You have two fundamentally different options, nevertheless the implementation is quite similar:

  • Read the complete content of the file in X++ and return it from your service method. If it’s a text file, your service may return a simple string. If it’s a binary file, you would probably return a byte array.
  • You can create a stream of data, which may be necessary if your file is too large. (See Large Data and Streaming).

I don’t know either your input not the required output, so it’s difficult to give you any specific advice.

Hi Martin,

can we get some example code for above example.

Regards

Rahul

Rahul, I’m not going to write code for all combinations of input formats, output formats, way of streaming and so on. And if I randomly choose one (e.g. reading a text file and returning it as string), it may be useless for you and waste of time for me (if you, for example, want to read any file and return is as a byte array. You’ll have to define what you want to implement before writing code.

Also, please explain what’s the part you’re struggling with. For example, if you already know how to read a file, there is no reason why I should write another example for you.

Hi Martin,

today i have identify one more issue, when i am trying to deploy activate the inbound service i am getting the error :- the network path not found.