none
Publishing metadata using code omits wsdl:service RRS feed

  • Question

  • I create a self hosted WCF service and add mex endpoint using code:

            static void Main(string[] args)
            {
                var contractType = typeof(IWSTrust13AsyncContract);
                var serviceType = typeof(MyStsService);
    
                var myBinding = new WSHttpBinding
                {
                    Security =
                    {
                        Mode = SecurityMode.Message,
                        Message = {ClientCredentialType = MessageCredentialType.Windows}
                    }
                };
    
                var baseAddress = new Uri("http://localhost:8222/");
                using (var myServiceHost = new ServiceHost(serviceType, baseAddress))
                {
                    myServiceHost.AddServiceEndpoint(contractType, myBinding, "sts");
    
                    var smb = new ServiceMetadataBehavior
                    {
                        HttpGetEnabled = true,
                        MetadataExporter =
                        {
                            PolicyVersion = PolicyVersion.Policy12
                        }
                    };
                    myServiceHost.Description.Behaviors.Add(smb);
                    myServiceHost.AddServiceEndpoint(ServiceMetadataBehavior.MexContractName,
                        MetadataExchangeBindings.CreateMexHttpBinding(), "mex");
    
                    myServiceHost.Open();
                    Console.WriteLine($"address: {baseAddress}");
                    Console.ReadLine();
                    myServiceHost.Close();
                }
            }
    

    but genereted WSDL doen't contain neither wsdl:binding nor wsdl:service tags. How to make them to be generated?

    The code that get metadata from another application:

        public class WsdlGenerator
        {
            private const string StsIdentity = "http://schemas.microsoft.com/ws/2008/06/identity/securitytokenservice";
            private static string _cachedMetadata;
    
            public string GetMex(string mexUrl)
            {
                if (string.IsNullOrEmpty(_cachedMetadata))
                {
                    var metaTransfer = new MetadataExchangeClient(new Uri(mexUrl), MetadataExchangeClientMode.MetadataExchange)
                    {
                        ResolveMetadataReferences = true
                    };
    
                    var otherDocs = metaTransfer.GetMetadata();
                    var doc = otherDocs.MetadataSections.SingleOrDefault(d => d.Identifier == StsIdentity);
    
                    _cachedMetadata = doc!= null ? GetWsdlData(doc) : string.Empty;
                }
    
                return _cachedMetadata;
            }
    
            private static string GetWsdlData(MetadataSection current)
            {
                var serviceDescription = current.Metadata as ServiceDescription;
                if (current.Dialect == MetadataSection.ServiceDescriptionDialect && serviceDescription != null)
                {
                    return ReadWsdl(serviceDescription);
                }
                return string.Empty;
            }
    
            private static string ReadWsdl(ServiceDescription wsdl)
            {
                var builder = new StringBuilder();
                using (var xmlWriter = XmlWriter.Create(builder))
                {
                    wsdl.Write(xmlWriter);
                }
                return builder.ToString();
            }
    
        }


    Monday, December 5, 2016 3:40 PM

Answers

  • Hi Michael_M_1980,

    I made a test with your code, but I failed to reproduce your issue. I could find wsdl:binding nor wsdl:service tags in the output.

    If you browser the wsdl from web browser by http://localhost:8222/?wsdl, will you get these tags? How did you define IWSTrust13AsyncContract and MyStsService? Is _cachedMetadata null?

    I would suggest you share us your project which could reproduce your issue.

    Best Regards,

    Edward


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    • Marked as answer by Michael_M_1980 Tuesday, December 6, 2016 7:46 AM
    Tuesday, December 6, 2016 2:57 AM

All replies

  • Hi Michael_M_1980,

    I made a test with your code, but I failed to reproduce your issue. I could find wsdl:binding nor wsdl:service tags in the output.

    If you browser the wsdl from web browser by http://localhost:8222/?wsdl, will you get these tags? How did you define IWSTrust13AsyncContract and MyStsService? Is _cachedMetadata null?

    I would suggest you share us your project which could reproduce your issue.

    Best Regards,

    Edward


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    • Marked as answer by Michael_M_1980 Tuesday, December 6, 2016 7:46 AM
    Tuesday, December 6, 2016 2:57 AM
  • yes, you are right I looked in wrong place
    Tuesday, December 6, 2016 4:34 PM