zoukankan      html  css  js  c++  java
  • C# sliverlight调用WCF服务出现的一个错误

    错误提示如下:

    尝试向 URI“http://localhost:8396/Service1.svc”发出请求时出错。这可能是由于试图以跨域方式访问服务而又没有正确的跨域策略,或策略不适用于 SOAP 服务。您可能需要与该服务的所有者联系,以发布跨域策略文件并确保该文件允许发送 SOAP 相关的 HTTP 标头。出现此错误也可能是由于使用的是 Web 服务代理中的内部类型而没有使用 InternalsVisibleToAttribute 属性。有关详细信息,请参阅内部异常。

    出现问题的过程:

    1、打开vs2013,新建项目sliverlight引用程序

    2、在解决方案中添加一个新建项目wcf服务应用程序

    3、在SilverlightApplication1中添加服务引用,单击"发现"按钮(添加服务之前记得将wcf服务编译生成一下,不然找不到服务)

    4、在SilverlightApplication1中使用wcf服务

    MainPage.xaml.cs添加代码(红框内部分是添加进去的)

    using System.Linq;
    using System.Net;
    using System.Windows;
    using System.Windows.Controls;
    using System.Windows.Documents;
    using System.Windows.Input;
    using System.Windows.Media;
    using System.Windows.Media.Animation;
    using System.Windows.Shapes;
    
    namespace SilverlightApplication1
    {
        public partial class MainPage : UserControl
        {
            public MainPage()
            {
                InitializeComponent();
    
                ServiceReference1.Service1Client client = new ServiceReference1.Service1Client();
                client.GetDataCompleted += client_GetDataCompleted;     //处理返回值的函数
                client.GetDataAsync(1);     //传参数的地方
            }
    
            void client_GetDataCompleted(object sender, ServiceReference1.GetDataCompletedEventArgs e)   //处理返回值的函数
            {
                MessageBox.Show(e.Result);
                //throw new NotImplementedException();
            }
        }
    }
    View Code

    5、编译运行即出现本文开头提到的错误。

    6、解决方法

    在WCF服务目录下放两个文件clientaccesspolicy.xml、crossdomain.xml即可

    7、运行结果

    整个测试的项目(此项目是在vs2013下生成的)下载:链接:http://pan.baidu.com/s/1eQezJj0

  • 相关阅读:
    转:matplotlib画图,plt.xx和ax.xx之间有什么差异
    转:Python __call__()方法,可调用对象
    训练集,验证集,测试集,交叉验证
    Visio画图和导出图的时候,去除多余白色背景
    在线jupyter notebook
    dfs序
    codeforces 877b
    codeforce864d
    codeforce868c
    查看本地git查看git公钥,私钥的方式
  • 原文地址:https://www.cnblogs.com/lwngreat/p/4757154.html
Copyright © 2011-2022 走看看