IIS CRM 2011 Web服务调用问题

时间:2013-01-12 14:44:10

标签: wcf web-services iis-7 dynamics-crm-2011 dynamics-crm

我有一个简单的程序,一个asp.net网站,其中我添加了一个webservice

其中一种网络方法访问了CRM`

 [WebMethod]
public bool RecordExists (String projectName)
{
    var service = GetService("http://localhost/EventoCorp/");

    Entity project = new Entity("new_project");

    /*PROJECT DETAILS*/
    project.Attributes["new_name"] = projectName;
    var request = new RetrieveDuplicatesRequest
    {
        BusinessEntity = project,
        MatchingEntityName = "new_project",
        PagingInfo = new PagingInfo() { PageNumber = 1, Count = 50 }
    };

    Console.WriteLine("Retrieving duplicates");
    var response = service.Execute(request);
    EntityCollection collection = (EntityCollection)response.Results["DuplicateCollection"];

    return collection.Entities.Count > 1 ? true : false;
}

当我按F5时。该项目运行良好。我调用此记录存在方法,并正确地从CRM 2011中提取数据

然而,当我在IIS 7.5上部署此应用程序时。我受到这种非常无意义的例外的欢迎

System.ServiceModel.FaultException: The server was unable to process the request due to an internal error.  For more information about the error, either turn on IncludeExceptionDetailInFaults (either from ServiceBehaviorAttribute or from the <serviceDebug> configuration behavior) on the server in order to send the exception information back to the client, or turn on tracing as per the Microsoft .NET Framework 3.0 SDK documentation and inspect the server trace logs.

服务器堆栈跟踪:

 at System.ServiceModel.Channels.ServiceChannel.ThrowIfFaultUnderstood(Message reply, MessageFault fault, String action, MessageVersion version, FaultConverter faultConverter)
   at System.ServiceModel.Channels.ServiceChannel.HandleReply(ProxyOperationRuntime operation, ProxyRpc& rpc)
   at System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[] outs, TimeSpan timeout)
   at System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCallMessage methodCall, ProxyOperationRuntime operation)
   at System.ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessage message)

我是CRM 2011 noob。不知道发生了什么。请帮帮我

1 个答案:

答案 0 :(得分:0)

在尝试连接Web服务时使用的客户端中会发生此异常。它只说服务器端发生了未处理的异常,但没有关于异常的信息。还有建议启用IncludeExceptionDetailInFaults以传递给客户端未处理的异常详细信息。但是还有其他方法可以查看正在发生的事情,它是attach到IIS进程并调试您的Web服务。
此外,最好在代码中添加异常处理,因为现在代码完全不安全。当您访问CRM时会发生不同的异常,例如身份验证异常等。此外,您可以获取null而不是您认为存在的集合。
当您将此代码部署到IIS时,可能会出现身份验证问题,因为IIS正在NETWORK SERVICE帐户下运行。如果CRM使用Windows身份验证,则您的请求可能无法获得授权。