How to get rid of tempuri.org in a WCF service created by SharePoint Factory

I am showing a WCF service in SharePoint 2010 using the Service Factory class and cannot completely get rid of the tempuri.org namespace in the generated WSDL.

That's what I'm doing:

Svc file in ISAPI folder

<%@ServiceHost
    Language="C#"
    Factory="Microsoft.SharePoint.Client.Services.MultipleBaseAddressBasicHttpBindingServiceHostFactory, Microsoft.SharePoint.Client.ServerRuntime, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c"
    Service="MyService, [...]"   
%>

Service agreement

using System.ServiceModel;

    namespace MyService
    {
        [ServiceContract(Namespace="http://myname.com")]
        interface IMyService
        {
            [OperationContract]
            string GetSomeDefinition();
        }
    }

Service implementation

using System;
using System.ServiceModel;
using System.ServiceModel.Activation;
using Microsoft.SharePoint.Client.Services;

    namespace MyService
    {
        [ServiceBehavior(Namespace = "http://myname.com")]
        [BasicHttpBindingServiceMetadataExchangeEndpointAttribute]
        [AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Required)]
        class MyService : IMyService
        {
            public string GetSomeDefinition()
            {
                // do some stuff...
                return result;
            }
        }
    }

Wsdl

<wsdl:definitions name="MyService" targetNamespace="http://myname.com" [...]>
  <wsdl:import namespace="http://tempuri.org/" location="http://localhost/_vti_bin/myservice.svc/mex?wsdl=wsdl0" /> 
  [...]
</wsdl:definitions>

, WSDL . http://myname.com http://tempuri.org. , bindingNamespace . Factory, . web.config : http://localhost/...

Web.config

  <system.serviceModel>
    <services>
      <service name="MyService.MyService">
        <endpoint address="http://localhost/_vti_bin/myservice.svc" binding="basicHttpBinding" contract="MyService.IMyService" bindingNamespace="http://myname.com" />
      </service>
    </services>
  </system.serviceModel>

2010-10-07 : MultipleBaseAddressBasicHttpBindingServiceHostFactory ServiceHost. , .

+3
2

, , , tempuri.org :

  • ServiceContract ( )
  • ServiceBehavior ( )
  • bindingNamespace < endpoint/ > .

    - larsw

+2

blogpost Cameron Verhelst: http://cameron-verhelst.be/blog/2014/10/19/hosting-a-wcf-service-in-sharepoint-with-a-spcontext/ ( ! )

, WSDL , .

factory svc.

:

CustomMultipleBaseAddressBasicHttpBindingServiceHostFactory.cs

using System;
using System.ServiceModel;
using Microsoft.SharePoint.Client.Services;

public class CustomMultipleBaseAddressBasicHttpBindingServiceHostFactory : MultipleBaseAddressBasicHttpBindingServiceHostFactory
{
    protected override ServiceHost CreateServiceHost(Type serviceType, Uri[] baseAddresses)
    {
        return new CustomMultipleBaseAddressBasicHttpBindingServiceHost(serviceType, baseAddresses);
    }
}

CustomMultipleBaseAddressBasicHttpBindingServiceHostFactory.cs

using System;
using System.Linq;
using System.ServiceModel.Description;
using Microsoft.SharePoint.Client.Services;

public class CustomMultipleBaseAddressBasicHttpBindingServiceHost : MultipleBaseAddressBasicHttpBindingServiceHost
{
    public CustomMultipleBaseAddressBasicHttpBindingServiceHost(Type serviceType, params Uri[] baseAddresses)
        : base(serviceType, baseAddresses)
    {
    }

    protected override void OnOpening()
    {
        base.OnOpening();

        string targetNamespace = ImplementedContracts.First().Value.Namespace;

        foreach (ServiceEndpoint endpoint in Description.Endpoints)
        {
            endpoint.Binding.Namespace = targetNamespace;
        }
    }
}

.

0

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


All Articles