擾人的RIA Service not found訊息解決方式
在撰寫RIA Service時,有時候錯誤訊息只有一個not found,原因參考http://blog.darkthread.net/blogs/darkthreadtw/archive/2010/07/08/ria-nofound-error.aspx.
不過文中並無解決方式,後來又在網路上尋得解決之道如下.
1.安裝後方網頁中的WCF RIA Services Toolkit (http://www.silverlight.net/getstarted/riaservices/)
2.於Silverlight的Web專案中加入參考Microsoft.ServiceModel.DomainServices.Hosting.dll,並注意Copy Local是否為True.
3.修改web.config
於<configSection>區段下第一行加入
<configSections>
<sectionGroup name="system.serviceModel">
<section name="domainServices"
type="System.ServiceModel.DomainServices.Hosting.DomainServicesSection, System.ServiceModel.DomainServices.Hosting, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"
allowDefinition="MachineToApplication"
requirePermission="false" />
</sectionGroup>
</configSections>
再加入
<system.diagnostics>
<sources>
<source name="System.ServiceModel" switchValue="Information" propagateActivity="false">
<listeners>
<add name="InMemoryTraceListener" />
</listeners>
</source>
</sources>
<sharedListeners>
<add
type="Microsoft.ServiceModel.DomainServices.Hosting.InMemoryTraceListener, Microsoft.ServiceModel.DomainServices.Hosting"
name="InMemoryTraceListener" />
</sharedListeners>
</system.diagnostics>
於<system.serviceModel>區段內加入粗體部分
<system.serviceModel>
……
<domainServices>
<endpoints>
<add
name="traces"
type="Microsoft.ServiceModel.DomainServices.Hosting.TracingDomainServiceEndpointFactory, Microsoft.ServiceModel.DomainServices.Hosting"
maxEntries="200" />
</endpoints>
</domainServices>
</system.serviceModel>
完成後就能透過TraceListener幫我們記錄WCF的追蹤記錄.
然後就可以透過瀏覽器瀏覽追蹤記錄.
瀏覽方式為http://hostname/yourwcfservice.svc/traces/
譬如
http://localhost:1189/MyDomainService.svc/traces/
而.svc實際上之名稱,可以瀏覽RIA Service於silverlight端產生的Generated_Code目錄下的相關.g.cs檔案.
Log畫面如下.
而如要加大log紀錄可以修改上面web.config中的maxEntries數字.