首页 \ 问答 \ 带有WCF服务的Silverlight MEF(Silverlight MEF with WCF service)

带有WCF服务的Silverlight MEF(Silverlight MEF with WCF service)

我有一个带有许多用户控件的仪表板项目。 本周我创建了一个不仅仅是用户控件的应用程序,并将其集成到我的仪表板应用程序中似乎很痛苦。 所以我搜索了解决方案,发现了MEF和PRISM。 MEF似乎比PRISM容易一些,我开始用教程做一个Hello World MEF应用程序。 它进展顺利,我成功注入了Hello World xap。

之后我尝试注入我的实际应用程序并遇到一些问题。 我想指出我解决的问题,因为我可能以错误的方式解决它们,或者它们可能是我当前问题的原因。

注意:我的应用程序使用支持Silverlight的WCF Web服务来检索数据。

第一个问题

在xap包中找不到ServiceReferences.ClientConfig。 我将此文件添加为我的MEF项目客户端的链接。 问题解决了。

第二个问题

我在客户端使用一个Settings.xml,它包含端点,如:

<?xml version="1.0" encoding="utf-8" ?>
 <Services>
  <Service Name="MyService">
    <HostPath Name="/ClientBin/MyComponent.xap">
      <Endpoint Url="/MyService.svc"></Endpoint>
    </HostPath>
    <HostPath Name="MyComponent.Web/ClientBin/MyComponent.xap">
      <Endpoint Url="MyComponent.Web/MyService.svc"></Endpoint>
    </HostPath>
  </Service>
</Services>

并阅读此内容以获得具有我的2个功能的WCF Web服务客户端:

public MyServiceClient GetMyServiceClient()
    {
        if (serviceClient == null)
        {
            serviceClient = new MyServiceClient();
            Uri uriEndpointAddress = serviceClient.Endpoint.Address.Uri;
            UriBuilder ub = new UriBuilder(uriEndpointAddress)
            {
                Host = Application.Current.Host.Source.Host,
                Path =
                    GetURLForService("MyService",
                                     Application.Current.Host.Source.AbsolutePath)
            };
            serviceClient.Endpoint.Address = new System.ServiceModel.EndpointAddress(ub.Uri);
        }
        return serviceClient;
    }

private string GetURLForService(string ServiceName, string HostURL)
    {
        string retval = "";
        XDocument doc = XDocument.Load("Settings.xml");
        if (doc.Root != null)
        {
            XElement elmService = doc.Root.Elements("Service").FirstOrDefault(c =>
            {
                XAttribute xAttribute = c.Attribute("Name");
                return xAttribute != null && xAttribute.Value.ToLower() == ServiceName.ToLower();
            });
            if (elmService != null)
            {
                XElement elmHostPath = elmService.Elements("HostPath").FirstOrDefault(c =>
                {
                    XAttribute xAttribute = c.Attribute("Name");
                    return xAttribute != null && xAttribute.Value.ToLower() == HostURL.ToLower();
                });
                if (elmHostPath != null)
                {
                    retval = elmHostPath.Element("Endpoint").Attribute("Url").Value;
                }
            }
        }

        return retval;
    }

我已经将我的Settings.xml文件添加为链接,问题也解决了。

主要问题

解决了这两个问题后,我遇到了主要问题。 远程服务器返回错误:NotFound。

我甚至在我的Settings.xml中尝试过这个:

<HostPath Name="/MEFHubApp/ClientBin/MyComponent.xap">
  <Endpoint Url="/MyComponent.Web/MyService.svc"></Endpoint>
</HostPath>

无论我尝试什么,我的MEF应用都无法找到/使​​用我的网络服务。

谢谢


I have a dashboard project with many user controls. This week I've created an application which is more than just a user control and integrating it into my dashboard application seemed like a pain. So I searched for solutions and found MEF and PRISM. MEF seemed a bit easier than PRISM and I started to do a Hello World MEF app with this tutorial. It went well and I injected a Hello World xap successfully.

After that I tried to inject my real application and encountered some problems. I want to point out problems that I solved because I might solved them in a wrong way or they may be the reason of my current problem.

Note: My application uses a Silverlight enabled WCF Web Service to retrieve data.

First Problem

ServiceReferences.ClientConfig was not found in xap package. I added this file as link to my MEF project client side. Problem solved.

Second Problem

I am using a Settings.xml on my client side which holds the endpoints like:

<?xml version="1.0" encoding="utf-8" ?>
 <Services>
  <Service Name="MyService">
    <HostPath Name="/ClientBin/MyComponent.xap">
      <Endpoint Url="/MyService.svc"></Endpoint>
    </HostPath>
    <HostPath Name="MyComponent.Web/ClientBin/MyComponent.xap">
      <Endpoint Url="MyComponent.Web/MyService.svc"></Endpoint>
    </HostPath>
  </Service>
</Services>

and read this to get WCF Web Service service client with my 2 functions which are:

public MyServiceClient GetMyServiceClient()
    {
        if (serviceClient == null)
        {
            serviceClient = new MyServiceClient();
            Uri uriEndpointAddress = serviceClient.Endpoint.Address.Uri;
            UriBuilder ub = new UriBuilder(uriEndpointAddress)
            {
                Host = Application.Current.Host.Source.Host,
                Path =
                    GetURLForService("MyService",
                                     Application.Current.Host.Source.AbsolutePath)
            };
            serviceClient.Endpoint.Address = new System.ServiceModel.EndpointAddress(ub.Uri);
        }
        return serviceClient;
    }

private string GetURLForService(string ServiceName, string HostURL)
    {
        string retval = "";
        XDocument doc = XDocument.Load("Settings.xml");
        if (doc.Root != null)
        {
            XElement elmService = doc.Root.Elements("Service").FirstOrDefault(c =>
            {
                XAttribute xAttribute = c.Attribute("Name");
                return xAttribute != null && xAttribute.Value.ToLower() == ServiceName.ToLower();
            });
            if (elmService != null)
            {
                XElement elmHostPath = elmService.Elements("HostPath").FirstOrDefault(c =>
                {
                    XAttribute xAttribute = c.Attribute("Name");
                    return xAttribute != null && xAttribute.Value.ToLower() == HostURL.ToLower();
                });
                if (elmHostPath != null)
                {
                    retval = elmHostPath.Element("Endpoint").Attribute("Url").Value;
                }
            }
        }

        return retval;
    }

I've added my Settings.xml file as link also and problem solved.

Main Problem

After solving these two problems, I've encountered main problem. The remote server returned an error: NotFound.

I even tried this in my Settings.xml:

<HostPath Name="/MEFHubApp/ClientBin/MyComponent.xap">
  <Endpoint Url="/MyComponent.Web/MyService.svc"></Endpoint>
</HostPath>

My MEF app can't find/use my web service no matter what I try.

Thanks


原文:https://stackoverflow.com/questions/16455913
更新时间:2022-05-06 12:05

最满意答案

您可以在C ++中预先声明(转发声明)类类型。

struct Products;

但是,以这种方式声明的类类型是不完整的 。 不完整类型只能以非常有限的方式使用。 您将能够声明指向此类型的指针或引用,您将能够在非定义函数声明等中提及它,但您将无法定义此类不完整类型的对象或访问其成员。

如果要定义类Products对象或访问类Products成员,除了在使用之前完全定义类之外别无选择。

在您的情况下,您将在main中定义Products类型的对象,并在那里访问类Products成员。 这意味着您必须在main之前完全定义Products


You can pre-declare (forward-declare) a class type in C++.

struct Products;

However, a class type declared in this way is incomplete. Incomplete types can only be used in a number of very limited ways. You will be able to declare pointers or references to such type, you will be able to mention it in non-defining function declarations etc., but you will not be able to define objects of such incomplete type or access their members.

If you want to define objects of class Products or access members of class Products, you have no other choice but to fully define the class before such use.

In your case you are defining an object of type Products in main as well as accessing members of class Products there. This means that you have to completely define Products before main.

相关问答

更多
  • 从您的ah头文件中,只需删除#include "bh" 。 前向声明struct B; 是你所需要的全部。 该更改将修复循环包含依赖项,并将使使用这些标头的任何代码更加清晰。 然后,只要您想要使用B结构,只需包含bh ,并在有或没有struct关键字的情况下使用它。 一些代码来说明: ah头文件: /* a.h */ struct B; typedef struct A { void (*func)(struct B* b); } A; bh头文件: /* b.h */ #include "a. ...
  • f.x = 54; f.array[3]=9; 应该在里面一些功能。 除初始化外,您不能在全局范围内编写函数外的程序流。 要全局初始化,请使用 struct Foo f = {54, {0, 0, 0, 9}}; 现场代码 在C99中,您也可以写作 struct Foo f = {.x=54, .array[3] = 9 }; 现场代码 您提到的示例链接说: struct Foo f; //自动分配,所有字段都放在堆栈上 fx = 54; f.array[3]=9; 使用文字堆栈表明它开始在如下的本地 ...
  • 喜欢这个 var Symbols = [String:SData]() 测试数据 var symbols = [String:SData]() let test = SData(OldValue: 2.2, Values: [1.1], Times: [UInt32(22)]) symbols["Thing"] = test // use lower case for variable names as well Like this var Symbols = [String:SData]() Te ...
  • 您可以在C ++中预先声明(转发声明)类类型。 struct Products; 但是,以这种方式声明的类类型是不完整的 。 不完整类型只能以非常有限的方式使用。 您将能够声明指向此类型的指针或引用,您将能够在非定义函数声明等中提及它,但您将无法定义此类不完整类型的对象或访问其成员。 如果要定义类Products对象或访问类Products成员,除了在使用之前完全定义类之外别无选择。 在您的情况下,您将在main中定义Products类型的对象,并在那里访问类Products成员。 这意味着您必须在mai ...
  • 您的代码正在调用未定义的行为,因为诸如vector标准容器不能包含不完整的类型,而tnode在结构定义中是不完整的类型。 根据C ++ 11标准,17.6.4.8p2: 在以下情况下,效果未定义:[...]如果在实例化模板组件时将不完整类型(3.9)用作模板参数,除非特别允许该组件。 Boost.Container库提供了可以包含不完整类型的替代容器(包括vector )。 递归数据类型(例如您想要的类型)将作为此用例给出。 以下内容适用于Boost.Container: #include
  • extern "C" { typedef struct _CONTEXT CONTEXT, *PCONTEXT; } 您需要声明_CONTEXT是一个struct 。 并将其声明为extern "C"以匹配windows.h的外部链接(这是一个C头)。 但是,您不需要为typedef提供定义,但是如果这样做,所有定义必须匹配(“ 一个定义规则” )。 编辑:我也忘记了外部的“C”。 extern "C" { typedef struct _CONTEXT CONTEXT, *PCONTEXT; } Yo ...
  • 正如我在评论中所说,您可以在结构和int之间使用隐式转换: internal struct MyInt { private int p; public int BoundedInt { // As CodesInChaos points out, the setter is not required here. // You could even make the whole property private and jsut use ...
  • 正如@zerkms所说,你做不到。 最好的想法是在MyObject创建自己的相同类型的字段。 您还可以在MyObject嵌入s3.GetObjectOutput 。 type MyObject struct { *s3.GetObjectOutput ... } 鉴于myobj是MyObject一个实例,请使用myobj.Metadata 。 @William Poussier In that way I have to use a global variable just for use ...
  • 我会给你两个解决方案。 根据情况,第一个可能不完全是你想要的。 如果你愿意,我可以详细说明这两种方法。 便宜的方法:使用填充阵列 如果您有一个大型结构并且只有少数成员的目的或大小已知,那么通过创建临时虚拟数组来填充结构的间隙通常很有用。 这使得结构定义在IDA中更具可读性和可维护性,并且它还允许您将结构整形为特定大小,而无需定义比您需要的更多成员。 假设您有一个已知大小为0x400字节的结构,并且您知道偏移量+ 0x0和+ 0x384处的成员的定义。 我们还要说你知道+ 0x4和+ 0x6有单词,但你不知道 ...

相关文章

更多

最新问答

更多
  • 您如何使用git diff文件,并将其应用于同一存储库的副本的本地分支?(How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?)
  • 将长浮点值剪切为2个小数点并复制到字符数组(Cut Long Float Value to 2 decimal points and copy to Character Array)
  • OctoberCMS侧边栏不呈现(OctoberCMS Sidebar not rendering)
  • 页面加载后对象是否有资格进行垃圾回收?(Are objects eligible for garbage collection after the page loads?)
  • codeigniter中的语言不能按预期工作(language in codeigniter doesn' t work as expected)
  • 在计算机拍照在哪里进入
  • 使用cin.get()从c ++中的输入流中丢弃不需要的字符(Using cin.get() to discard unwanted characters from the input stream in c++)
  • No for循环将在for循环中运行。(No for loop will run inside for loop. Testing for primes)
  • 单页应用程序:页面重新加载(Single Page Application: page reload)
  • 在循环中选择具有相似模式的列名称(Selecting Column Name With Similar Pattern in a Loop)
  • System.StackOverflow错误(System.StackOverflow error)
  • KnockoutJS未在嵌套模板上应用beforeRemove和afterAdd(KnockoutJS not applying beforeRemove and afterAdd on nested templates)
  • 散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)
  • android - 如何避免使用Samsung RFS文件系统延迟/冻结?(android - how to avoid lag/freezes with Samsung RFS filesystem?)
  • TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)
  • 企业安全培训的各项内容
  • 错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)
  • C#类名中允许哪些字符?(What characters are allowed in C# class name?)
  • NumPy:将int64值存储在np.array中并使用dtype float64并将其转换回整数是否安全?(NumPy: Is it safe to store an int64 value in an np.array with dtype float64 and later convert it back to integer?)
  • 注销后如何隐藏导航portlet?(How to hide navigation portlet after logout?)
  • 将多个行和可变行移动到列(moving multiple and variable rows to columns)
  • 提交表单时忽略基础href,而不使用Javascript(ignore base href when submitting form, without using Javascript)
  • 对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)
  • Angular $资源不会改变方法(Angular $resource doesn't change method)
  • 在Angular 5中不是一个函数(is not a function in Angular 5)
  • 如何配置Composite C1以将.m和桌面作为同一站点提供服务(How to configure Composite C1 to serve .m and desktop as the same site)
  • 不适用:悬停在悬停时:在元素之前[复制](Don't apply :hover when hovering on :before element [duplicate])
  • 常见的python rpc和cli接口(Common python rpc and cli interface)
  • Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)
  • 产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)