CRM Web Service from .net compact framework

P

Peter Kenyon

Hi,

I have been attempting to use the CRM web service to retrieve a list of
accounts belonging to the connected user. I am able to do this from my
workstation, but the same code executed on a pocket PC device behaves as if
the query's Criteria and ColumnSet fields have been left null: the query
returns all the accounts I have read access to (ie all on the system) and
only a single attribute for each account (accountid).

I captured the SOAP sessions from my device and there are a few differences:
the device is sending a soap header while the workstation is not, the
namespace is missing from the <Order> element on the device, and the order
of some XML nodes in the soap request is different. I'm not sure which if
any of these should result in the behaviour I'm seeing, and if so what I can
do to change XML generated by the .net compact framework.

Does anybody have any suggestions before I open a support incident? I am
using the .net compact framework 2.0 SP1.

Cheers

Peter

My code below:

CrmService service = new CrmTest.mscrm.CrmService();
service.Credentials = new System.Net.NetworkCredential("Peter", "*******",
"mydomain");

WhoAmIResponse whoAmI = (WhoAmIResponse)service.Execute(new
WhoAmIRequest());

ColumnSet columnSet = new ColumnSet();
columnSet.Attributes = new string[] { "accountnumber", "name",
"address1_name", "address1_line1", "address1_line2", "address1_line3",
"address1_postalcode", "address1_city" };

ConditionExpression conditionExpression = new ConditionExpression();
conditionExpression.AttributeName = "ownerid";
conditionExpression.Operator = ConditionOperator.Equal;
conditionExpression.Values = new object[] { whoAmI.UserId };

FilterExpression filterExpression = new FilterExpression();
filterExpression.FilterOperator = LogicalOperator.And;
filterExpression.Conditions = new ConditionExpression[] {
conditionExpression };
filterExpression.Filters = new FilterExpression[0];

QueryExpression query = new QueryExpression();
query.EntityName = Convert.ToString(EntityName.account);
query.ColumnSet = columnSet;
query.Criteria = filterExpression;
query.Distinct = true;
query.Orders = new OrderExpression[] { new OrderExpression() };
query.Orders[0].AttributeName = "name";
query.Orders[0].OrderType = OrderType.Ascending;
query.PageInfo = new PagingInfo();
query.PageInfo.Count = 50;
query.PageInfo.PageNumber = 1;

RetrieveMultipleRequest request = new RetrieveMultipleRequest();
request.Query = query;
request.ReturnDynamicEntities = true;
RetrieveMultipleResponse response =
(RetrieveMultipleResponse)service.Execute(request);
 
P

Peter Kenyon

Peter Kenyon said:
Hi,

I have been attempting to use the CRM web service to retrieve a list of
accounts belonging to the connected user. I am able to do this from my
workstation, but the same code executed on a pocket PC device behaves as
if the query's Criteria and ColumnSet fields have been left null: the
query returns all the accounts I have read access to (ie all on the
system) and only a single attribute for each account (accountid).

I captured the SOAP sessions from my device and there are a few
differences: the device is sending a soap header while the workstation is
not, the namespace is missing from the <Order> element on the device, and
the order of some XML nodes in the soap request is different. I'm not sure
which if any of these should result in the behaviour I'm seeing, and if so
what I can do to change XML generated by the .net compact framework.

Does anybody have any suggestions before I open a support incident? I am
using the .net compact framework 2.0 SP1.

Cheers

Peter

I've isolated the problem: some of the elements in the soap document
generated by the cf are missing namespaces and hence ignored by the CRM
service. Eg the request from the workstation looks like this:
.....
<q1:Conditions>
<q1:Condition>
<q1:AttributeName>ownerid</q1:AttributeName>
<q1:Operator>Equal</q1:Operator>
<q1:Values>
<q1:Value xmlns:q2="http://microsoft.com/wsdl/types/"
xsi:type="q2:guid">eaccbd71-f37f-db11-971c-0007e933207f</q1:Value>
</q1:Values>
</q1:Condition>
</q1:Conditions>
.....

while the device request looks like this:
.....
<q1:Conditions>
<Condition> !!! namespace missing
<q1:Values>
<Value xmlns:q2="http://microsoft.com/wsdl/types/"
xsi:type="q2:guid">eaccbd71-f37f-db11-971c-0007e933207f</Value>
</q1:Values>
<q1:Operator>Equal</q1:Operator>
<q1:AttributeName>ownerid</q1:AttributeName>
</Condition>
</q1:Conditions>
.....

The CRM service thinks it's receiving a query with no condition due to the
missing namespaces. If I manually code up a request using the soap request
generated by the device but with namespaces added to the Condition and Value
tags, then it behaves correctly.

Is the lack of namespaces due to a bug in the cf, if so is there any way I
can work around this so that the correct SOAP requests are generated?

Any advice will be much appreciated.

Peter
 
J

Jeffry van de Vuurst

I've isolated the problem: some of the elements in the soap document
generated by the cf are missing namespaces and hence ignored by the CRM
service. Eg the request from the workstation looks like this:
....
<q1:Conditions>
<q1:Condition>
<q1:AttributeName>ownerid</q1:AttributeName>
<q1:Operator>Equal</q1:Operator>
<q1:Values>
<q1:Value xmlns:q2="http://microsoft.com/wsdl/types/"
xsi:type="q2:guid">eaccbd71-f37f-db11-971c-0007e933207f</q1:Value>
</q1:Values>
</q1:Condition>
</q1:Conditions>
....

while the device request looks like this:
....
<q1:Conditions>
<Condition> !!! namespace missing
<q1:Values>
<Value xmlns:q2="http://microsoft.com/wsdl/types/"
xsi:type="q2:guid">eaccbd71-f37f-db11-971c-0007e933207f</Value>
</q1:Values>
<q1:Operator>Equal</q1:Operator>
<q1:AttributeName>ownerid</q1:AttributeName>
</Condition>
</q1:Conditions>
....

The CRM service thinks it's receiving a query with no condition due to the
missing namespaces. If I manually code up a request using the soap request
generated by the device but with namespaces added to the Condition and Value
tags, then it behaves correctly.

Is the lack of namespaces due to a bug in the cf, if so is there any way I
can work around this so that the correct SOAP requests are generated?

Any advice will be much appreciated.

Peter


Hi Peter,

I see you already figured out the problem. I struggled with exactly
the same problem some time ago. I do think it's a bug in CF, it should
just generate those namespaces.

Anyway, the workaround is to edit the generated webservice proxy file
and explicitly add the namespace to the elements that miss them in the
soap message. E.g. here's one I added:
/// <summary>
/// Explicit namespace has been added. Without this CF omits to add a
namespace prefix
/// to the items in the array which causes problems when deserializing
the xml into an object.
/// </summary>
[System.Xml.Serialization.XmlArrayItemAttribute(ElementName =
"Condition", Namespace = "http://schemas.microsoft.com/crm/2006/
Query", IsNullable = false)]
public ConditionExpression[] Conditions
{
get
{
return this.conditionsField;
}
set
{
this.conditionsField = value;
}
}

HTH,
 
P

Peter Kenyon

Jeffry van de Vuurst said:
I've isolated the problem: some of the elements in the soap document
generated by the cf are missing namespaces and hence ignored by the CRM
service. Eg the request from the workstation looks like this:
....
<q1:Conditions>
<q1:Condition>
<q1:AttributeName>ownerid</q1:AttributeName>
<q1:Operator>Equal</q1:Operator>
<q1:Values>
<q1:Value xmlns:q2="http://microsoft.com/wsdl/types/"
xsi:type="q2:guid">eaccbd71-f37f-db11-971c-0007e933207f</q1:Value>
</q1:Values>
</q1:Condition>
</q1:Conditions>
....

while the device request looks like this:
....
<q1:Conditions>
<Condition> !!! namespace missing
<q1:Values>
<Value xmlns:q2="http://microsoft.com/wsdl/types/"
xsi:type="q2:guid">eaccbd71-f37f-db11-971c-0007e933207f</Value>
</q1:Values>
<q1:Operator>Equal</q1:Operator>
<q1:AttributeName>ownerid</q1:AttributeName>
</Condition>
</q1:Conditions>
....

The CRM service thinks it's receiving a query with no condition due to
the
missing namespaces. If I manually code up a request using the soap
request
generated by the device but with namespaces added to the Condition and
Value
tags, then it behaves correctly.

Is the lack of namespaces due to a bug in the cf, if so is there any way
I
can work around this so that the correct SOAP requests are generated?

Any advice will be much appreciated.

Peter


Hi Peter,

I see you already figured out the problem. I struggled with exactly
the same problem some time ago. I do think it's a bug in CF, it should
just generate those namespaces.

Anyway, the workaround is to edit the generated webservice proxy file
and explicitly add the namespace to the elements that miss them in the
soap message. E.g. here's one I added:
/// <summary>
/// Explicit namespace has been added. Without this CF omits to add a
namespace prefix
/// to the items in the array which causes problems when deserializing
the xml into an object.
/// </summary>
[System.Xml.Serialization.XmlArrayItemAttribute(ElementName =
"Condition", Namespace = "http://schemas.microsoft.com/crm/2006/
Query", IsNullable = false)]
public ConditionExpression[] Conditions
{
get
{
return this.conditionsField;
}
set
{
this.conditionsField = value;
}
}

HTH,

Thanks Jeffry. It's a little annoying, because I'll have to re-edit the
proxy file any time it is refreshed. However, I'm glad to have a solution to
the problem.

Cheers,

Peter
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top