public static void ParseMetadata2(ServiceProviderDto dto, Type t) { MethodInfo[] methods = t.GetMethods(BindingFlags.Public | BindingFlags.Instance); foreach (var method in methods) { var attribute = method.GetCustomAttributes(typeof(OperationContractAttribute)).FirstOrDefault(); if (attribute != null) { var operationAttri = attribute as OperationContractAttribute; var name = operationAttri.Name; var action = operationAttri.Action; var replyAction = operationAttri.ReplyAction; var operationDto = dto.Operations.FirstOrDefault(o => o.OperationName == (name ?? method.Name)); if (operationDto != null) { operationDto.RealName = method.Name; operationDto.Action = action; operationDto.ReplyAction = replyAction; } else { } Console.WriteLine(operationDto.OperationName); } } }
public static List <ServiceProviderDto> ParseMetadata(MetadataSet metadataSet) { List <ServiceProviderDto> list = new List <ServiceProviderDto>(); var wsdlimp = new WsdlImporter(metadataSet); var endpoints = wsdlimp.ImportAllEndpoints(); if (metadataSet.MetadataSections.Count > 0) { foreach (var section in metadataSet.MetadataSections) { var metadata = section.Metadata as System.Web.Services.Description.ServiceDescription; if (metadata != null && metadata.PortTypes.Count > 0) { foreach (System.Web.Services.Description.PortType portType in metadata.PortTypes) { //var endpoint = endpoints.First(a => a.Name == portType.Name); var endpoint = endpoints.FirstOrDefault(); if (portType.Operations.Count > 0) { foreach (System.Web.Services.Description.Operation operation in portType.Operations) { ServiceProviderDto dto = list.SingleOrDefault(o => o.InterfaceName == operation.PortType.Name); //WsdlOperationMessage operationMessage = new WsdlOperationMessage(); //operationMessage.ActionName = operation.Name; if (dto != null) { dto.Operations.Add(new ServiceOperationDto() { OperationName = operation.Name, //SoapAction = metadata.TargetNamespace + "/" + portType.Name + "/" + operation.Name, SoapAction = operation.Messages.Input.ExtensibleAttributes.FirstOrDefault(x => x.LocalName == "Action").Value, SoapReplyAction = operation.Messages.Output.ExtensibleAttributes.FirstOrDefault(x => x.LocalName == "Action").Value, }); } else { dto = new ServiceProviderDto() { InterfaceName = operation.PortType.Name, ServiceAddress = endpoint?.Address.Uri.ToString() }; dto.Operations = new List <ServiceOperationDto>(); dto.Operations.Add(new ServiceOperationDto() { OperationName = operation.Name, SoapAction = operation.Messages.Input.ExtensibleAttributes.FirstOrDefault(x => x.LocalName == "Action").Value, SoapReplyAction = operation.Messages.Output.ExtensibleAttributes.FirstOrDefault(x => x.LocalName == "Action").Value, }); list.Add(dto); } } } } } } } return(list); }