0

I have change server and now i'm having a problem with fechxml, all other SOAP services are working 100%, like updade, create, delete, expect fetch, and i don`t have idea or the reason for this to be happening.

Mesagem error:

@"Server was unable to process request.
       at System.Web.Services.Protocols.SoapHttpClientProtocol.ReadResponse(SoapClientMessage message, WebResponse response, Stream responseStream, Boolean asyncCall)
       at System.Web.Services.Protocols.SoapHttpClientProtocol.Invoke(String methodName, Object[] parameters)
       at ws.CrmService.CrmService.Fetch(String fetchXml) in c:\CRMServer\ws\ws\Web References\CrmService\Reference.cs:line 180
       at wsService.Crm2013test(String nomechave) in c:\CRMServer\ws\ws\test\test2013.cs:line 416"

Reference.cs file:

[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]));
}

test2013 file:

 public PrxActivityResult Crm2013test(string nomechave)

{
    PrxActivityResult res = new PrxActivityResult();
    Tb_Log_Create("WS.Crm2013test", "Entrada", "Codigo; valor:" + nomechave, "Anónimo");


    try
    {

        OrganizationServiceProxy organizationProxy = CrmServiceManager.GetOrganisationServiceProxy();
        CrmService service = CrmServiceManager.GetCrmService();

        Microsoft.Xrm.Sdk.Query.ConditionExpression condition = new Microsoft.Xrm.Sdk.Query.ConditionExpression("name", Microsoft.Xrm.Sdk.Query.ConditionOperator.Like, new string[] { nomechave });

        Microsoft.Xrm.Sdk.Query.FilterExpression filter = new Microsoft.Xrm.Sdk.Query.FilterExpression();
        filter.AddCondition(condition);
        filter.FilterOperator = Microsoft.Xrm.Sdk.Query.LogicalOperator.And;

        Microsoft.Xrm.Sdk.Query.QueryExpression query = new Microsoft.Xrm.Sdk.Query.QueryExpression();
        query.EntityName = "account";
        query.ColumnSet = new Microsoft.Xrm.Sdk.Query.ColumnSet(true);
       // query.Criteria = filter;

        EntityCollection ec = organizationProxy.RetrieveMultiple(query);

        string fetchXml = @"<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='false'>
            <entity name='account'>
            <attribute name='name'/>
            <attribute name='telephone1'/>
            </entity></fetch>";

        string ret = service.Fetch(fetchXml);
        res.XmlContent = ret;

        }


    catch (Exception ex)
    {
    }
    return res;
}

Any one have an idea of what is? Thanks a million

Hugo Silva
  • 155
  • 1
  • 3
  • 16
  • 1
    can you please explain what are you trying to do by writing `result.XmlContent = return;` I don't think you can even build this code by using a reserved keyword as variable name. – Scorpion Sep 25 '13 at 13:04
  • Hi Scorpion, the issue is not there, `result.XmlContent = return` ist ok, the problem is whend execute the `service.Fetch(fetchXml)` give me the Exception. The `result.XmlContent = return` it will return me the xml content. – Hugo Silva Sep 25 '13 at 14:06

1 Answers1

1

Don't know if there is something else, but you're missing your closing </Entity> Tag in your fetch XML.

Edit

wondering why you're rolling you're own Fetch SOAP.

Should just be doing something like this:

string fetchXml = @"<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='false'>
    <entity name='account'>
    <attribute name='name'/>
    <attribute name='telephone1'/>
</fetch>";

EntityCollection ec = organizationProxy.RetrieveMultiple(new FetchExpression(fetchXml));

Also, OrganizationServiceProxy implements IDisposible and therefor should be wrapped in a using statement

Daryl
  • 18,592
  • 9
  • 78
  • 145
  • Hi Daryl, yes it's missing, but i failed on the copy & paste, but even with the `` does not work! – Hugo Silva Sep 26 '13 at 13:44
  • @HugoSilva Fix your post then, and see updated answer. And `string return = service.Fetch(fetchXml);` doesn't compile for me. – Daryl Sep 26 '13 at 13:57
  • It Works OK, i can get the info but now who can i put the result on a string? Example: abs1232 ? This was what i have in the past and it works, i really dont know why is not working enymore. – Hugo Silva Sep 26 '13 at 14:54
  • @HugoSilva You could always serialize the entities back, or gen your own XML based on the attributes collection. Or ask a new Question, "How do I access the result of FetchXML as XML rather than entities?" – Daryl Sep 26 '13 at 15:06