2013-10-23 134 views
0

当我试图从一个XML文件中读取,当我尝试使用加载它的XmlDocument我得到这个错误处理请求错误: 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 SDK documentation and inspect the server trace logs.服务器无法加载XML文件

下面是导致此代码:

public string calorieCount(int choice) 
    { 
    string calCount = "250"; 
    XmlDocument doc = new XmlDocument(); 

    //ERROR WITH LINE BELOW. no error without. 
    doc.LoadXml("XMLFile1.xml"); 

    //XmlElement root = doc.DocumentElement; 
    //XmlNode node = doc.SelectSingleNode("/menu/item[@name='Burger']/calories"); 
    //string checker = node.Value; 
    //MessageBox.Show(checker); 
    return calCount; 
} 

看起来好像不管我放在哪里的路径都行不通。有任何想法吗?

编辑 我做了以下错误仍然存​​在,我已经更新了服务的参考,它仍然给了我这个错误。

<behavior name="debug"> 
     <serviceDebug includeExceptionDetailInFaults="true"/> 
</behavior> 

<services> 
<service name="calorieCount" behaviorConfiguration="debug"></service> 
</services> 

回答

3

做这件事情的错误消息指出。

添加到您的服务 -

<services> 
     <service name="YourServiceName" behaviorConfiguration="debug"> 
    </services> 

添加到您的配置文件

<serviceBehaviors> 
    <behavior name="debug"> 
    <serviceDebug includeExceptionDetailInFaults="true" /> 
    </behavior> 
</serviceBehaviors> 

编辑

  1. 如果不能解决你的问题,请跟踪上。
  2. 确保服务名称全称如:Namespace.ClassName
  3. 确保合同具有完全如名称:Namespace.ClassName
+0

我已经试过这一点,但什么也没有发生 – Andy

+2

你有没有回收的应用程序池的网站在进行配置更改后使用服务? – Dijkgraaf

+1

@Andy:如果你仍然收到相同的错误信息,那么你还没有打开这个服务。 – NotMe