【问题标题】:Passing file data to C# WCF Service function (Error 400 Bad Request)将文件数据传递给 C# WCF 服务函数(错误 400 错误请求)
【发布时间】:2021-10-24 19:25:11
【问题描述】:

Ionic1 控制器文件 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)
                    });
        }

在我的服务文件 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);
                    }
                }
            );

        }

最后在我的 C# WCF 服务中

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# 函数调试未启动,并且 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

【问题讨论】:

    标签: c# wcf ionic-framework service


    【解决方案1】:

    不确定是否在配置文件中声明了绑定类型,需要显式声明,像这样:

    <endpoint address="" bindingConfiguration="BasicHttpBinding_IServicioSalud" binding="basicHttpBinding" contract="IServicioSalud" />
    

    如果设置,您可以根据提示查看WebContentTypeMapper文档。

    看看这个错误的其他解决方案:HTTP Bad Request error when requesting a WCF service contract

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-04-27
      • 2015-11-24
      • 2019-06-07
      • 2011-09-29
      • 2014-01-11
      • 1970-01-01
      • 2013-11-24
      • 2012-12-01
      相关资源
      最近更新 更多