I have a SOAP XML file name "LogEvents.xml" that I want to add/remove elements from it.
<?xml version="1.0" encoding="utf-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://www.w3.org/2001/12/soap-envelope" SOAP-ENV:encodingStyle="http://www.w3.org/2001/12/soap-encoding" >
<SOAP-ENV:Body xmlns:lle="http://www.examplee.org/logevents" >
<Event>
<eventid>ID-1</eventid>
<title>title1</title>
<description>desc1</description>
<location>
<lat>1.357207</lat>
<long>103.944880</long>
<address>address1</address>
</location>
<datetimestamp>datetime1</datetimestamp>
</Event>
<Event>
<eventid>ID-2</eventid>
<title>title2</title>
<description>desc2</description>
<location>
<lat>1.304121</lat>
<long>103.831950</long>
<address>addres2</address>
</location>
<datetimestamp>datetime2</datetimestamp>
</Event>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
Below shows the code that I have tried but failed using Visual Studio.
XDocument xDoc1 = XDocument.Load(#"C:\LogEvents.xml");
xDoc1.Element("SOAP-ENV").Add(new XElement("Event", new XElement("eventid", "strEventID"),
new XElement("title", "title2"),
new XElement("description", "desc3"),
new XElement("location", new XElement("lat", "lat3"),
new XElement("long", "long3"),
new XElement("address", "addresses3")),
new XElement("datetimestamp", "DateTime3")));
I have tried to remove the SOAP envelope in the XML file and replace it with "Events" and edit the C# code accordingly and it works as shown below.
<?xml version="1.0" encoding="utf-8"?>
<!--Changed to Events-->
<Events>
<Event>
<eventid>ID-1</eventid>
<title>title1</title>
<description>desc1</description>
<location>
<lat>1.357207</lat>
<long>103.944880</long>
<address>address1Edge</address>
</location>
<datetimestamp>datetime1</datetimestamp>
</Event>
<Event>
<eventid>ID-2</eventid>
<title>title2</title>
<description>desc2</description>
<location>
<lat>1.304121</lat>
<long>103.831950</long>
<address>addres2</address>
</location>
<datetimestamp>datetime2</datetimestamp>
<!--Changed to Events-->
</Event>
<Events>
XDocument xDoc1 = XDocument.Load(#"C:\LogEvents.xml");
// Changed SOAP-ENV to Events
xDoc1.Element("Events").Add(new XElement("Event", new XElement("eventid", "ID-3"),
new XElement("title", "title3"),
new XElement("description", "desc3"),
new XElement("location", new XElement("lat", "lat3"),
new XElement("long", "long3"),
new XElement("address", "addresses3")),
new XElement("datetimestamp", "DateTime3")));
Is there any method to ignore the SOAP envelope, or a way to work around it?
Use Root. You can always get the default namespace from the root when needed.
XDocument xDoc1 = XDocument.Load(FILENAME);
XElement soap = xDoc1.Root;
XNamespace ns = soap.GetDefaultNamespace();
soap.Add(new XElement("Event", new XElement("eventid", "strEventID"),
new XElement("title", "title2"),
new XElement("description", "desc3"),
new XElement("location", new XElement("lat", "lat3"),
new XElement("long", "long3"),
new XElement("address", "addresses3")),
new XElement("datetimestamp", "DateTime3")));
Related
var baseAddress = new Uri("http://www.easyredmine.com/");
using (var httpClient = new HttpClient { BaseAddress = baseAddress })
{
using (var response = await httpClient.GetAsync("issues/{id}.xml{?include}"))
{
string responseData = await response.Content.ReadAsStringAsync();
}
}
in this link you can found the API documentation of Redmine:
https://easyredmine.docs.apiary.io/
However, you can take all issue list with this url:
http://www.easyredmine.com/issues.xml
You have to create the model to map the result of the call and then with linq you can filter the list of objects obtained.
The model of reponse is this:
<issues total_count="1" offset="0" limit="25" type="array">
<issue>
<id>765</id>
<project id="71" name="Administration"/>
<tracker id="13" name="Other"/>
<status id="1" name="Planned"/>
<priority id="12" name="High"/>
<author id="5" name="Andrew Smith"/>
<assigned_to id="5" name="Andrew Smith"/>
<subject>issue subject</subject>
<description>
issue description
</description>
<start_date>2014-04-11</start_date>
<due_date>2014-04-11</due_date>
<done_ratio>0</done_ratio>
<estimated_hours>1.0</estimated_hours>
<easy_email_to>test#test.com</easy_email_to>
<easy_email_cc>test#test.com</easy_email_cc>
<created_on>2014-04-11T08:24:47Z</created_on>
<updated_on>2014-04-11T08:24:47Z</updated_on>
<closed_on/>
<sprint id="1" name="Sprint" due_date="2014-04-11"></sprint>
</issue>
</issues>
I think you’ll have to filter through the 'status' field
I am going to use sofort payment API in ASP.Net MVC, but I am having issue to add info in following XML format in C#.
<?xml version="1.0" encoding="UTF-8" ?>
<multipay>
<project_id>53245</project_id>
<interface_version>pn_test_1</interface_version>
<amount>2.20</amount>
<currency_code>EUR</currency_code>
<reasons>
<reason>Testueberweisung</reason>
<reason>-TRANSACTION-</reason>
</reasons>
<user_variables>
<user_variable>test</user_variable>
</user_variables>
<success_url>xyz</success_url>
<success_link_redirect>1</success_link_redirect>
<abort_url>xyz</abort_url>
<notification_urls>
<notification_url>xyz</notification_url>
<notification_url notify_on="received,loss">xyz</notification_url>
</notification_urls>
<su />
</multipay>
var xmlRequest = new XElement("multipay",
new XElement("project_id", "53245"),
new XElement("interface_version", "pn_test_1"),
new XElement("amount", "2.20"),
new XElement("currency_code", "EUR"),
new XElement("reasons", new XElement("reason", "Testueberweisung"), new XElement("reason", "-TRANSACTION-"))
);
string xmlreq = xmlRequest.ToString();
I have an XML file (it's a SOAP request to an SAP ME Service).
The file looks like this:
<?xml version="1.0" encoding="utf-8" ?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:me="http://sap.com/xi/ME">
<soapenv:Header />
<soapenv:Body>
<me:ShopOrderByBasicDataQuery_sync>
<me:ShopOrderByBasicDataQuery>
<me:ShopOrder>BOXBUILD_LASER_TEST</me:ShopOrder>
<me:SiteRef>
<me:Site>TEST1</me:Site>
</me:SiteRef>
</me:ShopOrderByBasicDataQuery>
</me:ShopOrderByBasicDataQuery_sync>
</soapenv:Body>
</soapenv:Envelope>
Using Paste Special I used Paste XML as Classes and got a number of classes.
I the created a new Envelope object
Envelope shoporder = new Envelope();
EnvelopeBody shoporderBody = new EnvelopeBody();
ShopOrderByBasicDataQuery_sync shoporderSync = new ShopOrderByBasicDataQuery_sync();
ShopOrderByBasicDataQuery_syncShopOrderByBasicDataQuery shoporderDataQuery = new ShopOrderByBasicDataQuery_syncShopOrderByBasicDataQuery();
shoporderSync.ShopOrderByBasicDataQuery = shoporderDataQuery;
shoporderDataQuery.ShopOrder = "BOXBUILD_LASER_TEST";
shoporderDataQuery.SiteRef = new ShopOrderByBasicDataQuery_syncShopOrderByBasicDataQuerySiteRef();
shoporderDataQuery.SiteRef.Site = "TEST1";
shoporderSync.ShopOrderByBasicDataQuery = shoporderDataQuery;
shoporderBody.ShopOrderByBasicDataQuery_sync = shoporderSync;
shoporder.Body = shoporderBody;
string tmp = (string)SoapHelper.SerializeToXmlString(shoporder);
The string tmp contains this (after a bit of formatting)
<?xml version="1.0" encoding="utf-16"?>
<Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://schemas.xmlsoap.org/soap/envelope/">
<Body>
<ShopOrderByBasicDataQuery_sync xmlns="http://sap.com/xi/ME">
<ShopOrderByBasicDataQuery>
<ShopOrder>BOXBUILD_LASER_TEST</ShopOrder>
<SiteRef>
<Site>TEST1</Site>
</SiteRef>
</ShopOrderByBasicDataQuery>
</ShopOrderByBasicDataQuery_sync>
</Body>
</Envelope>
Which is not a correct file! What have I done wrong?
I have source file like this:
<LicenseFile xmlns="">
<Object Id="Settings">
<ProductID xmlns="">P2</ProductID>
<FirstName xmlns="">John</FirstName>
<LastName xmlns="">Jackson</LastName>
</Object>
</LicenseFile>
I need to add sign and receive file like this:
<LicenseFile xmlns="">
<Signature xmlns="http://www.w3.org/2000/09/xmldsig#">
...
<Object Id="Settings">
<ProductID xmlns="">P2</ProductID>
<FirstName xmlns="">John</FirstName>
<LastName xmlns="">Jackson</LastName>
</Object>
</Signature>
</LicenseFile>
But I have the result file like this:
<LicenseFile xmlns="">
<Signature xmlns="http://www.w3.org/2000/09/xmldsig#">
...
</Signature>
<Object Id="Settings">
<ProductID xmlns="">P2</ProductID>
<FirstName xmlns="">John</FirstName>
<LastName xmlns="">Jackson</LastName>
</Object>
</LicenseFile>
I use that code:
XmlDocument doc = new XmlDocument();
doc.PreserveWhitespace = false;
doc.Load(new XmlTextReader(FileName));
SignedXml signedXml = new SignedXml(doc);
signedXml.SigningKey = Key;
Signature XMLSignature = signedXml.Signature;
Reference reference = new Reference("#Settings");
XmlDsigEnvelopedSignatureTransform env = new XmlDsigEnvelopedSignatureTransform();
reference.AddTransform(env);
XMLSignature.SignedInfo.AddReference(reference);
KeyInfo keyInfo = new KeyInfo();
keyInfo.AddClause(new RSAKeyValue((RSA)Key));
XMLSignature.KeyInfo = keyInfo;
// Compute the signature.
signedXml.ComputeSignature();
XmlElement xmlDigitalSignature = signedXml.GetXml();
// Append the element to the XML document.
doc.DocumentElement.AppendChild(doc.ImportNode(xmlDigitalSignature, true));
if (doc.FirstChild is XmlDeclaration)
{
doc.RemoveChild(doc.FirstChild);
}
// Save the signed XML document to a file specified
// using the passed string.
XmlTextWriter xmltw = new XmlTextWriter(SignedFileName, new UTF8Encoding(false));
doc.WriteTo(xmltw);
xmltw.Close();
What is incorrect?
Thnx.
The Object Node must be child of the Signature, and not in the same level.
I need to update MerchantOrderID in Amazon Marketplace via Amazon MWS API using C#.
So, first I created XML file like:
<?xml version="1.0"?>
<AmazonEnvelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="amzn-envelope.xsd">
<Header>
<DocumentVersion>1.01</DocumentVersion>
<MerchantIdentifier>M_STORE_3918753</MerchantIdentifier>
</Header>
<MessageType>OrderAcknowledgement</MessageType>
<Message>
<MessageID>1</MessageID>
<OrderAcknowledgement>
<AmazonOrderID>104-9209939-0469021</AmazonOrderID>
<MerchantOrderID>100828163</MerchantOrderID>
<StatusCode>Success</StatusCode>
<Item>
<AmazonOrderItemCode>11111111111111</AmazonOrderItemCode>
<MerchantOrderItemID>111111</MerchantOrderItemID>
<AmazonOrderItemCode>22222222222222</AmazonOrderItemCode>
<MerchantOrderItemID>222222222</MerchantOrderItemID>
</Item>
</OrderAcknowledgement>
</Message>
</AmazonEnvelope>
then I try to call Amazon MWS SubmitFeed:
SubmitFeedRequest request = new SubmitFeedRequest();
request.Merchant = merchantId;
request.MarketplaceIdList = new IdList();
request.MarketplaceIdList.Id = new List<string>(new string[] { marketplaceId });
request.FeedContent = File.Open(path, FileMode.Open, FileAccess.Read);
request.ContentMD5 = MarketplaceWebServiceClient.CalculateContentMD5(request.FeedContent);
request.FeedContent.Position = 0;
request.FeedType = "_POST_ORDER_ACKNOWLEDGEMENT_DATA_";
MarketplaceWebService.MarketplaceWebService serviceFeed = new MarketplaceWebServiceClient(
accessKeyId,
secretAccessKey,
applicationName,
applicationVersion,
configFeed);
SubmitFeedResponse response = serviceFeed.SubmitFeed(request);
it succesfully submits but when I open my order in Amazon (sellercentral.amazon.com) it says "none saved":
Your Merchant Order ID: # none saved
Who can help me, what is wrong or what should I do?
Thanks!
For those who want to update merchant order id in multiple orders at once, here is example (also works in amazon mws scratchpad):
<?xml version="1.0"?>
<AmazonEnvelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="amzn-envelope.xsd">
<Header>
<DocumentVersion>1.01</DocumentVersion>
<MerchantIdentifier>ALVH0CYWPBFNA</MerchantIdentifier>
</Header>
<MessageType>OrderAcknowledgement</MessageType>
<Message>
<MessageID>1</MessageID>
<OrderAcknowledgement>
<AmazonOrderID>000-0000000-0000000</AmazonOrderID>
<MerchantOrderID>YOUR_MERCHANT_ORDER_ID</MerchantOrderID>
<StatusCode>Success</StatusCode>
</OrderAcknowledgement>
</Message>
<Message>
<MessageID>2</MessageID>
<OrderAcknowledgement>
<AmazonOrderID>000-0000000-0000000</AmazonOrderID>
<MerchantOrderID>YOUR_MERCHANT_ORDER_ID</MerchantOrderID>
<StatusCode>Success</StatusCode>
</OrderAcknowledgement>
</Message>
</AmazonEnvelope>
It's actually right code. Somehow amazon doesn't mark some special orders or marks them later.