如何在ASP.NET Core中修复WrongInputException? [英] How to fix WrongInputException in ASP.NET Core?

查看:88
本文介绍了如何在ASP.NET Core中修复WrongInputException?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用由另一个团队准备的SOAP Web服务,该Web服务在ASP.NET Core中准备的新REST API中内部使用.我的Web服务客户端代码使用

I want to use a SOAP web service prepared by another team, used internally in my new REST API prepared in ASP.NET Core. My web service client code was scaffolded with WCF Web Service Reference Provider Tool. I cleaned up code (e.g. I changed property and method names) according to my team's naming convention.

当我通过新的REST API发送请求时,我收到了 WrongInputException .我检查了示例请求中的所有参数,所有参数都在使用C#代码的脚手架客户端中的同一位置.

When I send requests by my new REST API, I received WrongInputException. I checked all the parameters from an example request, all of them are in the same place in my C# code consuming scaffolded client.

我不知道我的新REST API确切发送了什么消息.

I don't know what message exactly is sent by my new REST API.

推荐答案

就我而言,所描述行为和 WrongInputException 的主要原因是

In my case, the main cause of the described behavior and WrongInputException was premature refactoring. I changed the names of properties in the web service client without knowledge of the consequences.

例如如果请求正文中的元素是 objectRefNum ,那么我不能简单地更改脚手架服务引用类中的相关属性,因为-在没有额外配置的情况下-该名称使用相同的字母大小写复制到请求中SOAP信封的主体. SOAP信封应该以区分大小写的方式进行编码.

E.g. if the element in the request body is objectRefNum, then I cannot simply change the related property in the scaffolded service reference class, because - without extra configuration - that name is copied with the same letter case to the request body of the SOAP envelope. The SOAP envelope should be encoded in the case-sensitive mode.

要跟踪我的新REST API在ASP.NET Core中发送的原始请求正文,我遵循了这个绝佳答案的说明.

To trace the raw request body send by my new REST API in ASP.NET Core, I followed instructions from this excellent answer.

(请注意,顺便说一句,IDE可能会处理这种错误(应用不适当的字母大小写),至少作为警告,但事实并非如此,因此:在进行重构时,即使我们必须谨慎操作.拥有涵盖所有路径的单元测试,即使我们使用IDE支持的语义重命名.)

(Note, BTW, that kind of error (applying inappropriate letter case) could be handled by IDE, at least as a warning, but it is not, so: we need to be careful when we make refactoring, even if we have unit tests covering all the paths, and even if we use semantic renaming supported by IDE.)

这篇关于如何在ASP.NET Core中修复WrongInputException?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆