从Silverlight Web应用程序调用WCF服务方法 [英] Call a WCF Service method from Silverlight Web app

查看:75
本文介绍了从Silverlight Web应用程序调用WCF服务方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


我正在开发一个Silverlight Web应用程序,该应用程序使用WCF服务方法与数据库进行交互. 我得到了System.ServiceModel.CommunicationException.我不知道哪里出了问题.这是Im使用...的代码部分...

在MainPage.xaml.cs中:

Hi
I am developing a silverlight web application which uses WCF service methods to interact with database..
I got System.ServiceModel.CommunicationException. I dont know where it went wrong. Here is the code section Im using...

In MainPage.xaml.cs:

private void btnUpdate_Click(object sender, RoutedEventArgs e)
        {
            c.GetNameCompleted += new  EventHandler<GetNameCompletedEventArgs>(c_GetNameCompleted);
            c.GetNameAsync();
        }

        void c_GetNameCompleted(object sender, GetNameCompletedEventArgs e)
        {
            txtCustName.Text = (string)e.Result;
        }


在此先感谢,
Naresh.


Thanks in Advance,
Naresh.

推荐答案

问题是,当您在asp.net Web项目中添加WCF服务时,默认情况下它将wsHttpBinding添加为默认配置.现在看起来Silverlight尚未实现WSHttpBinding,因此我在客户端使用BasicHttpBinding. WSHttpBinding使用SOAP 1.2,而BasicHttpBinding使用SOAP 1.1&因此协议异常.您可能猜到的解决方案是将web.config更改为具有binding ="basicHttoBinding"->刷新SL项目中的服务引用.
The issue is when you add a WCF service in your asp.net web project it by default adds the wsHttpBinding as a default configuration. Now looks like the Silverlight does not have WSHttpBinding implemented yet so I was using BasicHttpBinding on the client side. WSHttpBinding uses SOAP 1.2 while BasicHttpBinding uses SOAP 1.1 & hence the protocol exception. The solution as you might guess is to change your web.config to have binding="basicHttoBinding" -> refresh the service ref in SL project.


这篇关于从Silverlight Web应用程序调用WCF服务方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆