3
我創建了一個寧靜服務的框架算法,顯示如何處理帖子和獲取請求。從我的例子得到工作正常,但後沒有。我想我應該添加到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>
您希望哪一個作爲POST工作?第一個沒有聲明方法,只有另一個GET – Michel 2012-04-12 14:43:30
你會得到什麼例外? – 2012-04-12 14:44:16
我修改了帖子。現在是對的,我希望第二個職位能成爲職位。我得到的錯誤是:終點沒有找到 – 2012-04-12 15:05:05