I have created a web service and I have added my quite simple function, obtaining as a parameter a field of type Stream
.
After that I have tried to test from the SoapUI. When the MTOM is not activated, everything goes correctly, the problem arises when it is required.
HTTP/1.1 415 Cannot process the message because the content type 'multipart/related; type="application/xop+xml"; start=""; start-info="text/xml"; boundary="----=_Part_133_2094112.1548776402204"' was not the expected type 'text/xml; charset=utf-8'.
I have managed to solve it after many hours and I think it can be useful for the community, so I post it step by step in the answer.
I understand that the part of creating a project etc. we all already know, anyway I summarize it.
I have created a project
WCF
and within it a serviceSVC
.CREATE THE SERVICE
The first thing I have done is add my function to the file
svc
A simple function that takes a
Stream
how parameter and returnsint
as a response (the intent ofint
is to handle error codes to notify clients that call it).After finishing with my function I have named it in the interface.
WEB.CONFIG
This part is the one that gives me the most problems, forget what it generates by default, the mapping of the binding etc. I recommend you copy this code directly and then enter a security issue, etc. after having tested that everything works correctly:
It is important to name the well
binding
and call it properly in all places, in my case it is "basicHttp".The name of
servicio
the and thecontract
must be the same as the project. If not it won't work.The type of binding I have placed
basicHttpBinding
but obviously it will depend on the type of project you have.Finally it is very important that we do not forget to encode the binding:
messageEncoding="Mtom"
.SoapUI
The same, I understand that we know how to test services in the program, in any case on the same website it is quite well indicated.
Something that I would like to indicate is that it
ID
must be the same as the numbercid
and not the one automatically generated by the program.We activate
MTOM
in the properties that appear below on the left. I have put it to force its use too.With this the communication should work without any problem, if we debug we can see that it
stream
arrives correctly and in SoapUI we see thatWSDL
it is returning a "1".STREAM TO FILE
He
Stream
is not justStream
anyone, he is given as suchbodyStream
that his transformation into a file directly is impossible. (if anyone knows how to do it please comment).In my case I have solved this part by passing it to
Memory stream
and from that to aFileStream
(it doesn't directly convert me). I save theFilestream
in the desired path and fly!CONTRIBUTIONS
I hope it helps you and any contribution is welcome, I don't know the subject well either, but I've wasted many hours looking for a solution that I hope will save other people time ;P