我試圖通過創建一個WCF REST服務,並已成功實施了經[WebInvoke(Method = "GET")]
問題:在.NET
調用的函數REST服務現在我想創建一個使用Method="POST"
更新功能。這會導致405:方法不允許。我懷疑我可能需要在我的web.config中配置一些東西。
我在VS2010調試器中運行我的wcf服務時出現此錯誤。
這是服務的定義:
[OperationContract]
[WebInvoke(Method = "POST", ResponseFormat = WebMessageFormat.Xml, BodyStyle = WebMessageBodyStyle.Bare,
UriTemplate = "object/{id}?status={status}&reason={reason}")]
Textblock SetObjectStatus(string id, string status, string reason);
當我打電話通過HttpWebRequest req
此方法Method = "POST"
我得到一個錯誤405:不允許的方法。
我的web.config文件看起來是這樣的:
<?xml version="1.0"?>
<configuration>
<system.web>
<compilation debug="true" targetFramework="4.0" />
</system.web>
<system.serviceModel>
<services>
<service behaviorConfiguration="ServiceBehaviour" name="WcfService1.TextblockService">
<endpoint address="" behaviorConfiguration="web" binding="webHttpBinding" contract="WcfService1.ITextblockService" />
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="ServiceBehaviour">
<!-- 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="true"/>
</behavior>
</serviceBehaviors>
<endpointBehaviors>
<behavior name="web">
<webHttp/>
</behavior>
</endpointBehaviors>
</behaviors>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
</system.serviceModel>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true"/>
</system.webServer>
</configuration>
你也發送了什麼URL? – SecretDeveloper 2011-03-30 08:45:33
我使用的URL是:GET請求的http:// localhost:54270/Service1.svc/object/1和POST請求的http:// localhost:54270/Service1.svc/object。 – 2011-03-30 09:00:41
@Secret開發人員:謝謝。你的問題引發了另一個新的面貌,現在我發現了這個問題。 – 2011-03-30 10:35:08