Ionic1 controller file ionic
istruzioniService.caricaDocumentoCompilato(formData)
.then(function(res) {
if (res.Esito == true) {
console.log('allegaFileCompilato : OK ')
} else {
console.log('allegaFileCompilato : ERRORE Esito = false')
}
},
function(error) {
console.log('allegaFileCompilato : ERRORE - ' + error.body)
});
}
Call this in my service file ionic
result.caricaDocumentoCompilato = function(_stream) {
var self = this;
return $q(
function(resolve, reject) {
try {
remoteService
.post(EasyWork.SERVER_LINK + '/json/CaricaDocumentoCompilato', { stream: _stream }, true)
.then(
function(res) {
resolve(res);
},
function(error) {
console.error('caricaDocumentoCompilato ERRORE -> ' + error.message);
reject(error);
}
)
} catch (error) {
console.error('caricaDocumentoCompilato ERRORE -> ' + error.message);
reject(error);
}
}
);
}
Finally in my C# WCF service
public EsitoOperazione CaricaDocumentoCompilato(Stream stream)
{
using (TransactionScope())
{
try
{
BinaryReader reader = new BinaryReader(stream);
byte[] photo = reader.ReadBytes((int)stream.Length);
reader.Close();
// CODE
var esito = new EsitoOperazione();
esito.Esito = true;
esito.Messaggio = "Documento caricato correttamente";
return esito;
}
catch (Exception e)
{
var esito = new EsitoOperazione();
esito.Esito = false;
esito.Messaggio = e.Message;
return esito;
}
}
}
C# function debug doesn't start, and GET ERROR 400
Il server ha riscontrato un errore durante l'elaborazione della richiesta.
Messaggio dell'eccezione: 'Il messaggio in arrivo per l'operazione
'CaricaDocumentoCompilato' (contratto '' con spazio dei nomi
'http://tempuri.org/') contiene un valore 'Json' del formato del corpo del messaggio http non riconosciuto.
Il valore previsto del formato del corpo del messaggio è 'Raw'.
Ciò può essere dovuto a un WebContentTypeMapper non configurato nell'associazione. Vedere la documentazione di WebContentTypeMapper per maggiori dettagli.'.
Per ulteriori dettagli, vedere i log del server. Traccia di stack dell'eccezione:
in System.ServiceModel.Dispatcher.HttpStreamFormatter.GetStreamFromMessage(Message message, Boolean isRequest)
in System.ServiceModel.Dispatcher.HttpStreamFormatter.DeserializeRequest(Message message, Object[] parameters)
in System.ServiceModel.Dispatcher.UriTemplateDispatchFormatter.DeserializeRequest(Message message, Object[] parameters) in System.ServiceModel.Dispatcher.CompositeDispatchFormatter.DeserializeRequest(Message message, Object[] parameters)
in System.ServiceModel.Dispatcher.DispatchOperationRuntime.DeserializeInputs(MessageRpc& rpc)
in System.ServiceModel.Dispatcher.DispatchOperationRuntime.InvokeBegin(MessageRpc& rpc) in System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage5(MessageRpc& rpc)
in System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage41(MessageRpc& rpc)
in System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage4(MessageRpc& rpc)
in System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage31(MessageRpc& rpc)
in System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage3(MessageRpc& rpc)
in System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage2(MessageRpc& rpc)
in System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage11(MessageRpc& rpc)
in System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage1(MessageRpc& rpc)
in System.ServiceModel.Dispatcher.MessageRpc.Process(Boolean isOperationContextSet