I have a WCF webservice to receive files but when i make a post call always return me Unsuported media type multipart-form-data when i try to send a file, if i dont send file and set contentype to xml, service get me an OK and create the file pruebffa.jpg fine
this is my web.config:
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="streamBinding" transferMode="Streamed" messageEncoding="Mtom" maxReceivedMessageSize="615424521" openTimeout="00:10:00" sendTimeout="00:10:00" receiveTimeout="00:10:00"/>
</basicHttpBinding>
</bindings>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true"/>
<services>
<service name="WcfService3.Service1" behaviorConfiguration="WcfService3.Service1Behavior">
<endpoint address="" binding="basicHttpBinding" bindingConfiguration="streamBinding" contract="WcfService3.IService1">
<identity>
<dns value="localhost"/>
</identity>
</endpoint>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="WcfService3.Service1Behavior">
<!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment -->
<serviceMetadata httpGetEnabled="true"/>
<!-- To receive exception details in faults for debugging purposes, set the value below to true. Set to false before deployment to avoid disclosing exception information -->
<serviceDebug includeExceptionDetailInFaults="false"/>
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
code:
[ServiceContract]
public interface IService1
{
[OperationContract]
[WebGet(BodyStyle=WebMessageBodyStyle.Bare, UriTemplate="")]
void UploadImage(Stream image);
}
public class Service1 : IService1
{
public void UploadImage(Stream image)
{
var buf = new byte[1024];
var path = Path.Combine(@"C:\", "pruebffa.jpg");
int len = 0;
using (var fs = File.Create(path))
{
while ((len = image.Read(buf, 0, buf.Length)) > 0)
{
fs.Write(buf, 0, len);
}
}
}
}
How can i enabled to accept multipart/form-data?
Since it’s a POST operation you should use
WebInvokeinstead ofWebGet.