Now, I use CRM 2016 and VS 2013.
I want migrate older CRM Services (CRM 4 - CRM 2011) that uses CrmService (WebReference http://server:5555/MSCrmServices/2007/CrmServiceWsdl.aspx)
public partial class CrmService : System.Web.Services.Protocols.SoapHttpClientProtocol {
[System.Web.Services.Protocols.SoapHeaderAttribute("CorrelationTokenValue")]
[System.Web.Services.Protocols.SoapHeaderAttribute("CrmAuthenticationTokenValue")]
[System.Web.Services.Protocols.SoapHeaderAttribute("CallerOriginTokenValue")]
[System.Web.Services.Protocols.SoapDocumentMethodAttribute("http://schemas.microsoft.com/crm/2007/WebServices/Fetch", RequestNamespace="http://schemas.microsoft.com/crm/2007/WebServices", ResponseNamespace="http://schemas.microsoft.com/crm/2007/WebServices", Use=System.Web.Services.Description.SoapBindingUse.Literal, ParameterStyle=System.Web.Services.Protocols.SoapParameterStyle.Wrapped)]
public string Fetch(string fetchXml) {
object[] results = this.Invoke("Fetch", new object[] {
fetchXml});
return ((string)(results[0]));
}
Legacy code:
string result = aCrm.Fetch(fetchQuery);
if (result.ToString() == "<resultset morerecords=\"0\" />")
{
return "<codigoerror>01</codigoerror><descripcion>Mediador sin campañas</descripcion>";
}
else
{
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.LoadXml(result);
XmlNodeList xmlNodes = xmlDoc.GetElementsByTagName("result");
for (int i = 0; i < xmlNodes.Count; i++)
{
string fetchquery2 = string.Empty;
fetchquery2 = ConsultasFetch.MostrarInfoCampaña();
fetchquery2 = fetchquery2.Replace("MiVariable1", MediadorCodeCPC);
fetchquery2 = fetchquery2.Replace("MiVariable2", xmlNodes.Item(i).FirstChild.FirstChild.Value.ToString());
string result2 = aCrm.Fetch(fetchquery2);
XmlDocument xmlDoc2 = new XmlDocument();
xmlDoc2.LoadXml(result2);
XmlNodeList xmlNodes2 = xmlDoc2.GetElementsByTagName("result");
for (int j = 0; j < xmlNodes2.Item(0).ChildNodes.Count; j++)
{
if (xmlNodes2.Item(0).ChildNodes.Item(j).Name == "new_informada")
{
XmlElement xmlelem1 = xmlDoc.CreateElement("Informada");
xmlelem1.InnerText = xmlNodes2.Item(0).ChildNodes[j].InnerXml;
xmlDoc.ChildNodes.Item(0).ChildNodes.Item(i).AppendChild(xmlelem1);
}
else if (xmlNodes2.Item(0).ChildNodes.Item(j).Name == "new_fechainformada")
{
XmlElement xmlelem2 = xmlDoc.CreateElement("Fecha");
xmlelem2.InnerText = xmlNodes2.Item(0).ChildNodes[j].Attributes["date"].Value;
xmlDoc.ChildNodes.Item(0).ChildNodes.Item(i).AppendChild(xmlelem2);
}
else if (xmlNodes2.Item(0).ChildNodes.Item(j).Name == "new_interescompromiso")
{
XmlElement xmlelem3 = xmlDoc.CreateElement("Interes");
xmlelem3.InnerText = xmlNodes2.Item(0).ChildNodes[j].InnerXml;
xmlDoc.ChildNodes.Item(0).ChildNodes.Item(i).AppendChild(xmlelem3);
}
}
}
Any suggestions or alternative?
*This post is locked for comments
I have the same question (0)