标签: wcf-data-services

如何加载与WCF数据服务的二度实体关系?

我试图用DataServiceQuery查询数据库中的单个实体.我试图加载的实体与我想要加载的其他实体的图形有关系.MSDN在这里这里描述我可以使用DataServiceQuery <TElement> .Expand或DataServiceContext.LoadProperty加载我的引用实体.

这适用于我的实体的一级关系,但我在加载关系关系时遇到问题.

显然我可以为所有二度关系调用LoadProperty并循环遍历所有二度集合,但我希望我可以在一个查询中急切加载整个关系图.那可能吗?

编辑

实际上加载二度关系并不是那么明显.以下代码失败(为清晰起见,域模型已更改):

            var context = DataServiceReference.DataServiceContextFactory.Create();
            var customer = (from c in context.Customers.Expand("Orders")
                                where c.CustomerId.Equals(customerId)
                                 select c).First();
            foreach (var order in customer.Orders)
            {
                context.LoadProperty(order, "Products");
Run Code Online (Sandbox Code Playgroud)

上面的最后一行抛出InvalidOperationException:"上下文当前没有跟踪实体." 我使用自我跟踪实体.这个错误可能与STE有关吗?

我如何以任何方式加载二级关系?

解决方案编辑

事实证明,与ObjectQuery <T> .Include相比,DataServiceQuery <TElement> .Expand使用不同的路径语法.前者使用斜杠作为路径分隔符,后者使用点.任何人都可以解释为什么语法不一致,我在哪里可以找到扩展路径语法的文档?

wcf-data-services

3
推荐指数
1
解决办法
3278
查看次数

如何使用OData在单个POST请求中正确创建和链接一对一关系

在OData:Operations文档的第2.4节第4段中,它在使用POST创建实体时读取,也可以在同一请求中创建链接.但是,我在努力完成这项工作时遇到了麻烦.关于创建时的多对多链接也有类似的问题,如果没有批量请求,看起来不可能出现特定情况.下面是我尝试使用此示例OData读写服务创建的场景.

创建一个名为"Test Product"的新产品,并使用JSON在单个POST中将其链接到Category(0).

我试过了...

POST /OData/OData.svc/Products HTTP/1.1
Accept: application/json
Content-Type: application/json

{ "ID": 99, "Name": "Test Product", "Description": "Simple Test", "ReleaseDate": "\/Date(1210204800000)\/", "DiscontinuedDate": null, "Rating": 3, "Price": "99.99", "Category":"http://services.odata.org/OData/OData.svc/Categories(0)" }

POST /OData/OData.svc/Products HTTP/1.1
Accept: application/json
Content-Type: application/json

{ "ID": 99, "Name": "Test Product", "Description": "Simple Test", "ReleaseDate": "\/Date(1210204800000)\/", "DiscontinuedDate": null, "Rating": 3, "Price": "99.99", "Category": {"uri": "http://services.odata.org/OData/OData.svc/Categories(0)"} }

POST /OData/OData.svc/Products HTTP/1.1
Accept: application/json
Content-Type: application/json

{ "ID": 99, "Name": "Test Product", "Description": "Simple Test", "ReleaseDate": "\/Date(1210204800000)\/", "DiscontinuedDate": null, …

entity-framework wcf-data-services odata

3
推荐指数
1
解决办法
2045
查看次数

Linq查询错误

我正在使用以下Linq查询:

from p in People
 where p.Name == "George Lucas"
select p.TitlesActedIn
Run Code Online (Sandbox Code Playgroud)

其中TitlesActedIn是一个列表.人和TitlesActedIn是关联的

但我收到错误:

InvalidCastException:无法将类型为"System.Linq.Expressions.PropertyExpression"的对象强制转换为"System.Data.Services.Client.ResourceExpression".

请建议解决方案.

linq linqpad wcf-data-services

3
推荐指数
1
解决办法
2848
查看次数

OData/WCF数据服务不使用复杂类型

我是OData和WCF数据服务的新手,所以这可能是一个简单的问题.我正在使用VS Web Developer Express 2010,我在控制台应用程序中托管了一个非常简单的WCF数据服务.它从一个存储库(位于一个单独的dll项目中)返回一个简单的"Study"类的IQuerable集合,后者又从另一个dll中的db项目中检索"Study"类(因此解决方案中有3个项目).

我在db项目中也有一个"实验"课程,研究中可以有多个实验.当我从研究中排除实验课时,一切正常,我得到了数据.当我将一个List集合添加到Study类时发生问题,然后当我尝试运行该服务时出现运行时错误.在Firebug中,错误是"500内部服务器错误",浏览器中的消息是"请求错误".服务器遇到处理请求的错误.有关详细信息,请参阅服务器日志.

我有IIS 7,我也刚刚安装了IIS 7.5,但它对我来说是全新的,所以我无法弄清楚托管服务的位置或查看服务器/网络日志的位置.在'C:\ inetpub\logs\LogFiles\W3SVC1'中只能看到IIS 7日志.当我运行应用程序时,VS Web服务器(Cassini)无法启动,因此这表明它是在IIS 7.5(?)中托管的.

那么
- 我如何返回子类/复杂对象?
- 我如何知道托管服务的位置以及在哪里可以找到服务器日志?

这是主机应用程序:

using MyStudyRepository;
using MyStudyDB;

namespace MyStudyService
{
    public class Program
    {
        public static void Main(string[] args)
        {
            string serviceAddress = "http://localhost:998";
            Uri[] uriArray = { new Uri(serviceAddress) };
            Type serviceType = typeof(StudyDataService);

            using (var host = new DataServiceHost(serviceType,uriArray))
            {
                host.Open();
                Console.WriteLine("Press any key to stop service");
                Console.ReadKey();
            }
        }
    }

    public class StudyDataService : DataService<StudyRepository>
    {
        public static void InitializeService(IDataServiceConfiguration config) …
Run Code Online (Sandbox Code Playgroud)

wcf vwdexpress wcf-data-services odata

3
推荐指数
1
解决办法
5922
查看次数

如何以编程方式配置WCF数据服务?

如何在C#中流畅地配置以下WCF数据服务?

<configuration>

  ...

  <system.serviceModel>
    <services>
      <service name="Foo.WebServices.FooService">
        <endpoint address="http://localhost:8081/PhoenixData" 
                  binding="webHttpBinding" 
                  bindingConfiguration=""
                  contract="System.Data.Services.IRequestHandler" />
      </service>
    </services>

    <behaviors>
      <serviceBehaviors>
        <behavior name="">
          <serviceMetadata httpGetEnabled="true" />
          <serviceDebug includeExceptionDetailInFaults="true" />
        </behavior>
      </serviceBehaviors>
    </behaviors>

  </system.serviceModel>  
</configuration>
Run Code Online (Sandbox Code Playgroud)

astoria wcf-data-services

3
推荐指数
1
解决办法
1325
查看次数

如何将对象列表发送到WCF服务?

我正在构建WCF服务,我想接受List作为我的方法之一的参数.

这是我的代码:

[ServiceContract]
public interface IProductService
{
    [OperationContract]
    int InsertProducts(List<Product> products);
}

[DataContract]
[KnownType(typeof(List<Product>))]
public class Product
{
    [DataMember]
    public int ProductId{ get; set; }

    [DataMember]
    public string ProductName{ get; set; }

    [DataMember]
    public List<Product> Products { get; set; }
}
Run Code Online (Sandbox Code Playgroud)

当我运行服务时,它给了我一个错误.

WCF不支持此操作,因为它使用 NameSpace.Product[]

c# wcf wcf-client asp.net-4.0 wcf-data-services

3
推荐指数
1
解决办法
1万
查看次数

WCF数据服务与WCF RIA服务

我需要评估WCF数据服务WCF RIA服务之间的SOA架构.以下是我的一些参数:

  1. 多客户端(HTML5/iOS/Android/Windows 8 Metro/Windows Phone 7)
  2. 断开连接和离线操作
  3. 验证引擎
  4. 性能
  5. 网络数据压缩
  6. 支持云环境

谁能帮我收集一些数据供我评估.此外,SOA实现是否还有其他好的选择.

我知道DevForce.

wcf soa wcf-data-services wcf-ria-services devforce

3
推荐指数
1
解决办法
2525
查看次数

oData WCF数据服务过滤子集合

我有一系列客户,每个客户都有一系列订单.

以下查询返回客户及其订单并按预期工作:

~Customers?$expand=Orders
Run Code Online (Sandbox Code Playgroud)

现在我想要获得现有客户,但是按Order.Amount> 100过滤他们的订单(我很高兴没有此类订单留在列表中的客户),

当我尝试以下内容时:

~Customers?$expand=Orders&$filter=Orders/Amount gt 100
Run Code Online (Sandbox Code Playgroud)

我收到以下错误:

The 'Amount' is not allowed at position ***. Member access or specifying a type identifier on a resource set reference is not allowed.
Run Code Online (Sandbox Code Playgroud)

我可以遍历客户并致电

~Customers('Blah')/Orders?$filter=Amount gt 100 
Run Code Online (Sandbox Code Playgroud)

哪个有效,但我真的很想一气呵成.

你能就我如何做到这一点提出建议吗?

rest wcf wcf-data-services odata

3
推荐指数
1
解决办法
5107
查看次数

如何使用EF 6为WCF数据服务(odata)设置配置文件

我有一个数据服务启动并运行,但我收到此错误:

远程服务器返回错误:(413)请求实体太大.

我已经尝试过许多方法来解决这个问题而没有运气.我已将网站上的uploadReadAheadSize和IIS中的数据服务设置为最大设置.我还为配置文件尝试了许多不同的设置.

这是客户端的当前app.config:

  <system.serviceModel>
<bindings>
  <basicHttpBinding>
    <binding name="BasicHttpBinding_ILogging" />
    <binding name="WCFHttpBinding"
             maxReceivedMessageSize="2147483647"
             maxBufferSize="2147483647"
             maxBufferPoolSize="2147483647">
      <readerQuotas maxArrayLength="2147483647"
                    maxDepth="2147483647"
                    maxBytesPerRead="2147483647"
                    maxNameTableCharCount="2147483647"
                    maxStringContentLength="2147483647"/>
    </binding>
  </basicHttpBinding>
  <webHttpBinding>
    <binding name="WCFWebBinding" maxBufferPoolSize="2147483647" maxBufferSize="2147483647" maxReceivedMessageSize="2147483647">
      <readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647"/>
    </binding>
  </webHttpBinding>
</bindings>
<client>
  <endpoint address="http://localhost/PSIDataService/PSIWcfDataService.svc"
            binding="webHttpBinding" bindingConfiguration="WCFWebBinding"
            name="WCFWebBinding" contract="*"/>
</client>
Run Code Online (Sandbox Code Playgroud)

我尝试了两种绑定,WCFWebBinding和WCFHttpBinding.

这是web服务web.config.

  <system.serviceModel>
<behaviors>
  <serviceBehaviors>
    <behavior name="">
      <serviceMetadata httpGetEnabled="true" httpsGetEnabled="true" />
      <serviceDebug includeExceptionDetailInFaults="true" />
    </behavior>
  </serviceBehaviors>
</behaviors>
<bindings>
  <basicHttpBinding>
    <binding name="WCFHttpBinding" maxBufferPoolSize="2147483647" maxBufferSize="2147483647" maxReceivedMessageSize="2147483647" messageEncoding="Text">
      <readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />
    </binding>
  </basicHttpBinding> …
Run Code Online (Sandbox Code Playgroud)

wcf wcf-data-services odata

3
推荐指数
1
解决办法
2229
查看次数

字段'Target'缺少必需成员'LogicalName'

我正在使用Microsoft XRM SDK以编程方式添加实体.但是,每次运行.Create()命令时都会出现以下错误:

Required member 'LogicalName' missing for field 'Target'
Run Code Online (Sandbox Code Playgroud)

第一次在我们公司使用这项服务和类似的资源是稀缺的,所以不确定这个错误意味着什么或如何调查/解决它.

下面是我为处理XRM通信而创建的类.我实例化construtor中的每个连接属性.然后,在这种情况下,打电话CreateAgency(AgentTransmission agt).CreateAgency().Create(account)方法调用的方法中抛出异常.

class DynamicsCommunication
{
    private Uri OrganizationUri = new Uri("http://devhildy03/xRMDRMu01/XRMServices/2011/Organization.svc");
    private ClientCredentials credentials;
    private OrganizationServiceProxy servicePoxy;
    private Guid accountId;
    private Entity account;

    public DynamicsCommunication()
    {
        credentials = new ClientCredentials();
        credentials.Windows.ClientCredential = CredentialCache.DefaultNetworkCredentials;
        servicePoxy = new OrganizationServiceProxy(OrganizationUri, null, credentials, null);
        accountId = Guid.Empty;
    }

    public string UpdateDynamics(AgentTransmission agt)
    {
        switch (DeterminAction(agt))
        {
            case DynamicsAction.Create:
                return CreateAgency(agt);
            case DynamicsAction.Update:
                return …
Run Code Online (Sandbox Code Playgroud)

c# xrm wcf-data-services odata

3
推荐指数
1
解决办法
3179
查看次数