none
调用Microsoft Dynamics CRM 3.0中的crmservice出错 RRS feed

  • 问题

  • 使用的开发工具是vs2003,CRM是安装在服务器上的,本地调用crmservice出错。验证方式我也改成了匿名访问。不知道是什么原因。
    另外我想问一个问题,是不是我的机器要和服务器是属于同一个域。

    我的代码:

            Test.CrmSDK.CrmService service = new CrmService();
    service.Url = "http://192.168.1.200/mscrmservices/2006/crmservice.asmx";
    service.Credentials = System.Net.CredentialCache.DefaultCredentials;

    ColumnSet cols = new ColumnSet();
    cols.Attributes = new string[] { "name", "accountid"};
    ConditionExpression condition = new ConditionExpression();
    condition.AttributeName = "name";
    condition.Operator = ConditionOperator.Like;
    condition.Values = new String[] { "Test account" };

    FilterExpression filter = new FilterExpression();
    filter.FilterOperator = LogicalOperator.And;
    filter.Conditions = new ConditionExpression[] {condition};
    QueryExpression query = new QueryExpression();
    query.EntityName = EntityName.account.ToString();
    query.ColumnSet = cols;
    query.Criteria = filter;

    BusinessEntityCollection accounts = service.RetrieveMultiple(query);

    if(accounts.BusinessEntities.Length > 0) 
    {
    account a = (account)accounts.BusinessEntities[0];
    Guid accountID = a.accountid.Value;
    Response.Write(accountID.ToString());

    }


    调用后出现的异常及堆栈跟踪信息:

    Server was unable to process request.

    说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。

    异常详细信息: System.Web.Services.Protocols.SoapException: Server was unable to process request.

    源错误:

    行 153:        [return: System.Xml.Serialization.XmlElementAttribute(Namespace="http://schemas.microsoft.com/crm/2006/WebServices")]
    行 154:        public BusinessEntityCollection RetrieveMultiple([System.Xml.Serialization.XmlElementAttribute(Namespace="http://schemas.microsoft.com/crm/2006/WebServices")] QueryBase query) {
    行 155:            object[] results = this.Invoke("RetrieveMultiple", new object[] {
    行 156:                        query});
    行 157:            return ((BusinessEntityCollection)(results[0]));

    源文件: C:\Inetpub\wwwroot\Test\Web References\CrmSDK\Reference.cs    行: 155

    堆栈跟踪:

    [SoapException: Server was unable to process request.]
       System.Web.Services.Protocols.SoapHttpClientProtocol.ReadResponse(SoapClientMessage message, WebResponse response, Stream responseStream, Boolean asyncCall) +1496
       System.Web.Services.Protocols.SoapHttpClientProtocol.Invoke(String methodName, Object[] parameters) +218
       Test.CrmSDK.CrmService.RetrieveMultiple(QueryBase query) in C:\Inetpub\wwwroot\Test\Web References\CrmSDK\Reference.cs:155
       Test.WebForm1.Page_Load(Object sender, EventArgs e) in c:\inetpub\wwwroot\test\webform1.aspx.cs:45
       System.Web.UI.Control.OnLoad(EventArgs e) +67
       System.Web.UI.Control.LoadRecursive() +35
       System.Web.UI.Page.ProcessRequestMain() +731
    



    2009年12月9日 3:06

答案

  • service.Credentials = System.Net.CredentialCache.DefaultCredentials;

    改成

    service.Credentials = new System.Net.NetworkCredential("username","password", "domainname");

    指定一个账号

    Batistuta Cai-刀客 | 蔡敏生 | MS CRM MVP | Blog:http://caims.cnblogs.com
    2009年12月9日 10:00
    版主