0
我試圖創建並託管一個簡單的RESTful WCF服務。除1情況外,該服務完美運行。我試圖執行一個POST插入一個新的對象到我使用的JSON請求靜態列表:對RESTful WCF服務的錯誤請求強制IIS回收應用程序池
{"sampleItem":{"Id":1,"StartValue":2,"EndValue":3}}
如果我再改的要求是:
{"sampleItemBlah":{"Id":1,"StartValue":2,"EndValue":3}}
我得到一個500響應,並所有未來的POST都將返回一個500錯誤,直到我回收IIS應用程序池並再次開始工作。
它似乎沒有出現服務處於故障狀態,因爲我仍然可以執行GET並返回數據。我打開了跟蹤調試,並且在日誌文件中看不到任何錯誤。
有沒有人有任何想法?
這裏是我的服務合同:
[ServiceContract]
public interface IWcfRestService
{
[WebInvoke(Method = "POST", BodyStyle = WebMessageBodyStyle.Wrapped, UriTemplate = "", RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json)]
[OperationContract]
SampleItem Insert(SampleItem sampleItem);
}
[DataContract]
public class SampleItem
{
[DataMember]
public int Id { get; set; }
[DataMember]
public int StartValue { get; set; }
[DataMember]
public int EndValue { get; set; }
}
這裏是我的實現:
public class WcfRestService : IWcfRestService
{
private static readonly List<SampleItem> Items = new List<SampleItem>();
public SampleItem Insert(SampleItem sampleItem)
{
return BaseInsert(sampleItem);
}
private static SampleItem BaseInsert(SampleItem sampleItem)
{
if (Items.Exists(x => x.Id == sampleItem.Id))
Items.RemoveAll(x => x.Id == sampleItem.Id);
Items.Add(sampleItem);
return sampleItem;
}
}
最後這裏是我的web.config的我ServiceModel部分:
<services>
<service behaviorConfiguration="Services.ServiceBehavior"
name="WcfRestServiceApp.WcfRestService">
<endpoint address=""
behaviorConfiguration="RESTBehavior"
binding="webHttpBinding"
contract="WcfRestServiceApp.IWcfRestService">
<identity>
<dns value="localhost" />
</identity>
</endpoint>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
</service>
</services>
<behaviors>
<endpointBehaviors>
<behavior name="RESTBehavior">
<webHttp />
</behavior>
</endpointBehaviors>
<serviceBehaviors>
<behavior name="Services.ServiceBehavior">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="false" />
</behavior>
</serviceBehaviors>
</behaviors>
任何和所有的幫助,不勝感激。
K,你是新的。這筆交易。這裏的人們不會調試你的應用程序。但是,如果您將問題縮小到單個特定情況並詢問其發生的原因,您會得到一個很好的答案。如果你拋出一串代碼並問「這裏有什麼問題」,你可能會很幸運,但是你不會這樣做。在這種情況下,最好使用盡可能最少的代碼來創建演示應用程序,以重現問題。這樣,你可以在這三行代碼上尋求幫助,而不是「在這裏的某個地方是一個bug,爲我找到它」。 – Will 2010-03-03 14:28:48
我刪除了所有額外的代碼。我仍然可以用我留下的代碼重新創建問題。我不確定是否在某處丟失了註釋/配置,或者是否有需要更改的IIS設置。 – Brandon 2010-03-03 14:52:54
你在使用什麼客戶端? – 2010-03-03 18:20:54