【发布时间】:2013-10-16 15:21:47
【问题描述】:
我是写问题的新手,老读者。如果我遗漏了什么,请告诉我。
我查看了许多不同的方案和可能的修复,但无法让我的 WCF 服务正常工作。
我的服务负责将来自许多不同集合的数据传递到主存储库。客户端在本地集合级别收集数据并将其传递给插入数据并传回结果消息的服务。再次在测试环境中,这正常工作。
在生产中,我将服务添加到异地服务器并在远程集上配置客户端。客户端能够配置和接收来自服务的更新。到目前为止,一切正常。但是,一旦客户端尝试通过它传输数据,就会收到以下错误“对象引用未设置为对象的实例。”
通过错误检查,我确认数据库没有连接字符串问题。我在我的测试环境中再次运行相同的数据传输,没有任何问题。我能够连接到本地集上的 .svc url。
我已通过数据协定方法调用在不同点添加了日志记录,但这些日志均未触发任何结果。我还在测试应用程序上测试了写入功能,确认写入临时文件夹的凭据没有问题。例如:
public Result InsertVenueRecord(Venue v)
{
System.IO.File.WriteAllText(@"C:\temp\MadeItToVenue" + DateTime.Now.Ticks.ToString() + ".log.txt", "insertVenue()\r\n\r\n");
int oldId = v.VenueId;
try
{
System.IO.File.WriteAllText(@"C:\temp\MadeItToVenue" + DateTime.Now.Ticks.ToString() + ".log.txt", "insertVenue()\r\n\r\n");
//Check Address
if (v.Address.AddressId != 0)
客户端 app.Config 如下所示:
<configuration>
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="BasicHttpBinding_placeholder" />
</basicHttpBinding>
</bindings>
<client>
<endpoint address="Removed" binding="basicHttpBinding"
bindingConfiguration="BasicHttpBinding_placeholder" contract="placeholder.placeholder"
name="BasicHttpBinding_placeholder" />
</client>
</system.serviceModel>
<appSettings>
<add key="DTFirstWave" value="Venue|Event|EventSurveyLocation|Agent|LoginHistory|LoginUsed"/>
</appSettings>
<connectionStrings>
<!-- Removed Connection Strings -->
</connectionStrings>
</configuration>
服务 webconfig 如下所示:
<configuration>
<system.web>
<compilation debug="true" targetFramework="4.0"/>
<httpRuntime/>
</system.web>
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding allowCookies="true" maxBufferPoolSize="2147483647" maxBufferSize="2147483647" maxReceivedMessageSize="2147483647">
<readerQuotas maxDepth="32" maxStringContentLength="52428800" maxArrayLength="52428800" maxBytesPerRead="52428800" maxNameTableCharCount="52428800"/>
</binding>
</basicHttpBinding>
</bindings>
<behaviors>
<serviceBehaviors>
<behavior>
<!-- To avoid disclosing metadata information, set the values below to false before deployment -->
<serviceMetadata httpGetEnabled="true" httpsGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="false"/>
</behavior>
</serviceBehaviors>
</behaviors>
<protocolMapping>
<add binding="basicHttpsBinding" scheme="https"/>
</protocolMapping>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true"/>
</system.serviceModel>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true"/>
<directoryBrowse enabled="true"/>
</system.webServer>
<connectionStrings>
<!--Removed -->
</connectionStrings>
</configuration>
我不知道为什么这不起作用。
【问题讨论】:
-
尝试更改服务器配置:
<serviceDebug includeExceptionDetailInFaults="true"/>然后任何服务器端异常都应发送到客户端 -
我最初将其标记为 true。由于此错误,我将其更改为 false:该服务无法激活,因为它不支持 ASP.NET 兼容性。为此应用程序启用了 ASP.NET 兼容性。在 web.config 中关闭 ASP.NET 兼容模式,或将 AspNetCompatibilityRequirements 属性添加到服务类型,RequirementsMode 设置为“Allowed”或“Required”。
-
我将尝试解决该问题以获取有关异常的更多详细信息。谢谢!
-
我添加了 true 标志。没有给出新的细节。仍然在同一条船上。
-
NullReferenceException的几乎所有情况都是相同的。请参阅“What is a NullReferenceException in .NET?”获取一些提示。这可能是一个简单的服务编程错误,与配置无关。
标签: c# wcf nullreferenceexception