目前我有這樣的代碼來構建一個SOAP信封:構建SOAP信封,而不是字符串的XDocument
"<?xml version=\"1.0\" encoding=\"utf-8\"?>" +
"<soap:Envelope " +
"xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" " +
"xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" " +
"xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\">" +
"<soap:Body> " +
"<ABRSearchByABN xmlns=\"http://abr.business.gov.au/ABRXMLSearch/\"> " +
"<searchString>" + searchValue + "</searchString>" +
"<includeHistoricalDetails>" + history + "</includeHistoricalDetails>" +
"<authenticationGuid>" + guid + "</authenticationGuid>" +
"</ABRSearchByABN>" +
"</soap:Body>" +
"</soap:Envelope>";
我想,而不是創建一個XML文檔,但我不知道如何與去命名空間。
是obiously不起作用代碼:
XNamespace soap = "http://schemas.xmlsoap.org/soap/envelope/";
XNamespace xmlns = "http://abr.business.gov.au/ABRXMLSearch/";
XNamespace xsi = "http://www.w3.org/2001/XMLSchema-instance";
XNamespace xsd = "http://www.w3.org/2001/XMLSchema";
XDocument xd = new XDocument(
new XDeclaration("1.0","utf-8",""),
new XElement("soap:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\"",
new XElement("soap:Body",
new XElement("ABRSearchByABN xmlns=\"http://abr.business.gov.au/ABRXMLSearch/\"",
new XElement("searchString", searchValue),
new XElement("includeHistoricalDetails", history),
new XElement("authenticationGuid", guid)))));
我怎樣才能完成這個?
在此先感謝。
例如,使用'new XElement(soap +「Body」)' – 2011-05-24 14:50:37
此外,爲什麼您要手動執行此操作而不是使用「添加服務引用」? – 2011-05-24 14:50:55