0

ReSTful 構造を使用して、単一の POST メソッドを受け入れてデータベースを更新する Web アプリケーションを作成したいと考えています。

私の問題は、(フィドラーを使用して) JSON オブジェクトを URL に投稿すると、エラー 404 が表示されることです。

私が呼び出そうとしているメソッドは、以下の属性を使用して公開されています。

[WebInvoke(Method="POST", UriTemplate="projectors", RequestFormat=WebMessageFormat.Json,BodyStyle=WebMessageBodyStyle.Wrapped )]
[OperationContract]
void RecordBreakdown(string sn, int modelCode); 

Web 構成ファイルには、公開されたメソッドにバインドするサービスがあります。以下は抽象化です。

<system.serviceModel>
  <bindings/>
  <services>
      <service name="VIServiceToolServiceLibrary.ProjectorService"
               behaviorConfiguration="RESTBehaviour">
      <endpoint address="" 
              binding="webHttpBinding"
              contract="VIServiceToolServiceLibrary.IProjectorService"
               behaviorConfiguration="RESTEndPointbehaviour"  />
      <host>
        <baseAddresses>
          <add baseAddress="http://localhost:8080/projectorservice/" />
        </baseAddresses>
      </host>
    </service>
  </services>

<behaviors>      
  <serviceBehaviors>
    <behavior name="RESTBehaviour">
      <serviceMetadata httpGetEnabled="true"/>
      <serviceDebug includeExceptionDetailInFaults="true"/>
    </behavior>
  </serviceBehaviors>      
  <endpointBehaviors>
    <behavior name="RESTEndPointbehaviour">
      <webHttp/>
    </behavior>
  </endpointBehaviors>      
</behaviors>

VS または IIS で Web アプリを実行すると、svc ファイルが正常に表示されます。

http://localhost:5970/Service.svc
http://localhost/vi/Service.svc

しかし、リクエストを投稿すると、エラー 404 メッセージが表示されます

POST http://localhost/vi/projectors HTTP/1.1
User-Agent: Fiddler
Host: localhost
Content-Length: 27

{sn:"23434", modelCode:34 }

ありがとう

4

1 に答える 1

1

エラー 404 は 2 つの理由で発生していました。

1回目:ベースアドレスが間違っていました。置き換えられた以前のバージョンの命名規則を使用していました

2回目:POSTメソッドのURLが間違っていました。localhost/vi/Service.svc/projectors のように、サービス ファイルの名前を URL に含める必要がありました。

問題を解決するために、次の記事が役立つこともわかりました http://msdn.microsoft.com/en-us/library/dd203052.aspx

于 2013-05-07T12:22:37.830 に答える