Public Overrides ReadOnly Property BehaviorType() As System.Type
Get
Return GetType(InlineXsdInWsdlBehavior)
End Get
End Property
Protected Overrides Function CreateBehavior() As Object
Return New InlineXsdInWsdlBehavior()
End Function
这将允许您在.config文件中添加扩展行为,并使用配置添加行为,而不必创建服务工厂 .
在system.servicemodel配置元素下添加:
<endpointBehaviors>
<behavior name="SSLLoadBalancerBehavior">
<flattenXsdImports/>
</behavior>
</endpointBehaviors>
</behaviors>
<extensions>
<behaviorExtensions>
<!--The full assembly name must be specified in the type attribute as of WCF 3.5sp1-->
<add name="flattenXsdImports" type="Org.ServiceModel.Description.FlattenXsdImportsEndpointBehavior, Org.ServiceModel, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null"/>
</behaviorExtensions>
</extensions>
3 回答
对您的服务类添加属性:
这允许客户端将服务作为https:// ...来解决,但是要在http://上托管服务,请参阅this answer了解如何创建扩展以允许指定AddressFilterMode.Any通过配置而不需要代码属性 .
在服务主机的web.config中, endpoints 元素必须在address属性中具有绝对URL,该URL是客户端将使用的公共URL . 在同一个 endpoints 元素中,将listenUri属性设置为服务主机正在侦听的绝对URL . 我确定主机正在侦听的默认绝对URI的方式是在客户端应用程序中添加服务引用,该服务引用指向托管服务的物理服务器 . 客户端的web.config将具有该服务的地址 . 然后我将其复制到主机web.config中的listenUri属性中 .
在服务行为配置中,添加具有属性httpGetEnabled = true的元素serviceMetaData
所以你会有类似的东西:
我不确定这是否适用于邮件安全性或传输安全性 . 对于此特定应用程序,凭据作为DataContract的一部分传递,因此我们有basicHttpBinding安全模式= none . 由于传输是安全的(对于ssl负载 balancer 器),因此没有安全问题 .
也可以将listenUri属性留空,但必须存在 .
遗憾的是,WCF中存在一个错误,其中WSDL中导入的模式的基地址具有listenUri基地址而不是公共基地址(使用 endpoints 的地址属性配置的地址) . 要解决该问题,您需要创建一个IWsdlExportExtension实现,它将导入的模式直接引入WSDL文档并删除导入 . 这里提供了一个例子http://winterdom.com/2006/10/inlinexsdinwsdlwithwcf . 此外,您可以让示例类继承BehaviorExtensionElement并使用以下方法完成两个新方法:
这将允许您在.config文件中添加扩展行为,并使用配置添加行为,而不必创建服务工厂 .
在system.servicemodel配置元素下添加:
然后使用behaviorConfiguration属性引用 endpoints 配置中的新 endpoints 行为
我有类似的问题,其中之一是公共和服务器地址的解决方案 . 这解决了这个问题,虽然我仍然有一些身份验证问题 .
http://blogs.msdn.com/wenlong/archive/2007/08/02/how-to-change-hostname-in-wsdl-of-an-iis-hosted-service.aspx
看http://msdn.microsoft.com/msdnmag/issues/07/06/ServiceStation/ .