Roboczy przykład przesyłania plików AJAX do usługi WCF
Szukam przykładu wywołania ajax do przesyłania strumieniowego danych do usługi WCF. Zawsze dostaję błąd. Każda pomoc doceniana, a nawet linki do blogów z rozwiązaniem. To jest moja klasa usług WCF
[ServiceBehavior(InstanceContextMode = InstanceContextMode.PerCall)]
public class Images : IImages
{
string IImages.UploadImage(string fileKey, Stream imageStream)
{
using (var fileStream = File.Create(@"Images\" + fileKey))
{
imageStream.CopyTo(fileStream);
}
return "done";
}
}
a moja umowa jest
[OperationContract(Name = "UploadImage")]
[WebInvoke(UriTemplate = "?file_key={fileKey}", Method = "POST", ResponseFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.Bare)]
string UploadImage(string fileKey, Stream imageStream);
Mam powiązanie strumienia web.config
<binding name="PublicStreamBinding"
maxReceivedMessageSize="2000000000" transferMode="Streamed">
<security mode="None" />
</binding>
moje wywołanie klienta ajax jest takie
var data = '{"image":"' + uri + '"}'
$.ajax({
url: GetServerUrl()+"images.svc/?file_key="+options.fileKey,
type: "POST",
contentType: "application/json",
data: data,
success: function (result) {
console.log("SUCCESS");
},
error: function (jqXHR, textStatus, errorThrown) {
console.log("error in transfer::" + jqXHR.responceText);
}
});