Silverlight WCF RIA service Not Found
2013-07-24 13:05
435 查看
完整记录新建一个简单的silverlight+wcf ria services的过程。
STEP 1:新建一个silverlight应用程序
STEP 2:新建一个wcf ria servies class library
生成的RIAServicesLibrary2.Web这种名称的类库就是所谓的服务端,RIAServicesLibrary2就是所谓的客户端。
STEP 3 添加服务
[EnableClientAccess()]
public class DomainService2 : DomainService
{
//[Invoke]
public string Test()
{
return "aaa";
}
//[Invoke]
public string GetData(int id)
{
//Sample sp = new Sample();
//return sp.SelectData(id);
return "Hello World";
}
}
在查阅资料的时候有同学说方法上要加[Invoke],经测试不加也是可以的。
STEP 4 配置
A web.config
<configuration>
<system.web>
<httpModules>
<add name="DomainServiceModule" type="System.ServiceModel.DomainServices.Hosting.DomainServiceHttpModule, System.ServiceModel.DomainServices.Hosting, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
</httpModules>
<compilation debug="true" targetFramework="4.0" />
<customErrors mode="Off"></customErrors>
</system.web>
<system.serviceModel>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
</system.serviceModel>
</configuration>
其中<httpModules>和 <system.serviceModel>经我测试是必须要有的,否则会报如下错误。
{System.Windows.ApplicationUnhandledExceptionEventArgs}
base {System.EventArgs}: {System.Windows.ApplicationUnhandledExceptionEventArgs}
ExceptionObject: {System.ServiceModel.DomainServices.Client.DomainOperationException: Invoke operation 'GetData' failed. 远程服务器返回了错误: NotFound。 ---> System.ServiceModel.CommunicationException: 远程服务器返回了错误: NotFound。 ---> System.Net.WebException: 远程服务器返回了错误: NotFound。 ---> System.Net.WebException: 远程服务器返回了错误: NotFound。
B 需要将RIAServicesLibrary2和RIAServicesLibrary2.Web中生成的.dll文件拷至 网站根目录下的bin文件夹内。
STEP 5 测试
InvokeOperation<string> o = null;
RIAServicesLibrary2.Web.DomainService2 s = new RIAServicesLibrary2.Web.DomainService2();
o = s.GetData(1, Callback, "abc");
s.Test(Callback, "111");
void Callback(InvokeOperation<string> io)
{
try
{
if (io.UserState.ToString() == "abc")
this.tb1.Text = io.Value;
else
this.tb2.Text = io.Value;
Console.WriteLine(io.Value);
}
catch (Exception ex)
{
Console.WriteLine(ex);
}
}
InvokeOperation<string>类型的对象有Completed事件,不过个人建议使用上述写法。
过程中遇到的问题与总结:
1、少做了第4步,一直报异常如下。
{System.Windows.ApplicationUnhandledExceptionEventArgs}
base {System.EventArgs}: {System.Windows.ApplicationUnhandledExceptionEventArgs}
ExceptionObject: {System.ServiceModel.DomainServices.Client.DomainOperationException: Invoke operation 'GetData' failed. 远程服务器返回了错误: NotFound。 ---> System.ServiceModel.CommunicationException: 远程服务器返回了错误: NotFound。 ---> System.Net.WebException: 远程服务器返回了错误: NotFound。 ---> System.Net.WebException: 远程服务器返回了错误: NotFound。
参考资料:/article/1435938.html
http://blogs.msdn.com/b/webapps/archive/2013/01/11/how-to-resolve-not-found-error-in-silverlight-for-wcf-ria-services-calls.aspx
http://msdn.microsoft.com/en-us/library/ff426913(v=VS.91).aspx
代码
相关文章推荐
- Silverlight调用WCFRIAService 'Not Found'错误小结
- Silverlight中服务通信方式的选择(WCF、Data Service、Ria Service)
- SilverLight中使用WCF Ria出现的问题empty domain service class
- Silverlight应用框架雏形:MVVM+WCF RIA Service + 业务逻辑层+自写的实体框架
- Silverlight中服务通信方式的选择(WCF、Data Service、Ria Service)
- 使用Entity Framework和WCF Ria Services开发SilverLight之7:多个Domain Service间共享Poco实体
- Silverlight使用WebService,WCF,RIA Service的同步方法
- WCF, the Service attribute value in the ServiceHost directive could not be found.
- 使用Entity Framework和WCF Ria Services开发SilverLight之7:多个Domain Service间共享Poco实体
- Silverlight WCF RIA Service也遭遇了一次编码问题
- Silverlight DataGrid使用WCF RIA Service实现Load-on-demand的数据加载
- [Silverlight学习笔记]关于利用WCF RIA Service进行通信并在客户端获取数据
- Silverlight中服务通信方式的选择(WCF、Data Service、Ria Service)
- Silverlight DataGrid使用WCF RIA Service实现Load-on-demand的数据加载
- Silverlight MVVM + WCF Ria Service 餐馆点菜DEMO
- [silverlight] WCF RIA Service的Validation数据验证
- Silverlight DataGrid使用WCF RIA Service实现Load-on-demand的数据加载
- SilverLight使用WCF RIA SERVICE实现对数据库的操作 (添加,删除,更新)
- [Silverlight]WCF RIA SERVICE如何返回自定义类型(非Entity)
- Silverlight Business Application 与 WCF Ria Service的使用 (3)