500承载WCF时出现服务器错误

本文关键字:服务器 错误 承载 WCF | 更新日期: 2023-09-27 18:29:41

也许你可以帮我,因为我在这里真的不知所措。

我正在尝试在子域上的IIS上托管我的WCF服务。

首先,这里是我的文件结构:

http://s18.postimage.org/eqmjxb00n/Serv.jpg

bin里面是我的.dll,代表我的接口及其实现。

这是web.config文件:

<?xml version="1.0"?>
<configuration>
  <system.web>
    <compilation debug="false" targetFramework="4.0" />
  </system.web>    
    <system.serviceModel>
        <services>
            <service name="AuthenticatorService.Authenticator">
                <endpoint address="" binding="basicHttpBinding" bindingConfiguration=""
                    name="AuthEndpoint" contract="AuthInterface.IAuthenticator" />
                <endpoint address="" binding="mexHttpBinding" name="MetadataEndpoint"
                    contract="IMetadataExchange" />
            </service>
        </services>
        <behaviors>
            <serviceBehaviors>
                <behavior>
                    <serviceMetadata httpGetEnabled="True"/>
                    <serviceDebug includeExceptionDetailInFaults="False" />
                </behavior>
            </serviceBehaviors>
        </behaviors>
    </system.serviceModel>
  <system.webServer>
    <modules runAllManagedModulesForAllRequests="true"/>
  </system.webServer>
</configuration>

它在本地工作,但当我上传到IIS时,它只会出现500个服务器错误。

谢谢!

如果它有任何用处,这里是来自详细错误页面的消息:

Module  ServiceModel-4.0
Notification    AuthenticateRequest
Handler svc-Integrated-4.0
Error Code  0x00000000
Requested URL   http://service.swiftposter.com:80/auth.svc
Logon Method    Anonymous
Logon User  Anonymous

编辑:我启用了ELMAH日志记录,最后得到了一条有意义的完整消息:

System.ArgumentException: This collection already contains an address with scheme http. There can be at most one address per scheme in this collection. If your service is being hosted in IIS you can fix the problem by setting 'system.serviceModel/serviceHostingEnvironment/multipleSiteBindingsEnabled' to true or specifying 'system.serviceModel/serviceHostingEnvironment/baseAddressPrefixFilters'. Parameter name: item

我打算开始研究这个错误,但我在这里发布了,以防有人知道哪里出了问题。

堆栈跟踪:

System.ServiceModel.ServiceActivationException: The service '/auth.svc' cannot be activated due to an exception during compilation.  The exception message is: This collection already contains an address with scheme http.  There can be at most one address per scheme in this collection. If your service is being hosted in IIS you can fix the problem by setting 'system.serviceModel/serviceHostingEnvironment/multipleSiteBindingsEnabled' to true or specifying 'system.serviceModel/serviceHostingEnvironment/baseAddressPrefixFilters'.
Parameter name: item. ---> System.ArgumentException: This collection already contains an address with scheme http.  There can be at most one address per scheme in this collection. If your service is being hosted in IIS you can fix the problem by setting 'system.serviceModel/serviceHostingEnvironment/multipleSiteBindingsEnabled' to true or specifying 'system.serviceModel/serviceHostingEnvironment/baseAddressPrefixFilters'.
Parameter name: item
   at System.ServiceModel.UriSchemeKeyedCollection.InsertItem(Int32 index, Uri item)
   at System.Collections.Generic.SynchronizedCollection`1.Add(T item)
   at System.ServiceModel.UriSchemeKeyedCollection..ctor(Uri[] addresses)
   at System.ServiceModel.ServiceHost..ctor(Type serviceType, Uri[] baseAddresses)
   at System.ServiceModel.Activation.ServiceHostFactory.CreateServiceHost(Type serviceType, Uri[] baseAddresses)
   at System.ServiceModel.Activation.ServiceHostFactory.CreateServiceHost(String constructorString, Uri[] baseAddresses)
   at System.ServiceModel.ServiceHostingEnvironment.HostingManager.CreateService(String normalizedVirtualPath)
   at System.ServiceModel.ServiceHostingEnvironment.HostingManager.ActivateService(String normalizedVirtualPath)
   at System.ServiceModel.ServiceHostingEnvironment.HostingManager.EnsureServiceAvailable(String normalizedVirtualPath)
   --- End of inner exception stack trace ---
   at System.Runtime.AsyncResult.End[TAsyncResult](IAsyncResult result)
   at System.ServiceModel.Activation.HostedHttpRequestAsyncResult.End(IAsyncResult result)
   at System.ServiceModel.Activation.ServiceHttpModule.EndProcessRequest(IAsyncResult ar)
   at System.Web.HttpApplication.AsyncEventExecutionStep.OnAsyncEventCompletion(IAsyncResult ar)

500承载WCF时出现服务器错误

我通过将其添加到web.config中修复了错误。

<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />

我想这是因为我有两个绑定,它们都使用http。也许其他人可以详细说明。

错误500识别任何类型的服务器错误。。。尝试从localhost访问该服务(IIS的默认设置仅在本地显示错误)。

同时尝试将IIS设置编辑为"将错误发送到浏览器"或在Internet Information Services(IIS)Manager>Your Web>Error Pages>properties中,然后选择Detail errors

通过这种方式,您可以看到服务引发的真正错误。

还要检查在应用程序池中是否选择了正确的框架版本

您的服务地址和服务的元数据地址

<system.serviceModel>
 <services>
   <service name="AuthenticatorService.Authenticator">
      <endpoint address="" binding="basicHttpBinding" bindingConfiguration=""
                name="AuthEndpoint" contract="AuthInterface.IAuthenticator" />
       <endpoint address="mex" binding="mexHttpBinding" name="MetadataEndpoint"
                contract="IMetadataExchange" />
   </service>
  </services>
  ...
</system.serviceModel>

http://msdn.microsoft.com/en-us/library/ms733766.aspx