首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >WCF4宿主在IIS中,WSDL: bindingNamespace永远不会被读取

WCF4宿主在IIS中,WSDL: bindingNamespace永远不会被读取
EN

Stack Overflow用户
提问于 2011-01-19 07:04:33
回答 1查看 5.6K关注 0票数 3

尝试从wsdl文件中删除"tempuri“引用。我遵循了我能想到的所有现有的建议。添加

代码语言:javascript
复制
[ServiceBehavior(Namespace="mynamespace")] 

属性添加到实现类中,则添加一个

代码语言:javascript
复制
[ServiceContract(Namespace="mynamespace")]

添加到contract接口,并更改web.config中端点的"bindingNamespace“属性以进行匹配。然而,当(在IIS中)加载时,bindingnamespace永远不会改变。它总是天妇罗。

有没有人有解决这个问题的其他想法?下面的示例来自web config...the绑定命名空间,无论我做什么,都不会更新为mynamespace,它始终是tempuri.org。如果在通过主机工厂加载端点后,我迭代主机描述中的绑定并更新它们,它们将会更改,但这似乎是一种黑客行为。

对于位于:"http://mydomain.com/MyService.svc“的服务,下面是我的终结点配置,它会被IIS使用吗?

代码语言:javascript
复制
<services>
  <service name="ServiceImplementationClassReference,MyAssembly" >
    <endpoint name=""
              address="MyService.svc"
              binding="basicHttpBinding"
              bindingNamespace="mynamespace"
              bindingConfiguration=""
              contract="IMyContract" />

    <endpoint name="mexHttpBinding" 
              address="mex"
              binding="mexHttpBinding"
              contract="IMetadataExchange" />        
  </service>
</services>

生成的仍然引用tempuri.org的WSDL文件的相关片段

代码语言:javascript
复制
  <wsdl:import namespace="http://tempuri.org/" location="http://mydomain.org/MyService.svc?wsdl=wsdl0" />

.

代码语言:javascript
复制
  <wsdl:service name="Directory">
    <wsdl:port name="BasicHttpBinding_IDirectoryServices"
    binding="i0:BasicHttpBinding_IDirectoryServices">
      <soap:address location="http://mydomain.org/MyService.svc" />
    </wsdl:port>
  </wsdl:service>

在wsdl:definition节点中,xml名称空间导入(正如上面列出的服务所引用的)也被设置为tempuri.org,因此需要使用i0语句。如果我使用BasicHttpBinding或wsHttpBinding,temprui的用法没有变化。实际上,在web.config文件中将绑定设置为wsHttpBinding仍然会导致上面的输出,引用BasicHttpBinding_IdirectoryServices。

谢谢!

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2011-01-20 01:44:07

似乎是一个已知的问题:https://connect.microsoft.com/wcf/feedback/details/583163/endpoint-bindingnamespace?wa=wsignin1.0

这是我的web.config的印章。请注意,我将我的使用限制为HTTPS,因此YMMV包含您可能需要执行的操作:

代码语言:javascript
复制
    <behaviors>
        <endpointBehaviors>
            <behavior name="Secure" />
        </endpointBehaviors>
        <serviceBehaviors>
            <behavior name="MetadataBehavior">
                <serviceMetadata httpsGetEnabled="true" />
                <serviceDebug includeExceptionDetailInFaults="true" />
            </behavior>
        </serviceBehaviors>
    </behaviors>
    <serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
    <services>
        <service name="Company.Services.Implementation.Service" behaviorConfiguration="MetadataBehavior">
            <endpoint address="" behaviorConfiguration="Secure"
                      binding="basicHttpBinding" bindingConfiguration="httpsBinding" bindingNamespace="http://services.company.com"
                      contract="Company.Services.Interfaces.IService" />
            <endpoint address="mex" behaviorConfiguration="Secure"
                      binding="mexHttpsBinding" bindingConfiguration="httpsBinding" bindingNamespace="http://services.company.com"
                      contract="IMetadataExchange" />
        </service>
    </services>
    <bindings>
        <basicHttpBinding>
            <binding name="httpsBinding">
                <security mode="Transport" />
            </binding>
        </basicHttpBinding>
        <mexHttpsBinding>
            <binding name="httpsBinding" />
        </mexHttpsBinding>
    </bindings>

这是一个来自Raffaele Rialdi的代码解决方案(我稍微修改了一下):

代码语言:javascript
复制
/// <summary>
/// Attribute which will add a binding namespace to every endpoint it's used in.
/// </summary>
[AttributeUsage(AttributeTargets.Class)]
public sealed class BindingNamespaceBehaviorAttribute : Attribute, IServiceBehavior
{
    /// <summary>
    /// The binding namespace;
    /// </summary>
    private readonly string bindingNamespace;

    /// <summary>
    /// Initializes a new instance of the <see cref="BindingNamespaceBehaviorAttribute"/> class.
    /// </summary>
    /// <param name="bindingNamespace">The binding namespace.</param>
    public BindingNamespaceBehaviorAttribute(string bindingNamespace)
    {
        this.bindingNamespace = bindingNamespace;
    }

    /// <summary>
    /// Gets the binding namespace.
    /// </summary>
    /// <value>The binding namespace.</value>
    public string BindingNamespace
    {
        get
        {
            return this.bindingNamespace;
        }
    }

    /// <summary>
    /// Provides the ability to pass custom data to binding elements to support the contract implementation.
    /// </summary>
    /// <param name="serviceDescription">The service description of the service.</param>
    /// <param name="serviceHostBase">The host of the service.</param>
    /// <param name="endpoints">The service endpoints.</param>
    /// <param name="bindingParameters">Custom objects to which binding elements have access.</param>
    public void AddBindingParameters(
        ServiceDescription serviceDescription,
        ServiceHostBase serviceHostBase,
        Collection<ServiceEndpoint> endpoints,
        BindingParameterCollection bindingParameters)
    {
    }

    /// <summary>
    /// Provides the ability to change run-time property values or insert custom extension objects such as error
    /// handlers, message or parameter interceptors, security extensions, and other custom extension objects.
    /// </summary>
    /// <param name="serviceDescription">The service description.</param>
    /// <param name="serviceHostBase">The host that is currently being built.</param>
    public void ApplyDispatchBehavior(ServiceDescription serviceDescription, ServiceHostBase serviceHostBase)
    {
    }

    /// <summary>
    /// Provides the ability to inspect the service host and the service description to confirm that the service
    /// can run successfully.
    /// </summary>
    /// <param name="serviceDescription">The service description.</param>
    /// <param name="serviceHostBase">The service host that is currently being constructed.</param>
    public void Validate(ServiceDescription serviceDescription, ServiceHostBase serviceHostBase)
    {
        if (serviceHostBase == null)
        {
            throw new ArgumentNullException("serviceHostBase");
        }

        foreach (var endpoint in serviceHostBase.Description.Endpoints)
        {
            endpoint.Binding.Namespace = this.bindingNamespace;
        }
    }
}

像这样使用:

代码语言:javascript
复制
[ServiceBehavior(Namespace = "http://schemas.vevy.com/Printing")]
[BindingNamespaceBehavior("http://schemas.vevy.com/Printing")]
public class LabelsService : ILabelsService
{
    // ...
}
票数 9
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/4730071

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档