3
私は、投稿と取得要求を処理する方法を示す安らかなサービスのスケルトンアルゴリズムを作成しています。私の例からgetはうまくいきますが、投稿はしません。私はweb.configに何かを追加すべきだと思いますが、何や理由がわかりません。事前に感謝、Zoli。wcf安らかなサービス設定エラー
[ServiceContract]
public interface IRestfulService
{
[OperationContract]
[WebGet(UriTemplate = "/GetAStudent")]
Student GetExistingStudent();
[OperationContract]
[WebInvoke(UriTemplate = "/GetTheGivenStudent/{studentName}", Method = "POST")]
Student GetGivenStudent(string studentName);
}
public class RestfulService : IRestfulService
{
public Student GetExistingStudent()
{
Student stdObj = new Student
{
StudentName = "Foo",
Age = 29,
Mark = 95
};
return stdObj;
}
public Student GetGivenStudent(string studentName)
{
Student stdObj = new Student
{
StudentName = studentName,
Age = 29,
Mark = 95
};
return stdObj;
}
}
[DataContract]
public class Student
{
[DataMember]
public string StudentName { get; set; }
[DataMember]
public int Age { get; set; }
[DataMember]
public double Mark { get; set; }
}
web.configファイル:
<system.web>
<compilation debug="true" targetFramework="4.0" />
</system.web>
<system.serviceModel>
<protocolMapping>
<add scheme="http" binding="webHttpBinding"/>
</protocolMapping>
<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>
<endpointBehaviors>
<behavior>
<webHttp />
</behavior >
</endpointBehaviors>
</behaviors>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
</system.serviceModel>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true"/>
</system.webServer>
このようなjsonエンドポイントを使用または追加することを選択してください。どちらをPOSTとして使用すると思いますか?最初のメソッドは宣言されていません。もう1つはGET – Michel
例外はありますか? –
投稿を修正しました。今それは正しい、私はポストとして働くことを期待する。私が得るエラーは次のとおりです。エンドポイントが見つかりません –