【问题标题】:Webservice respond with 400 Bad Request带有 400 错误请求的 Web 服务响应
【发布时间】:2011-10-21 11:15:23
【问题描述】:

我在 ASP .Net 4.0 中有一个标准的 web 服务,定义如下:

       [WebMethod]
        public string MyWebServiceRequest(string data)
        {
           //Code
        }

字符串的大小约为 10K 字节,当尝试发送到此 Web 服务时,我收到 400 错误请求。如果我只发送几行就可以了。

据我所知,默认的最大大小约为 65KB,还是我错了?我在事件查看器等中没有得到好的错误。有没有办法强制记录网络服务的错误?

更新: 如果这可能导致我的问题,是否允许您在字符串中具有任何限制?

这是我对我要发送的实际数据的请求。正如一个注释,我已经设法通过删除其中一行来发送它,但我不明白为什么这行会导致请求失败。

Score Lines then - Is Arrow, NS Pair, EW Pair, NS Score, Round
            NoSlam Tricks(+ or -, 6 or 7), Points NS & EW, Adjustments NS &
            EW, Penalties NS & EW, Contract, By, TricksMade, Lead,
            Table,Spare

整个 XML 请求

    <?xml version="1.0" encoding="UTF-8" standalone="no"?>
<soap12:Envelope xmlns:soap12="http://www.w3.org/2003/05/soap-envelope">
    <soap12:Body>
        <tns:xTournamentResultDatFile
            xmlns:tns="http://www.mywebsite.com/">
            <!-- Zero or one occurrences -->
            <tns:datFile>
                Version,8 ID1 - Type, Date Serial, Description, Section, Web
                File Name, Sessions P,40805,,,2011sep19.htm,1 ID2 - BridgeMate,
                IsStratified, 3x spares 0,0,0,0,0 Profile Tables, NTotal,
                ETotal, Pairs, Is 2 Winners, Min Details, ScoreMethod, Color
                5,5,5,10,-1,0,0,0 Swiss, E_Individual,Teams BPM Stored,0,0,0 Is
                VPs, VPs are Stored, Is Teams Travellers 0,0,0 Is Done -
                Movement, Tables, Sheets -1,-1,-1 Teams Entered as Imps, Teams
                Boards, Boards Per Set,-1,25,5 Results - pair number then 2 x
                Player Nos, Score, G Slams, S Slams Master Points, Orientation,
                Score, Score Divisor,Handicap, 2 x Player Names,Green Points
                Score Lines Count,Green Point, Is Handicapped, V3,10,0,0
                3,9,10,5400,0,0,25,N,108,200,0,Player Nine,Player Ten 0
                2,5,6,5050,0,0,10,N,101,200,0,Player Five,Player Six 0
                5,17,18,5050,0,0,10,N,101,200,0,Player Seventeen,Player Eighteen
                0 1,1,2,5000,0,0,0,N,100,200,0,Player One,Player Two 0
                4,13,14,4500,0,0,0,N,90,200,0,Player Thirteen,Player Fourteen 0
                7,7,8,7000,0,0,25,E,140,200,0,Player Seven,Player Eight 0
                10,19,20,5100,0,0,13,E,102,200,0,Player Nineteen,Player Twenty 0
                9,15,16,4700,0,0,0,E,94,200,0,Player Fithteen,Player Sixteen 0
                6,3,4,4250,0,0,0,E,85,200,0,Player Three,Player Four 0
                8,11,12,3950,0,0,0,E,79,200,0,Player Elven,Player Twelwe 0 ESE
                MPs Auto Calc,0 Master Points - Awarded, Printed, e File Serial,
                Serial Start, Hand Title, Spare 10,0,0,0,,S Master Pointing
                Score Level, CBAI Club Factor,1,0 Is a Qualifinal,
                Tables,#FALSE#,0 SABF - Grading, Is Closed, Is Mixed,0,0,0 No
                MPs For Event,0 SMPC Adjustment Method,
                E_ABFRestricted,E_ABFMFactor ,1,0,1 Table Allocations,5 N/S
                Pair, E/W Pair,4 x Player numbers, 2 x Spares 1,6,1,2,3,4,S,S
                2,7,5,6,7,8,S,S 3,8,9,10,11,12,S,S 4,9,13,14,15,16,S,S
                5,10,17,18,19,20,S,S Movement Not New Move, Name,
                Type,-1,Straight Mitchell - Boards Down, Pairs Up,M Board Sets,
                Boards Per Set, Max Rounds, Rounds Missed, Round 1 Not Played
                5,5,5,0,0 Missing Pair No, Missing Pair is NS, Pair Numbers
                Duped, EW Pair No Offset 0,0,-1,5 Is a Rover, Rover Table No,
                Rover Is NS, Standard Rover 0,0,0,0 Feed In Table, Boards Down
                1,0,0 Mitchell Skip Early +4 Spares,0,S,S,S,S Arrow Count,0
                Score Sheets Is NSNumbered, Are Slams, Butler Scoring Exclusions
                -1,0,1 Expected Min Score Lines, SMPC, Max Score Lines 5,-1,5
                Aggregate UpperLimit,1000 Order SS By Score, No Score Check &
                Spare,0,0,S Sheet Count 2,25 Show Contract,spare, spare,0,0,0
                Score Lines then - Is Arrow, NS Pair, EW Pair, NS Score, Round
                NoSlam Tricks(+ or -, 6 or 7), Points NS & EW, Adjustments NS &
                EW, Penalties NS & EW, Contract, By, TricksMade, Lead,
                Table,Spare 5 0,1,1,50,1,0,4,4,-1,-1,0,0,, ,0,,1,0
                0,2,3,100,5,0,7,1,-1,-1,0,0,, ,0,,2,0
                0,3,5,100,4,0,7,1,-1,-1,0,0,, ,0,,3,0
                0,4,2,-420,3,0,1,7,-1,-1,0,0,, ,0,,4,0
                0,5,4,-420,2,0,1,7,-1,-1,0,0,, ,0,,5,0 5
                0,1,1,500,1,0,3,5,-1,-1,0,0,, ,0,,1,0
                0,2,3,500,5,0,3,5,-1,-1,0,0,, ,0,,2,0
                0,3,5,620,4,0,7,1,-1,-1,0,0,, ,0,,3,0
                0,4,2,620,3,0,7,1,-1,-1,0,0,, ,0,,4,0
                0,5,4,-100,2,0,0,8,-1,-1,0,0,, ,0,,5,0 5
                0,1,1,140,1,0,4,4,-1,-1,0,0,, ,0,,1,0
                0,2,3,140,5,0,4,4,-1,-1,0,0,, ,0,,2,0
                0,3,5,140,4,0,4,4,-1,-1,0,0,, ,0,,3,0
                0,4,2,-50,3,0,0,8,-1,-1,0,0,, ,0,,4,0
                0,5,4,170,2,0,8,0,-1,-1,0,0,, ,0,,5,0 5
                0,1,1,-170,1,0,5,3,-1,-1,0,0,, ,0,,1,0
                0,2,3,-170,5,0,5,3,-1,-1,0,0,, ,0,,2,0
                0,3,5,-170,4,0,5,3,-1,-1,0,0,, ,0,,3,0
                0,4,2,-620,3,0,0,8,-1,-1,0,0,, ,0,,4,0
                0,5,4,-170,2,0,5,3,-1,-1,0,0,, ,0,,5,0 5
                0,1,1,600,1,0,3,5,-1,-1,0,0,, ,0,,1,0
                0,2,3,600,5,0,3,5,-1,-1,0,0,, ,0,,2,0
                0,3,5,600,4,0,3,5,-1,-1,0,0,, ,0,,3,0
                0,4,2,600,3,0,3,5,-1,-1,0,0,, ,0,,4,0
                0,5,4,630,2,0,8,0,-1,-1,0,0,, ,0,,5,0 5
                0,1,5,-620,2,0,3,5,-1,-1,0,0,, ,0,,1,0
                0,2,2,-620,1,0,3,5,-1,-1,0,0,, ,0,,2,0
                0,3,4,-600,5,0,7,1,-1,-1,0,0,, ,0,,3,0
                0,4,1,-630,4,0,0,8,-1,-1,0,0,, ,0,,4,0
                0,5,3,-600,3,0,7,1,-1,-1,0,0,, ,0,,5,0 5
                0,1,5,-100,2,0,2,6,-1,-1,0,0,, ,0,,1,0
                0,2,2,-100,1,0,2,6,-1,-1,0,0,, ,0,,2,0
                0,3,4,-100,5,0,2,6,-1,-1,0,0,, ,0,,3,0
                0,4,1,140,4,0,8,0,-1,-1,0,0,, ,0,,4,0
                0,5,3,110,3,0,6,2,-1,-1,0,0,, ,0,,5,0 5
                0,1,5,420,2,0,4,4,-1,-1,0,0,, ,0,,1,0
                0,2,2,420,1,0,4,4,-1,-1,0,0,, ,0,,2,0
                0,3,4,420,5,0,4,4,-1,-1,0,0,, ,0,,3,0
                0,4,1,420,4,0,4,4,-1,-1,0,0,, ,0,,4,0
                0,5,3,420,3,0,4,4,-1,-1,0,0,, ,0,,5,0 5
                0,1,5,420,2,0,1,7,-1,-1,0,0,, ,0,,1,0
                0,2,2,420,1,0,1,7,-1,-1,0,0,, ,0,,2,0
                0,3,4,450,5,0,5,3,-1,-1,0,0,, ,0,,3,0
                0,4,1,450,4,0,5,3,-1,-1,0,0,, ,0,,4,0
                0,5,3,480,3,0,8,0,-1,-1,0,0,, ,0,,5,0 5
                0,1,5,-140,2,0,5,3,-1,-1,0,0,, ,0,,1,0
                0,2,2,-140,1,0,5,3,-1,-1,0,0,, ,0,,2,0
                0,3,4,-170,5,0,2,6,-1,-1,0,0,, ,0,,3,0
                0,4,1,-110,4,0,8,0,-1,-1,0,0,, ,0,,4,0
                0,5,3,-200,3,0,0,8,-1,-1,0,0,, ,0,,5,0 5
                0,1,4,300,3,0,6,2,-1,-1,0,0,, ,0,,1,0
                0,2,1,110,2,0,4,4,-1,-1,0,0,, ,0,,2,0
                0,3,3,1400,1,0,8,0,-1,-1,0,0,, ,0,,3,0
                0,4,5,-50,5,0,1,7,-1,-1,0,0,, ,0,,4,0
                0,5,2,-50,4,0,1,7,-1,-1,0,0,, ,0,,5,0 5
                0,1,4,170,3,0,1,7,-1,-1,0,0,, ,0,,1,0
                0,2,1,170,2,0,1,7,-1,-1,0,0,, ,0,,2,0
                0,3,3,620,1,0,7,1,-1,-1,0,0,, ,0,,3,0
                0,4,5,620,5,0,7,1,-1,-1,0,0,, ,0,,4,0
                0,5,2,600,4,0,4,4,-1,-1,0,0,, ,0,,5,0 5
                0,1,4,-100,3,0,7,1,-1,-1,0,0,, ,0,,1,0
                0,2,1,-100,2,0,7,1,-1,-1,0,0,, ,0,,2,0
                0,3,3,-170,1,0,2,6,-1,-1,0,0,, ,0,,3,0
                0,4,5,-200,5,0,0,8,-1,-1,0,0,, ,0,,4,0
                0,5,2,-140,4,0,4,4,-1,-1,0,0,, ,0,,5,0 5
                0,1,4,500,3,0,5,3,-1,-1,0,0,, ,0,,1,0
                0,2,1,500,2,0,5,3,-1,-1,0,0,, ,0,,2,0
                0,3,3,690,1,0,8,0,-1,-1,0,0,, ,0,,3,0
                0,4,5,420,5,0,1,7,-1,-1,0,0,, ,0,,4,0
                0,5,2,420,4,0,1,7,-1,-1,0,0,, ,0,,5,0 5
                0,1,4,-100,3,0,3,5,-1,-1,0,0,, ,0,,1,0
                0,2,1,140,2,0,7,1,-1,-1,0,0,, ,0,,2,0
                0,3,3,-100,1,0,3,5,-1,-1,0,0,, ,0,,3,0
                0,4,5,140,5,0,7,1,-1,-1,0,0,, ,0,,4,0
                0,5,2,-200,4,0,0,8,-1,-1,0,0,, ,0,,5,0 5
                0,1,3,170,4,0,5,3,-1,-1,0,0,, ,0,,1,0
                0,2,5,170,3,0,5,3,-1,-1,0,0,, ,0,,2,0
                0,3,2,170,2,0,5,3,-1,-1,0,0,, ,0,,3,0
                0,4,4,140,1,0,0,8,-1,-1,0,0,, ,0,,4,0
                0,5,1,170,5,0,5,3,-1,-1,0,0,, ,0,,5,0 5
                0,1,3,450,4,0,5,3,-1,-1,0,0,, ,0,,1,0
                0,2,5,450,3,0,5,3,-1,-1,0,0,, ,0,,2,0
                0,3,2,300,2,0,0,8,-1,-1,0,0,, ,0,,3,0
                0,4,4,420,1,0,2,6,-1,-1,0,0,, ,0,,4,0
                0,5,1,480,5,0,8,0,-1,-1,0,0,, ,0,,5,0 5
                0,1,3,140,4,0,6,2,-1,-1,0,0,, ,0,,1,0
                0,2,5,-110,3,0,1,7,-1,-1,0,0,, ,0,,2,0
                0,3,2,-110,2,0,1,7,-1,-1,0,0,, ,0,,3,0
                0,4,4,140,1,0,6,2,-1,-1,0,0,, ,0,,4,0
                0,5,1,140,5,0,6,2,-1,-1,0,0,, ,0,,5,0 5
                0,1,3,460,4,0,6,2,-1,-1,0,0,, ,0,,1,0
                0,2,5,460,3,0,6,2,-1,-1,0,0,, ,0,,2,0
                0,3,2,430,2,0,1,7,-1,-1,0,0,, ,0,,3,0
                0,4,4,460,1,0,6,2,-1,-1,0,0,, ,0,,4,0
                0,5,1,430,5,0,1,7,-1,-1,0,0,, ,0,,5,0 5
                0,1,3,600,4,0,7,1,-1,-1,0,0,, ,0,,1,0
                0,2,5,-100,3,0,2,6,-1,-1,0,0,, ,0,,2,0
                0,3,2,-100,2,0,2,6,-1,-1,0,0,, ,0,,3,0
                0,4,4,600,1,0,7,1,-1,-1,0,0,, ,0,,4,0
                0,5,1,-100,5,0,2,6,-1,-1,0,0,, ,0,,5,0 5
                0,1,2,110,5,0,6,2,-1,-1,0,0,, ,0,,1,0
                0,2,4,130,4,0,8,0,-1,-1,0,0,, ,0,,2,0
                0,3,1,-170,3,0,2,6,-1,-1,0,0,, ,0,,3,0
                0,4,3,-420,2,0,0,8,-1,-1,0,0,, ,0,,4,0
                0,5,5,-150,1,0,4,4,-1,-1,0,0,, ,0,,5,0 5
                0,1,2,400,5,0,2,6,-1,-1,0,0,, ,0,,1,0
                0,2,4,400,4,0,2,6,-1,-1,0,0,, ,0,,2,0
                0,3,1,430,3,0,7,1,-1,-1,0,0,, ,0,,3,0
                0,4,3,430,2,0,7,1,-1,-1,0,0,, ,0,,4,0
                0,5,5,400,1,0,2,6,-1,-1,0,0,, ,0,,5,0 5
                0,1,2,690,5,0,0,8,-1,-1,0,0,, ,0,,1,0
                0,2,4,990,4,0,4,4,-1,-1,0,0,, ,0,,2,0
                0,3,1,990,3,0,4,4,-1,-1,0,0,, ,0,,3,0
                0,4,3,1010,2,0,8,0,-1,-1,0,0,, ,0,,4,0
                0,5,5,990,1,0,4,4,-1,-1,0,0,, ,0,,5,0 5
                0,1,2,-980,5,0,2,6,-1,-1,0,0,, ,0,,1,0
                0,2,4,-980,4,0,2,6,-1,-1,0,0,, ,0,,2,0
                0,3,1,100,3,0,7,1,-1,-1,0,0,, ,0,,3,0
                0,4,3,-980,2,0,2,6,-1,-1,0,0,, ,0,,4,0
                0,5,5,100,1,0,7,1,-1,-1,0,0,, ,0,,5,0 5
                0,1,2,420,5,0,5,3,-1,-1,0,0,, ,0,,1,0
                0,2,4,420,4,0,5,3,-1,-1,0,0,, ,0,,2,0
                0,3,1,420,3,0,5,3,-1,-1,0,0,, ,0,,3,0
                0,4,3,-50,2,0,0,8,-1,-1,0,0,, ,0,,4,0
                0,5,5,420,1,0,5,3,-1,-1,0,0,, ,0,,5,0 Split Boards - Count and
                Line numbers,0 Section Pairs Count 2,0 Section Count, 2 x
                spares,0,0,0 Sessions Input,0 VP Type,W EBU Green or SBU
                National Points,0 Swiss Pairing,1,2,1,99 Swiss BPM, DualTables,
                Sections, Alloc LPP, SBU Bonus MP Top,7,-1,A,B,10,0 SBU MPs Per
                Match,0 BWS DB File Path, Quali-final is a Final,0 EBU National
                Pairs Heat,0 Deal File
                Path,C:/BridgeData/Test/DealFiles/2011Sep19!!.dup Swiss Pairs
                Match Being Scored,1 Swiss Pair Numbering,0 Swiss Pair Input
                From TS,0 UK MP Multiplier,1 Last Bm Db Line Read,0 Ecats Hand
                Records Needed, Session No,#FALSE#, Tables For MPs,0 Scorers
                Name, Directors Name,xxxx xxxxx,Mr Director Is Parallel Play,0
                Barometer Event,0 MPs Ignore Minimum Boards Rule,0 Reuse Board
                Count,0 Swiss Pairs Rounds,8 PP Event FileName, QualiFinal
                ScaleQF,0 EBU P2P Charge Rate#ERROR 448#
            </tns:datFile>
        </tns:xTournamentResultDatFile>
    </soap12:Body>
</soap12:Envelope>

【问题讨论】:

  • 通常限制为 4MB,而不是 65K。我建议您确保从客户端调用传递一个字符串,并且参数名称与您的 Web 服务方法(数据)的名称匹配。

标签: asp.net web-services


【解决方案1】:

web.config 中有一个部分控制最大传输大小:

<security>
  <requestFiltering>
   <requestLimits maxAllowedContentLength=”2000000000″ />
  </requestFiltering>
 </security>

但我怀疑那是你真正的问题。您是否尝试过检查Fiddler 中的请求以确保您的页面确实发送了正确的数据? 400 错误可能意味着很多事情,包括发布到畸形的 URL(即 https 而不是 http、错误的主机标头等)。

评论

虽然我在这,你为什么要以这种方式使用 XML 信封?如果您要经历使用 XML/SOAP 的麻烦,为什么不传递一个更好的、对 XML 友好的数据集(带有子节点等)?

【讨论】:

  • 我已经用更多信息更新了帖子。我已经设法发布了请求大小的 5 倍,但随后只使用了字母。
  • @StefanE 这不是大小问题,而是请求格式的问题。特殊字符,如撇号、尖括号、& 符号(我在您的 XML 数据中看到)以及其他一些字符需要转义。你是如何产生请求的?您似乎没有使用任何类型的编码功能。
  • @StefanE 通过 Fiddler (fiddler2.com/fiddler2) 运行请求并使用实际请求内容更新您的问题。 (此外,您可以剪掉大部分重复记录。)
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-10-20
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-08-19
相关资源
最近更新 更多