ASP.NET MVC 到 Silverlight 通信
因此,我有一个 ASP.NET MVC Web 应用程序,其中嵌入了 silverlight 应用程序,并且我希望 SL 客户端通过在 ASP 内部运行的支持 SL 的 WCF 服务与数据库进行通信。 NET MVC 应用程序。我没有运气让它工作,silverlight 应用程序很好地获得了对 WCF 服务的服务引用。当我运行 silverlight 客户端并调用 Web 服务时,它每次都会返回 NOT FOUND 异常。我可以通过调试看到 WCF 服务确实被调用,但 silverlight 出错并且没有任何信息传回。
我确实尝试启用
serviceDebug includeExceptionDetailInFaults="true"
但我仍然收到 NOT FOUND 异常。有什么想法吗?
So I have an ASP.NET MVC web application that has a silverlight application embedded in it and I'd like the SL client to communicate with the database through a SL enabled WCF service that runs inside the ASP.NET MVC application. I have had no luck in getting this to work, the silverlight application gets a service reference to the WCF service just fine. When I run the silverlight client and call the web service it returns a NOT FOUND exception every single time. I can see through debugging that the WCF service does get called, but the silverlight errors out and nothing gets passed back.
I did try enabling the
serviceDebug includeExceptionDetailInFaults="true"
But I still get the NOT FOUND exception. Any thoughts?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
第一个技巧是让您的 silverlight 与您的 WCF 正确通信。 NOT FOUND 在很多情况下都会发生。可能是您的 Web 服务未在 IIS 中运行,也可能是您尝试使用某种违反服务契约的对象进行通信。例如,您的对象有一个“对象”类型的属性,可以是任何东西。缩小此过程范围的第一步是安装 Fiddler2 以显示客户端和服务器之间的网络流量。
一旦完成此操作,即一旦您确定您的 silverlight 应用程序可以与网络服务器通信,那么您就可以采取在 asp.net 和 silverlight 应用程序之间进行通信的方法。现在,请记住,Silverlight 在客户端上运行,而 asp.net 在服务器上运行,因此,从页面后面的 aspx 代码到 silverlight light 对象的通信必须通过某种常见代理进行 - 该代理是 JavaScript。定义一个 javascript 方法,该方法将访问 silverlight/对象容器的桥并传递该方法。反之亦然,定义一个允许 silverlight 与 javascript 对话的方法。
例如,假设您有一个在 silverlight 中显示在 aspx/html 页面上的类别列表。最有可能的是,该类别列表存在于您的 asp.net 项目的 ClientBin 文件夹中的 XAP 文件中。
示例:
接下来,在 Silverlight 项目的加载事件中,将对象注册为可编写脚本:
}
定义 javascript 方法来与类别列表视图模型中的某些方法对话
}
定义 SelectCategory 方法:
如果您想从另一个调用此方法页面上的 silverlight 对象:
最后,您应该能够在页面上使用 html/aspx 标记来调用 javascript 方法来调用 silverlight 对象。
享受。
The first trick would be to get your silverlight to communicate with your WCF properly. NOT FOUND occurs on MANY scenarios. It could be that your Web Service is not running in IIS, it could be that you are trying to communicate using some sort of object that violates the service contract. E.g. Your object has a property of type "object" that can be anything. The first step to narrow down this process would be to install Fiddler2 to show you the network traffic between your client and your server.
Once this is done, i.e., once you are sure that your silverlight app can communicate with the webserver, then you can take the approach of communicating between your asp.net and silverlight application. Now, keep in mind that Silverlight runs on the client, and asp.net runs on the server, therefore, communicating from and aspx code behind page to a silverlight light object must happen through some sort of common proxy - that proxy being JavaScript. Define a javascript method that would access a bridge to the silverlight/object container and pass the method. And vice versa, define a method that would allow the silverlight to talk back to the javascript.
For example, let's say you have a category listing that is displayed in silverlight on your aspx/html page. Most likely, that category listing exists in a XAP file in you ClientBin folder for your asp.net project.
Example:
Next, in your loaded event for your Silverlight Project, register the object as scriptable:
}
Define the javascript method to talk to some method in the category listing view model
}
Define the SelectCategory Method:
If you wanted to call this method from ANOTHER silverlight object on the page:
At the end of it all, you should be able to use your html/aspx markup on your page to invoke the javascript method to call the silverlight object.
Enjoy.
我能够弄清楚这一点 - 我用作数据契约的对象没有被标记为这样,即使它们被 silverlight 应用程序“接受”并且由服务引用生成,它们始终会在 WCF 服务之后通过此接受回来了。
I was able to figure this out - the objects I was using as data contracts were not marked as such and even though they were "accepted" by the silverlight app and were generated by the service reference they would always through this acception after the WCF service returned.