甚至不确定我是否在问正确的问题,但它就在这里。基本上是因为 WCF DS 客户端缺乏对“OData 深度插入”的支持,我不得不手动建立一个 Atom 请求。我的请求几乎完成了,唯一缺少的(它导致对服务器的请求出现问题)是将命名空间前缀添加到 XML 请求中的“条目”节点。
我正在使用 SyndicationItem 来构建请求。我需要在“入口”节点前加上“atom:”,以便服务器接受请求......
任何帮助深表感谢。这是现在正在生成的请求:
<?xml version="1.0" encoding="utf-8"?>
<entry xmlns:atom="http://www.w3.org/2005/Atom" xmlns:d="http://schemas.microsoft.com/ado/2007/08/dataservices" xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata" xmlns="http://www.w3.org/2005/Atom">
<atom:id>uuid:8ed93950-9c16-4923-b6cc-ca5c7d020709;id=1</atom:id>
<atom:title type="text"></atom:title>
<atom:updated>2011-11-03T23:02:40Z</atom:updated>
<atom:link rel="http://schemas.microsoft.com/ado/2007/08/dataservices/related/SalesOrderItems" type="application/atom+xml;type=feed" title="SALES_ORDER.SalesOrderHeader_SalesOrderItemsx" href="SalesOrderHeaders()/SalesOrderItems">
<m:inline>
<atom:feed>
<atom:entry>
<atom:content>
<m:properties>
<d:Item>10</d:Item>
<d:Material>70000559</d:Material>
<d:Plant>570B</d:Plant>
<d:Quantity>10</d:Quantity>
</m:properties>
</atom:content>
</atom:entry>
<atom:entry>
<atom:content>
<m:properties>
<d:Item>20</d:Item>
<d:Material>70000559</d:Material>
<d:Plant>570B</d:Plant>
<d:Quantity>10</d:Quantity>
</m:properties>
</atom:content>
</atom:entry>
</atom:feed>
</m:inline>
</atom:link>
<atom:content type="text/xml">
<m:properties>
<d:DocumentType>ZCSH</d:DocumentType>
<d:CustomerId>0001008657</d:CustomerId>
<d:SalesOrg>1100</d:SalesOrg>
<d:DistChannel>10</d:DistChannel>
<d:Division>40</d:Division>
</m:properties>
</atom:content>
</entry>
这是我现在用来生成请求的代码。这只是一个概念证明,所以请忽略废话。:)
XNamespace nsAtom = "http://www.w3.org/2005/Atom";
XNamespace nsD = "http://schemas.microsoft.com/ado/2007/08/dataservices";
XNamespace nsM = "http://schemas.microsoft.com/ado/2007/08/dataservices/metadata";
SyndicationItem soHeader = new SyndicationItem();
soHeader.AttributeExtensions.Add(new XmlQualifiedName("atom", XNamespace.Xmlns.ToString()), nsAtom.NamespaceName);
soHeader.AttributeExtensions.Add(new XmlQualifiedName("d", XNamespace.Xmlns.ToString()), nsD.NamespaceName);
soHeader.AttributeExtensions.Add(new XmlQualifiedName("m", XNamespace.Xmlns.ToString()), nsM.NamespaceName);
soHeader.Content = SyndicationContent.CreateXmlContent(
new XElement(nsM + "properties",
new XElement(nsD + "DocumentType", "ZCSH"),
new XElement(nsD + "CustomerId", "0001008657"),
new XElement(nsD + "SalesOrg", "1100"),
new XElement(nsD + "DistChannel", "10"),
new XElement(nsD + "Division", "40")
)
);
SyndicationLink link = SyndicationLink.CreateAlternateLink(new Uri("SalesOrderHeaders()/SalesOrderItems", UriKind.Relative), "application/atom+xml;type=feed");
link.Title = "SALES_ORDER.SalesOrderHeader_SalesOrderItems";
link.RelationshipType = "http://schemas.microsoft.com/ado/2007/08/dataservices/related/SalesOrderItems";
soHeader.Links.Add(link);
XElement items = new XElement(nsM + "inline",
new XElement(nsAtom + "feed")
);
for (int i = 0; i < 2; i++)
{
items.Element(nsAtom + "feed").Add(new XElement(nsAtom + "entry",
new XElement(nsAtom + "content",
new XElement(nsM + "properties",
new XElement(nsD + "Item", ((i+1)*10).ToString()),
new XElement(nsD + "Material", "70000559"),
new XElement(nsD + "Plant", "570B"),
new XElement(nsD + "Quantity", (Decimal)10.0)
)
)
)
);
}
link.ElementExtensions.Add(items);
XmlWriter xml = XmlWriter.Create("C:\\test.xml");
soHeader.SaveAsAtom10(xml);
xml.Close();