我有一个WCF服务(在IIS 7.5中托管),它使用以下
来激活SVC文件<serviceHostingEnvironment>
<serviceActivations>
<add factory="String"
service="String"/>
</serviceActivations>
</serviceHostingEnvironment>
我使用的是自定义主机工厂而非默认主机工厂。
该服务是WSTrustServiceContract。现在,如果你看到这个类的声明
[ServiceBehaviorAttribute(Name = "SecurityTokenService", Namespace = "http://schemas.microsoft.com/ws/2008/06/identity/securitytokenservice",
InstanceContextMode = InstanceContextMode.Single, ConcurrencyMode = ConcurrencyMode.Multiple)]
[AspNetCompatibilityRequirementsAttribute(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
public class WSTrustServiceContract : IWSTrustFeb2005SyncContract,
IWSTrust13SyncContract, IWSTrustFeb2005AsyncContract, IWSTrust13AsyncContract, IWsdlExportExtension, IContractBehavior
所以我们可以推断出
我的问题是
答案 0 :(得分:0)
正如我所说,我创建了简单的应用程序,它工作正常。所以试着比较一下:
<强>的ServiceHost 强>
Public Class MyServiceHost
Inherits ServiceHost
Public Sub New(serviceType As Type, baseAddresses As Uri())
MyBase.New(serviceType, baseAddresses)
End Sub
End Class
Public Class MyServiceHostFactory
Inherits ServiceHostFactory
Public Sub New()
Trace.TraceInformation("MyServiceHost instance created.")
End Sub
Protected Overrides Function CreateServiceHost(serviceType As Type, baseAddresses As Uri()) As ServiceHost
Return New MyServiceHost(serviceType, baseAddresses)
End Function
End Class
<强>服务强>
<ServiceContract>
Public Interface IService
<OperationContract()>
Function SayHello(name As String) As String
End Interface
<ServiceBehavior(InstanceContextMode:=InstanceContextMode.Single, ConcurrencyMode:=ConcurrencyMode.Multiple)>
<AspNetCompatibilityRequirements(RequirementsMode:=AspNetCompatibilityRequirementsMode.Allowed)>
Public Class Service
Implements IService
Public Sub New()
Trace.TraceInformation("Service instance created.")
End Sub
Public Function SayHello(name As String) As String Implements IService.SayHello
Trace.TraceInformation("Calling Service.SayHello({0}).", name)
Return "Hello " & name
End Function
End Class
Public Class Global_asax
Inherits HttpApplication
Sub Application_Start(ByVal sender As Object, ByVal e As EventArgs)
Trace.TraceInformation("Application started")
End Sub
End Class
<强>的Web.config 强>
<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior>
<serviceMetadata httpGetEnabled="true" />
</behavior>
</serviceBehaviors>
</behaviors>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true">
<serviceActivations>
<add factory="FileLessActivationWithCustomServiceHost.MyServiceHostFactory"
service="FileLessActivationWithCustomServiceHost.Service"
relativeAddress="Service.svc"/>
</serviceActivations>
</serviceHostingEnvironment>
</system.serviceModel>
<system.diagnostics>
<trace autoflush="true" indentsize="4">
<listeners>
<remove name="Default" />
<add name="Default"
type="System.Diagnostics.XmlWriterTraceListener"
initializeData="log.svclog" />
</listeners>
</trace>
</system.diagnostics>
我启动了Web应用程序,对SayHello
函数进行了几次调用,如下所示,它的行为正确: