这是一个具有ssl和成员资格的.svc IIS托管服务。
我的WCF客户报告:
System.ServiceModel.ServiceActivationException was unhandled
Message="The requested service, 'https://www.greenjump.nl/WebServices/OrderService.svc' could not be activated. See the server's diagnostic trace logs for more information."
Source="mscorlib"
在服务器上,我得到:
System.ArgumentException
该集合已包含一个使用方案http的地址。此集合中每个方案最多可以有一个地址。
参数名称:项目
奇怪的是,这仅发生在生产服务器上,相同的代码和配置
在本地主机开发服务器上工作正常。
我只更改端点地址,
从计算机名称到www.webdomain.com
更多服务器跟踪
<ExceptionType>
System.ArgumentException, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
</ExceptionType>
<Message>
This collection already contains an address with scheme http. There can be at most one address per scheme in this collection.
Parameter name: item
</Message>
<StackTrace>
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 SharpShop.Web.StructureMap.StructureMapServiceHost..ctor(Type serviceType, Uri[] baseAddresses)
at SharpShop.Web.StructureMap.StructureMapServiceHostFactory.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)
at System.ServiceModel.ServiceHostingEnvironment.EnsureServiceAvailableFast(String relativeVirtualPath)
at System.ServiceModel.Activation.HostedHttpRequestAsyncResult.HandleRequest()
at System.ServiceModel.Activation.HostedHttpRequestAsyncResult.BeginRequest()
at System.ServiceModel.Activation.HostedHttpRequestAsyncResult.OnBeginRequest(Object state)
at System.ServiceModel.PartialTrustHelpers.PartialTrustInvoke(ContextCallback callback, Object state)
at System.ServiceModel.Activation.HostedHttpRequestAsyncResult.OnBeginRequestWithFlow(Object state)
at System.ServiceModel.Channels.IOThreadScheduler.CriticalHelper.WorkItem.Invoke2()
at System.ServiceModel.Channels.IOThreadScheduler.CriticalHelper.WorkItem.Invoke()
at System.ServiceModel.Channels.IOThreadScheduler.CriticalHelper.ProcessCallbacks()
at System.ServiceModel.Channels.IOThreadScheduler.CriticalHelper.CompletionCallback(Object state)
at System.ServiceModel.Channels.IOThreadScheduler.CriticalHelper.ScheduledOverlapped.IOCallback(UInt32 errorCode, UInt32 numBytes, NativeOverlapped* nativeOverlapped)
at System.ServiceModel.Diagnostics.Utility.IOCompletionThunk.UnhandledExceptionFrame(UInt32 error, UInt32 bytesRead, NativeOverlapped* nativeOverlapped)
at System.Threading._IOCompletionCallback.PerformIOCompletionCallback(UInt32 errorCode, UInt32 numBytes, NativeOverlapped* pOVERLAP)
</StackTrace>
配置:
<system.serviceModel>
<bindings>
<wsHttpBinding>
<binding name="wsHttps">
<readerQuotas maxStringContentLength="128000"/>
<security mode="TransportWithMessageCredential">
<transport clientCredentialType="None"/>
<message clientCredentialType="UserName"/>
</security>
</binding>
</wsHttpBinding>
</bindings>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" >
<baseAddressPrefixFilters>
<add prefix="https://www.greenjump.nl"/>
</baseAddressPrefixFilters>
</serviceHostingEnvironment>
<behaviors>
<serviceBehaviors>
<behavior name="WsHttpWithAuthBehavior">
<serviceMetadata httpsGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="true" />
<serviceAuthorization principalPermissionMode="UseAspNetRoles"
roleProviderName="AspNetSqlRoleProvider"/>
<serviceCredentials>
<userNameAuthentication userNamePasswordValidationMode="MembershipProvider"
membershipProviderName="AspNetSqlMembershipProvider" />
</serviceCredentials>
</behavior>
</serviceBehaviors>
</behaviors>
<services>
<service behaviorConfiguration="WsHttpWithAuthBehavior" name="SharpShop.Services.OrderService">
<endpoint address="https://www.greenjump.nl/WebServices/OrderService.svc"
binding="wsHttpBinding"
bindingConfiguration="wsHttps"
contract="SharpShop.Services.IOrderService">
<identity>
<dns value="www.greenjump.nl" />
</identity>
</endpoint>
<endpoint address="mex" binding="mexHttpsBinding" contract="IMetadataExchange" />
</service>
</services>
</system.serviceModel>
最佳答案
如果您在IIS中托管,则不需要基地址部分(因为提供该地址的是IIS的站点配置),因此请删除该部分。
但是,当为多个主机 header 配置IIS时,存在一个“问题”,在这种情况下,您需要使用自定义工厂,该工厂将除去您想要的地址之外的所有地址。一个简单的例子是
namespace Example
{
public class GenericServiceHostFactory : ServiceHostFactory
{
protected override ServiceHost CreateServiceHost(Type serviceType,
Uri[] baseAddresses)
{
//return the first...
return new ServiceHost(serviceType, baseAddresses[0]);
}
}
}
然后,您将在.svc文件中使用它
<%@ ServiceHost
Service="MyImplementationClass"
Factory="Example.GenericServiceHostFactory"
%>
关于iis-7 - wcf服务无法激活,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2200105/