我试图用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使用不同的路径语法.前者使用斜杠作为路径分隔符,后者使用点.任何人都可以解释为什么语法不一致,我在哪里可以找到扩展路径语法的文档?
在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, …
我正在使用以下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".
请建议解决方案.
我是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) 如何在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) 我正在构建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[]
我需要评估WCF数据服务与WCF RIA服务之间的SOA架构.以下是我的一些参数:
谁能帮我收集一些数据供我评估.此外,SOA实现是否还有其他好的选择.
我知道DevForce.
我有一系列客户,每个客户都有一系列订单.
以下查询返回客户及其订单并按预期工作:
~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)
哪个有效,但我真的很想一气呵成.
你能就我如何做到这一点提出建议吗?
我有一个数据服务启动并运行,但我收到此错误:
远程服务器返回错误:(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) 我正在使用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) odata ×5
wcf ×5
c# ×2
asp.net-4.0 ×1
astoria ×1
devforce ×1
linq ×1
linqpad ×1
rest ×1
soa ×1
vwdexpress ×1
wcf-client ×1
xrm ×1