我试图在Visual Studio 2010中创建一个客户端来访问在线CRM Web服务。 我已将服务参考添加到:
https://<myAccountId>.crm.dynamics.com/XRMServices/2011/Organization.svc?wsdl
以下是代码:
string endPoint = "https://<myAccountId>.crm.dynamics.com/XRMServices/2011/Organization.svc?wsdl";
string UserName = "<myuser>@<mydomain>.onmicrosoft.com";
string Password = "<password>";
OrganizationServiceClient orgProxy = new OrganizationServiceClient();
orgProxy.Endpoint.Address = new EndpointAddress(endPoint);
orgProxy.ClientCredentials.UserName.UserName = UserName;
orgProxy.ClientCredentials.UserName.Password = Password;
ColumnSet cols = new ColumnSet();
cols.Columns = new[] { "fullname" };
QueryExpression query = new QueryExpression();
query.EntityName = "contact";
query.ColumnSet = cols;
orgProxy.RetrieveMultiple(query);
我得到了这个例外:
var exception ='<s:Fault>
<s:Code>
<s:Value>
s:Sender
</s:Value>
<s:Subcode>
<s:Value xmlns:a="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
a:InvalidSecurity
</s:Value>
</s:Subcode>
</s:Code>
<s:Reason>
<s:Text xml:lang="en-US">
An error occurred when verifying security for the message.
</s:Text>
</s:Reason>
</s:Fault>';
使用CRM SDK不是我的选择,因为它需要4.0 .Net框架,我的代码全部是3.5。谢谢!