WCF4 hosting in IIS, WSDL: bindingNamespace is never read

When trying to remove the "tempuri" links from the wsdl file. I followed all the existing tips that I can think of. Add

[ServiceBehavior(Namespace="mynamespace")] 

for implementation class add

[ServiceContract(Namespace="mynamespace")]

to the contract interface and change the "bindingNamespace" attribute for the endpoint in the web.config file. But on boot (in IIS), the namespace never changes. Its ALWAYS tempuri.

Does anyone have any other thoughts on fixing this problem? The following is a sample from the web configuration ... the associated_name is never, no matter what I do, updated to be mynamespace, its always tempuri.org. If after loading the endpoints through the factory host, I repeat the bindings in the host description and update them, they will change, but this seems like a hack.

for the service at: "http://mydomain.com/MyService.svc" the following represents my endpoint configuration, can it even be used by IIS?

<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>

Relavent fragments of the generated WSDL file that still link to tempuri.org

  <wsdl:import namespace="http://tempuri.org/" location="http://mydomain.org/MyService.svc?wsdl=wsdl0" />

........

  <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>

in wsdl: the definition of the node namespace xml i0 (as indicated in the service above) is also set to tempuri.org, so the need for an import statement is needed. There is no change in using temprui if I use BasicHttpBinding or wsHttpBinding. In fact, setting the binding to wsHttpBinding in the web.config file still leads to the output above, referring to BasicHttpBinding_IdirectoryServices.

Thank!

+3
source share
1 answer

: https://connect.microsoft.com/wcf/feedback/details/583163/endpoint-bindingnamespace?wa=wsignin1.0

web.config. , HTTPS, YMMV , :

    <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 ( ):

/// <summary>
/// Attribute which will add a binding namespace to every endpoint it 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;
        }
    }
}

:

[ServiceBehavior(Namespace = "http://schemas.vevy.com/Printing")]
[BindingNamespaceBehavior("http://schemas.vevy.com/Printing")]
public class LabelsService : ILabelsService
{
    // ...
}
+9

Source: https://habr.com/ru/post/1786263/


All Articles