2

Fiddler 2 を使用して POST すると失敗する単純な REST サービス エンドポイントがあります。入力パラメーターを必要としないエンドポイントは成功します。データを渡すだけでは失敗します。VS 2010 に統合された Web サーバーを使用しています。

詳細:

Global.asax エントリ:

private void Application_Start(object sender, EventArgs e)
        {
            RegisterRoutes();
        }
    private void RegisterRoutes()
        {
            RouteTable.Routes.Add(new ServiceRoute("Employee", new WebServiceHostFactory(), typeof(Employee)));
            RouteTable.Routes.Add(new ServiceRoute("Provider", new WebServiceHostFactory(), typeof(Provider)));
        }

ウェブサービス:

[ServiceContract]
        [AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
        [ServiceBehavior(InstanceContextMode = InstanceContextMode.PerCall)]
        public class Provider : BaseMvpWebService<ProviderPresenter>, IProvider

    [WebInvoke(Method="POST", RequestFormat=WebMessageFormat.Json, UriTemplate="",      ResponseFormat=WebMessageFormat.Json, BodyStyle=WebMessageBodyStyle.Wrapped)]
        public ProviderListWrap FilteredList(GeneralSearchView filtersearch)
    { ... }

Web 構成エントリ:

    <system.serviceModel>
        <standardEndpoints>
          <webHttpEndpoint>
        <!-- 
            Configure the WCF REST service base address via the global.asax.cs file and the default endpoint 
            via the attributes on the <standardEndpoint> element below
        -->
        <standardEndpoint name="" helpEnabled="true" automaticFormatSelectionEnabled="true"/>
      </webHttpEndpoint>
    </standardEndpoints>
    <behaviors>
      <serviceBehaviors>
        <behavior>
          <!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment -->
          <serviceMetadata httpGetEnabled="true"/>
          <!-- To receive exception details in faults for debugging purposes, set the value below to true.  Set to false before deployment to avoid disclosing exception information -->
          <serviceDebug includeExceptionDetailInFaults="false"/>
        </behavior>
      </serviceBehaviors>
    </behaviors>
    <serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
  </system.serviceModel>     

パラメータ タイプの定義:

 [DataContract]
 public class GeneralSearchView : IGeneralSearchView
 {
    [DataMember]
    public string ProviderListing { get; set; }

    [DataMember]
    public string FundingSource { get; set; }

    [DataMember]
    public string ProviderType { get; set; }

    [DataMember]
    public string ServiceType { get; set; }

    [DataMember]
    public string UserZipCode { get; set; }

    [DataMember]
    public string SearchRadius { get; set; }

    [DataMember]
    public string SearchCounty { get; set; }
 }

Fiddler 2 経由の投稿:

POST  http://localhost:19099/Provider/

リクエスト ヘッダー

User-Agent: Fiddler
Content-Type: application\json
Host: localhost:19099
Content-Length: 43

リクエスト本文

{"filtersearch":{"ProviderListing":"True"}}

生のレスポンス

HTTP/1.1 400 Bad Request
Server: ASP.NET Development Server/10.0.0.0
Date: Fri, 29 Jun 2012 17:31:35 GMT
X-AspNet-Version: 4.0.30319
Content-Length: 1770
Set-Cookie: ASP.NET_SessionId=qgvgtxlcvdouut2qgq40u4eh; path=/; HttpOnly
Cache-Control: private
Content-Type: text/html
Connection: Close

<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <title>Request Error</title>
    <style>BODY { color: #000000; background-color: white; font-family: Verdana; margin-left: 0px; margin-top: 0px; } #content { margin-left: 30px; font-size: .70em; padding-bottom: 2em; } A:link { color: #336699; font-weight: bold; text-decoration: underline; } A:visited { color: #6699cc; font-weight: bold; text-decoration: underline; } A:active { color: #336699; font-weight: bold; text-decoration: underline; } .heading1 { background-color: #003366; border-bottom: #336699 6px solid; color: #ffffff; font-family: Tahoma; font-size: 26px; font-weight: normal;margin: 0em 0em 10px -20px; padding-bottom: 8px; padding-left: 30px;padding-top: 16px;} pre { font-size:small; background-color: #e5e5cc; padding: 5px; font-family: Courier New; margin-top: 0px; border: 1px #f0f0e0 solid; white-space: pre-wrap; white-space: -pre-wrap; word-wrap: break-word; } table { border-collapse: collapse; border-spacing: 0px; font-family: Verdana;} table th { border-right: 2px white solid; border-bottom: 2px white solid; font-weight: bold; background-color: #cecf9c;} table td { border-right: 2px white solid; border-bottom: 2px white solid; background-color: #e5e5cc;}</style>
  </head>
  <body>
    <div id="content">
      <p class="heading1">Request Error</p>
      <p xmlns="">The server encountered an error processing the request. Please see the <a rel="help-page" href="http://localhost:19099/Provider/help">service help page</a> for constructing valid requests to the service.</p>
    </div>
  </body>
</html>

アイデア/フィードバックをいただければ幸いです。ありがとう!

4

1 に答える 1

1

コンテンツ タイプのスラッシュに構文上の問題があるのではないかと考えています。試す:

コンテンツ タイプ: アプリケーション/json

そうでない場合、応答に他の詳細はありますか? ちょうど 400 の悪い要求ですか?

于 2012-06-29T17:18:54.623 に答える