Iis 7 无法激活wcf服务
它是一个.svc IIS托管服务,具有ssl和成员资格 我的wcf客户端报告:Iis 7 无法激活wcf服务,iis-7,wcf,Iis 7,Wcf,它是一个.svc IIS托管服务,具有ssl和成员资格 我的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 l
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的地址。此集合中每个方案最多只能有一个地址。
参数名称:item
奇怪的是,这只发生在生产服务器上,相同的代码和配置
在localhost开发服务器上运行良好。
我只更改端点地址和
从计算机名到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.ArgumentException,mscorlib,版本=2.0.0.0,区域性=中性,PublicKeyToken=b77a5c561934e089
此集合已包含具有方案http的地址。此集合中每个方案最多只能有一个地址。
参数名称:item
位于System.ServiceModel.UrischemeKeydCollection.InsertItem(Int32索引,Uri项)
位于System.Collections.Generic.SynchronizedCollection`1.Add(T项)
位于System.ServiceModel.UrischemeKeydCollection..ctor(Uri[]地址)
位于System.ServiceModel.ServiceHost..ctor(类型serviceType,Uri[]baseAddresses)
位于SharpShop.Web.StructureMap.StructureMapServiceHost..ctor(类型serviceType,Uri[]baseAddresses)
位于SharpShop.Web.StructureMap.StructureMapServiceHostFactory.CreateServiceHost(类型serviceType,Uri[]baseAddresses)
位于System.ServiceModel.Activation.ServiceHostFactory.CreateServiceHost(字符串构造函数字符串,Uri[]基地址)
位于System.ServiceModel.ServiceHostingEnvironment.HostingManager.CreateService(字符串规范化VirtualPath)
位于System.ServiceModel.ServiceHostingEnvironment.HostingManager.ActivateService(字符串规范化VirtualPath)
位于System.ServiceModel.ServiceHostingEnvironment.HostingManager.EnsureServiceAvailable(字符串规范化VirtualPath)
位于System.ServiceModel.ServiceHostingEnvironment.EnsureServiceAvailableFast(字符串相对虚拟路径)
在System.ServiceModel.Activation.HostedHttpRequestAsyncResult.HandlerRequest()中
在System.ServiceModel.Activation.HostedHttpRequestAsyncResult.BeginRequest()中
位于System.ServiceModel.Activation.HostedHttpRequestAsyncResult.OnBeginRequest(对象状态)
位于System.ServiceModel.PartialTrustHelpers.PartialTrustInvoke(ContextCallback回调,对象状态)
位于System.ServiceModel.Activation.HostedHttPrequestStatAsyncResult.OnBeginRequestWithFlow(对象状态)
位于System.ServiceModel.Channels.IOThreadScheduler.CriticalHelper.WorkItem.Invoke2()处
在System.ServiceModel.Channels.IOThreadScheduler.CriticalHelper.WorkItem.Invoke()中
在System.ServiceModel.Channels.IOThreadScheduler.CriticalHelper.ProcessCallbacks()中
位于System.ServiceModel.Channels.IOThreadScheduler.CriticalHelper.CompletionCallback(对象状态)
位于System.ServiceModel.Channels.IOThreadScheduler.CriticalHelper.ScheduledOverlapped.IOCallback(UInt32错误代码,UInt32个字节,NativeOverlapped*NativeOverlapped)
在System.ServiceModel.Diagnostics.Utility.IOCompletionThunk.UnhandledExceptionFrame(UInt32错误,UInt32字节读取,NativeOverlapped*NativeOverlapped)
在System.Threading.\u IOCompletionCallback.PerformiCompletionCallback(UInt32错误代码,UInt32个字节,本机重叠*pOVERLAP)
配置:
<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>
两种猜测:您有多个尝试在web配置中为生产服务器添加前缀:
<serviceHostingEnvironment>
<baseAddressPrefixFilters>
<add prefix="https://www.greenjump.nl:443" />
</baseAddressPrefixFilters>
</serviceHostingEnvironment>
这将添加到
您的端点应该如下所示:
<endpoint address="https://www.greenjump.nl:443/WebServices/OrderService.svc"
binding="wsHttpBinding"
bindingConfiguration="wsHttps"
contract="SharpShop.Services.IOrderService">
否则,您可以像其他评论员建议的那样,始终重载ServiceFactory。如果您在IIS中托管,则不需要“基址”部分,因为它是由IIS的站点配置提供的,所以请删除该部分 但是,当为多个主机头配置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处理多个主机头引起的。 就像布洛达特在这里说的。 错误:此集合已包含具有方案http的地址 这里更详细一些 使用第一个基地址[0]对我来说不是一个选项,因为我的基地址是 按照这个顺序,我当然可以做[1],但我不喜欢这种配置依赖关系 由于https绑定,我的问题似乎更加复杂,这是我提出的ServiceHostFactory:
public class MyServiceHostFactory : ServiceHostFactory
{
protected override ServiceHost CreateServiceHost(Type serviceType, Uri[] baseAddresses)
{
Uri webServiceAddress = baseAddresses[0]; //default to first
if (HttpContext.Current != null) //this only works when aspNetCompatibilityEnabled=true
{
string host = HttpContext.Current.Request.Url.Host;
var goodAddress = baseAddresses.FirstOrDefault(a => a.Host == host);//try to find address with same hostname as request
if(goodAddress!=null)
{
webServiceAddress = goodAddress;
}
Type[] sslServices = { typeof(OrderService) };//add all https services here
if (sslServices.Any(s => s == serviceType))
{
UriBuilder builder = new UriBuilder(webServiceAddress);
builder.Scheme = "https";
builder.Port = 443; //fails if you use another port
webServiceAddress = builder.Uri;
}
}
return new ServiceHost(serviceType, webServiceAddress);
}
}
不过,这让人觉得很不舒服,应该由microsoft解决。我使用Visual Studio 2013通过以下步骤解决了这个问题:
<%@ ServiceHost
Service="MyImplementationClass"
Factory="Example.GenericServiceHostFactory"
%>
只有一个端点,在de-dev机器上,我也使用https做了一个搜索解决方案,只是为了确保没有找到其他端点。它在devserver中工作,我只替换产品上的域名和端点位置查看配置-您是否尝试过从主服务的端点中删除显式的“address=”?哟