gpt4 book ai didi

c# - WCF REST API - 使用 REST API 时出错“值不能为空。参数名称 : key:

转载 作者:行者123 更新时间:2023-12-03 04:35:36 27 4
gpt4 key购买 nike

我创建了一个 WCF REST API 并将其发布到 Windows Azure。该代码在 Azure 模拟器中完美运行。但是,当尝试通过浏览器使用 API GET 方法时,我收到以下错误:

    [ArgumentNullException: Value cannot be null.
Parameter name: key]
System.ThrowHelper.ThrowArgumentNullException(ExceptionArgument argument) +48
System.Collections.Generic.Dictionary`2.FindEntry(TKey key) +38
System.Collections.Generic.Dictionary`2.TryGetValue(TKey key, TValue& value) +20
System.ServiceModel.Dispatcher.WebHttpDispatchOperationSelector..ctor(ServiceEndpoint
endpoint) +2459
System.ServiceModel.Description.WebHttpBehavior.GetOperationSelector(ServiceEndpoint endpoint) +125
System.ServiceModel.Description.WebHttpBehavior.ApplyDispatchBehavior(ServiceEndpoint endpoint, EndpointDispatcher endpointDispatcher) +1955
System.ServiceModel.Description.DispatcherBuilder.InitializeServiceHost(ServiceDescription description, ServiceHostBase serviceHost) +4245
System.ServiceModel.ServiceHostBase.InitializeRuntime() +119
System.ServiceModel.ServiceHostBase.OnOpen(TimeSpan timeout) +45
System.ServiceModel.Channels.CommunicationObject.Open(TimeSpan timeout) +553
System.ServiceModel.HostingManager.ActivateService(ServiceActivationInfo serviceActivationInfo, EventTraceActivity eventTraceActivity) +350
System.ServiceModel.HostingManager.EnsureServiceAvailable(String normalizedVirtualPath, EventTraceActivity eventTraceActivity) +1614

[ServiceActivationException: The service '/RestServiceImpl.svc' cannot be activated due to an exception during compilation. The exception message is: Value cannot be null.
Parameter name: key.]
System.Runtime.AsyncResult.End(IAsyncResult result) +911
System.ServiceModel.Activation.HostedHttpRequestAsyncResult.End(IAsyncResult result) +525
System.ServiceModel.Activation.ServiceHttpModule.EndProcessRequest(IAsyncResult ar) +98
System.Web.AsyncEventExecutionStep.OnAsyncEventCompletion(IAsyncResult ar) +126

从堆栈跟踪来看,错误似乎与服务的端点有关。经过更多调查后,当从 web.config 中删除该元素时,此错误消失并出现另一个错误。但我看到的每个示例都出现在 web.config 中。这是我的网络配置:

    <?xml version="1.0"?>
<configuration>
<system.web>
<compilation debug="true" targetFramework="4.0" />
<customErrors mode="Off"/>
</system.web>
<system.serviceModel>
<services>
<service name="RestService.RestServiceImpl"
behaviorConfiguration="ServiceBehavior">
<endpoint address=""
binding="webHttpBinding"
contract="RestService.IRestServiceImpl"
behaviorConfiguration="web">
</endpoint>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="ServiceBehavior">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="false" />
</behavior>
</serviceBehaviors>
<endpointBehaviors>
<behavior name="web">
<webHttp />
</behavior>
</endpointBehaviors>
</behaviors>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
</system.serviceModel>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true" />
</system.webServer>
</configuration>

最佳答案

您没有为要等待的服务定义基址。

<services> 
<service name="RestService.RestServiceImpl" behaviorConfiguration="ServiceBehavior">
<host>
<baseAddresses>
<add baseAddress="http://localhost:1234/MyWCF/"/>
</baseAddresses>
</host>
<endpoint address=""
binding="webHttpBinding"
contract="RestService.IRestServiceImpl"
behaviorConfiguration="web">
</endpoint>
</service>
</services>

关于c# - WCF REST API - 使用 REST API 时出错“值不能为空。参数名称 : key:,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25399770/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com