Exemple #1
0
                internal XmlMembersMapping ImportFaultElement(FaultDescription fault, out XmlQualifiedName elementName)
                {
                    // the number of reflection members is always 1 because there is only one fault detail type
                    XmlReflectionMember[] members = new XmlReflectionMember[1];

                    XmlName faultElementName = fault.ElementName;
                    string  faultNamespace   = fault.Namespace;

                    if (faultElementName == null)
                    {
                        XmlTypeMapping mapping = _parent._importer.ImportTypeMapping(fault.DetailType);
                        faultElementName = new XmlName(mapping.ElementName, false /*isEncoded*/);
                        faultNamespace   = mapping.Namespace;
                        if (faultElementName == null)
                        {
                            throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(string.Format(SRServiceModel.SFxFaultTypeAnonymous, this.Operation.Name, fault.DetailType.FullName)));
                        }
                    }

                    elementName = new XmlQualifiedName(faultElementName.DecodedName, faultNamespace);

                    members[0] = XmlSerializerHelper.GetXmlReflectionMember(null /*memberName*/, faultElementName, faultNamespace, fault.DetailType,
                                                                            null /*additionalAttributesProvider*/, false /*isMultiple*/, false /*isWrapped*/);

                    string mappingKey = "fault:" + faultElementName.DecodedName + ":" + faultNamespace;

                    return(ImportMembersMapping(faultElementName.EncodedName, faultNamespace, members, false /*hasWrapperElement*/, this.IsRpc, mappingKey));
                }
        private static void BuildProxyOperation(OperationDescription operation, ClientRuntime parent)
        {
            ClientOperation child;

            if (operation.Messages.Count == 1)
            {
                child = new ClientOperation(parent, operation.Name, operation.Messages[0].Action);
            }
            else
            {
                child = new ClientOperation(parent, operation.Name, operation.Messages[0].Action,
                                            operation.Messages[1].Action);
            }
            child.TaskMethod   = operation.TaskMethod;
            child.TaskTResult  = operation.TaskTResult;
            child.SyncMethod   = operation.SyncMethod;
            child.BeginMethod  = operation.BeginMethod;
            child.EndMethod    = operation.EndMethod;
            child.IsOneWay     = operation.IsOneWay;
            child.IsInitiating = operation.IsInitiating;
            child.IsSessionOpenNotificationEnabled = operation.IsSessionOpenNotificationEnabled;
            for (int i = 0; i < operation.Faults.Count; i++)
            {
                FaultDescription fault = operation.Faults[i];
                child.FaultContractInfos.Add(new FaultContractInfo(fault.Action, fault.DetailType, fault.ElementName, fault.Namespace, operation.KnownTypes));
            }

            parent.Operations.Add(child);
        }
Exemple #3
0
 public override PolicyAssertionCollection GetFaultBindingAssertions(FaultDescription fault)
 {
     lock (this.faultBindingAssertions)
     {
         if (!this.faultBindingAssertions.ContainsKey(fault))
         {
             this.faultBindingAssertions.Add(fault, new PolicyAssertionCollection());
         }
     }
     return(this.faultBindingAssertions[fault]);
 }
 protected override void OnOpening()
 {
     foreach (ServiceEndpoint endpoint in this.Description.Endpoints)
     {
         foreach (OperationDescription operation in endpoint.Contract.Operations)
         {
             FaultDescription fault = new FaultDescription(ServiceExceptionDetail.FaultAction);
             fault.DetailType = typeof(ServiceExceptionDetail);
             operation.Faults.Add(fault);
         }
     }
     base.OnOpening();
 }
        private XmlQualifiedName ExportFaultElement(FaultDescription fault, System.ServiceModel.Description.XmlSerializerOperationBehavior.Reflector.OperationReflector operationReflector)
        {
            XmlQualifiedName  name;
            XmlMembersMapping xmlMembersMapping = operationReflector.ImportFaultElement(fault, out name);

            if (operationReflector.IsEncoded)
            {
                this.SoapExporter.ExportMembersMapping(xmlMembersMapping);
                return(name);
            }
            this.XmlExporter.ExportMembersMapping(xmlMembersMapping);
            return(name);
        }
Exemple #6
0
        private void ExportFault(FaultDescription fault)
        {
            Message message = new Message {
                Name = this.GetFaultMessageName(fault.Name)
            };
            XmlQualifiedName elementName = this.ExportFaultElement(fault);

            this.contractContext.WsdlPortType.ServiceDescription.Messages.Add(message);
            AddMessagePart(message, "detail", elementName, null);
            OperationFault operationFault = this.contractContext.GetOperationFault(fault);

            WsdlExporter.WSAddressingHelper.AddActionAttribute(fault.Action, operationFault, this.exporter.PolicyVersion);
            operationFault.Message = new XmlQualifiedName(message.Name, message.ServiceDescription.TargetNamespace);
        }
        private void ExportFault(FaultDescription fault, System.ServiceModel.Description.XmlSerializerOperationBehavior.Reflector.OperationReflector operationReflector)
        {
            Message message = new Message {
                Name = base.GetFaultMessageName(fault.Name)
            };
            XmlQualifiedName elementName = this.ExportFaultElement(fault, operationReflector);

            base.contractContext.WsdlPortType.ServiceDescription.Messages.Add(message);
            MessageContractExporter.AddMessagePart(message, "detail", elementName, null);
            OperationFault operationFault = base.contractContext.GetOperationFault(fault);

            WsdlExporter.WSAddressingHelper.AddActionAttribute(fault.Action, operationFault, base.exporter.PolicyVersion);
            operationFault.Message = new XmlQualifiedName(message.Name, message.ServiceDescription.TargetNamespace);
        }
                private void GenerateXmlSerializerFaultContractInfos()
                {
                    SynchronizedCollection <XmlSerializerOperationBehavior.Reflector.XmlSerializerFaultContractInfo> synchronizeds = new SynchronizedCollection <XmlSerializerOperationBehavior.Reflector.XmlSerializerFaultContractInfo>();

                    for (int i = 0; i < this.Operation.Faults.Count; i++)
                    {
                        XmlQualifiedName  name;
                        FaultDescription  fault             = this.Operation.Faults[i];
                        FaultContractInfo faultContractInfo = new FaultContractInfo(fault.Action, fault.DetailType, fault.ElementName, fault.Namespace, this.Operation.KnownTypes);
                        XmlMembersMapping mapping           = this.ImportFaultElement(fault, out name);
                        XmlSerializerOperationBehavior.Reflector.SerializerStub serializerStub = this.parent.generation.AddSerializer(mapping);
                        synchronizeds.Add(new XmlSerializerOperationBehavior.Reflector.XmlSerializerFaultContractInfo(faultContractInfo, serializerStub, name));
                    }
                    this.xmlSerializerFaultContractInfos = synchronizeds;
                }
        private FaultDescription MakeFault(Type detailType)
        {
            string action = detailType.Name;

            DescriptionAttribute description = (DescriptionAttribute)
                Attribute.GetCustomAttribute(detailType, typeof(DescriptionAttribute));

            if (description != null)
                action = description.Description;

            FaultDescription fd = new FaultDescription(action);
            fd.DetailType = detailType;
            fd.Name = detailType.Name;
            return fd;
        }
Exemple #10
0
                private void GenerateXmlSerializerFaultContractInfos()
                {
                    SynchronizedCollection <XmlSerializerFaultContractInfo> faultInfos = new SynchronizedCollection <XmlSerializerFaultContractInfo>();

                    for (int i = 0; i < this.Operation.Faults.Count; i++)
                    {
                        FaultDescription  fault             = this.Operation.Faults[i];
                        FaultContractInfo faultContractInfo = new FaultContractInfo(fault.Action, fault.DetailType, fault.ElementName, fault.Namespace, this.Operation.KnownTypes);

                        XmlQualifiedName  elementName;
                        XmlMembersMapping xmlMembersMapping = this.ImportFaultElement(fault, out elementName);

                        SerializerStub serializerStub = _parent._generation.AddSerializer(xmlMembersMapping);
                        faultInfos.Add(new XmlSerializerFaultContractInfo(faultContractInfo, serializerStub, elementName));
                    }
                    _xmlSerializerFaultContractInfos = faultInfos;
                }
        static void ImportFaultSoapAction(WsdlContractConversionContext contractContext, FaultDescription fault, FaultBinding wsdlFaultBinding)
        {
            string soapAction = SoapHelper.ReadSoapAction(wsdlFaultBinding.OperationBinding);

            if (contractContext != null)
            {
                OperationFault wsdlOperationFault = contractContext.GetOperationFault(fault);
                string wsaAction = WsdlImporter.WSAddressingHelper.FindWsaActionAttribute(wsdlOperationFault);
                if (wsaAction == null && soapAction != null)
                    fault.Action = soapAction;
                //

            }
            else
            {
                //
            }
        }
Exemple #12
0
        private static void BuildDispatchOperation(OperationDescription operation, DispatchRuntime parent)
        {
            string            requestAction = operation.Messages[0].Action;
            DispatchOperation child         = null;

            if (operation.IsOneWay)
            {
                child = new DispatchOperation(parent, operation.Name, requestAction);
            }
            else
            {
                string replyAction = operation.Messages[1].Action;
                child = new DispatchOperation(parent, operation.Name, requestAction, replyAction);
            }

            child.HasNoDisposableParameters = operation.HasNoDisposableParameters;

            child.IsTerminating = operation.IsTerminating;
            child.IsSessionOpenNotificationEnabled = operation.IsSessionOpenNotificationEnabled;
            for (int i = 0; i < operation.Faults.Count; i++)
            {
                FaultDescription fault = operation.Faults[i];
                child.FaultContractInfos.Add(new FaultContractInfo(fault.Action, fault.DetailType, fault.ElementName, fault.Namespace, operation.KnownTypes));
            }

            child.IsInsideTransactedReceiveScope = operation.IsInsideTransactedReceiveScope;

            if (requestAction != MessageHeaders.WildcardAction)
            {
                parent.Operations.Add(child);
            }
            else
            {
                if (parent.HasMatchAllOperation)
                {
                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.SFxMultipleContractStarOperations0));
                }

                parent.UnhandledDispatchOperation = child;
            }
        }
Exemple #13
0
        private XmlQualifiedName ExportFaultElement(FaultDescription fault)
        {
            XmlSchemaType    type;
            XmlQualifiedName rootElementName;
            XmlQualifiedName typeName = this.ExportType(fault.DetailType, fault.Name, this.operation.Name, out type);

            if (System.ServiceModel.Description.XmlName.IsNullOrEmpty(fault.ElementName))
            {
                rootElementName = this.DataContractExporter.GetRootElementName(fault.DetailType);
                if (rootElementName == null)
                {
                    throw System.ServiceModel.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(System.ServiceModel.SR.GetString("SFxFaultTypeAnonymous", new object[] { this.operation.Name, fault.DetailType.FullName })));
                }
            }
            else
            {
                rootElementName = new XmlQualifiedName(fault.ElementName.EncodedName, fault.Namespace);
            }
            this.ExportGlobalElement(rootElementName.Name, rootElementName.Namespace, true, typeName, type, this.exporter.GeneratedXmlSchemas);
            return(rootElementName);
        }
                internal XmlMembersMapping ImportFaultElement(FaultDescription fault, out XmlQualifiedName elementName)
                {
                    XmlReflectionMember[] members = new XmlReflectionMember[1];
                    System.ServiceModel.Description.XmlName name = fault.ElementName;
                    string ns = fault.Namespace;

                    if (name == null)
                    {
                        XmlTypeMapping mapping = this.parent.importer.ImportTypeMapping(fault.DetailType, this.IsEncoded);
                        name = new System.ServiceModel.Description.XmlName(mapping.ElementName, this.IsEncoded);
                        ns   = mapping.Namespace;
                        if (name == null)
                        {
                            throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(System.ServiceModel.SR.GetString("SFxFaultTypeAnonymous", new object[] { this.Operation.Name, fault.DetailType.FullName })));
                        }
                    }
                    elementName = new XmlQualifiedName(name.DecodedName, ns);
                    members[0]  = XmlSerializerHelper.GetXmlReflectionMember(null, name, ns, fault.DetailType, null, false, this.IsEncoded, false);
                    string mappingKey = "fault:" + name.DecodedName + ":" + ns;

                    return(this.ImportMembersMapping(name.EncodedName, ns, members, false, this.IsRpc, mappingKey));
                }
        public void ApplyDispatchBehavior(ServiceDescription serviceDescription, ServiceHostBase serviceHostBase)
        {
            IErrorHandler errorHandler;
            try
            {
                errorHandler = (IErrorHandler)Activator.CreateInstance(ErrorHandlerType);
            }
            catch (MissingMethodException e)
            {
                throw new ArgumentException("Must have a public empty constructor.", e);
            }
            catch (InvalidCastException e)
            {
                throw new ArgumentException("Must implement IErrorHandler.", e);
            }

            foreach (ChannelDispatcherBase channelDispatcherBase in serviceHostBase.ChannelDispatchers)
            {
                ChannelDispatcher channelDispatcher = channelDispatcherBase as ChannelDispatcher;
                channelDispatcher.ErrorHandlers.Add(errorHandler);
            }

            foreach (ServiceEndpoint ep in serviceDescription.Endpoints)
            {
                foreach (OperationDescription opDesc in ep.Contract.Operations)
                {
                    Type t = typeof(GeneralServerFault);
                    string name = t.Name;

                    FaultDescription faultDescription = new FaultDescription(ep.Contract.Namespace + "/" + ep.Contract.Name + "/" + opDesc.Name + name + "Fault");
                    faultDescription.Name = name + "Fault";
                    faultDescription.Namespace = ep.Contract.Namespace;
                    faultDescription.DetailType = t;
                    opDesc.Faults.Add(faultDescription);
                }
            }
        }
        void ExportFault(FaultDescription fault)
        {
            WsdlNS.Message faultMessage = new WsdlNS.Message();
            faultMessage.Name = GetFaultMessageName(fault.Name);

            XmlQualifiedName elementName = ExportFaultElement(fault);
            this.contractContext.WsdlPortType.ServiceDescription.Messages.Add(faultMessage);
            AddMessagePart(faultMessage, "detail", elementName, null);

            // create a wsdl:fault to put inside the wsdl:portType/wsdl:operation
            WsdlNS.OperationFault operationFault = contractContext.GetOperationFault(fault);
            WsdlExporter.WSAddressingHelper.AddActionAttribute(fault.Action, operationFault, this.exporter.PolicyVersion);
            operationFault.Message = new XmlQualifiedName(faultMessage.Name, faultMessage.ServiceDescription.TargetNamespace);
        }
 void ExportFaultBinding(FaultDescription fault, bool isEncoded, WsdlNS.OperationBinding operationBinding)
 {
     SoapHelper.CreateSoapFaultBinding(fault.Name, endpointContext, endpointContext.GetFaultBinding(fault), isEncoded);
 }
        WsdlNS.OperationFault CreateWsdlOperationFault(FaultDescription fault)
        {
            WsdlNS.OperationFault wsdlOperationFault;
            wsdlOperationFault = new WsdlNS.OperationFault();

            // operation fault name must not be empty (FaultDescription checks this)
            wsdlOperationFault.Name = fault.Name;

            // consider factoring this out of wslExporter
            WSAddressingHelper.AddActionAttribute(fault.Action, wsdlOperationFault, this.PolicyVersion);
            return wsdlOperationFault;
        }
 void cacheSerializer(OperationDescription operation, FaultDescription fault)
 {
     // todo: should this include operation known types? If so, what happens if two ops have different known types but same fault?
     _faultTypes.Add(fault.Action, fault.DetailType);
 }
Exemple #20
0
 public abstract PolicyAssertionCollection GetFaultBindingAssertions(FaultDescription fault);
 private XmlQualifiedName ExportFaultElement(FaultDescription fault)
 {
     XmlSchemaType type;
     XmlQualifiedName rootElementName;
     XmlQualifiedName typeName = this.ExportType(fault.DetailType, fault.Name, this.operation.Name, out type);
     if (System.ServiceModel.Description.XmlName.IsNullOrEmpty(fault.ElementName))
     {
         rootElementName = this.DataContractExporter.GetRootElementName(fault.DetailType);
         if (rootElementName == null)
         {
             throw System.ServiceModel.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(System.ServiceModel.SR.GetString("SFxFaultTypeAnonymous", new object[] { this.operation.Name, fault.DetailType.FullName })));
         }
     }
     else
     {
         rootElementName = new XmlQualifiedName(fault.ElementName.EncodedName, fault.Namespace);
     }
     this.ExportGlobalElement(rootElementName.Name, rootElementName.Namespace, true, typeName, type, this.exporter.GeneratedXmlSchemas);
     return rootElementName;
 }
        static SendReply BuildFaultReplies(FaultDescription faultDescription, bool isMessageContract)
        {
            Fx.Assert(faultDescription != null, "fault Description cannot be null");
            if (faultDescription.DetailType == TypeHelper.VoidType || faultDescription.DetailType == null)
            {
                throw FxTrace.Exception.ArgumentNullOrEmpty("FaultDescription.DetailType");
            }

            SendReply faultReply = new SendReply()
            {
                DisplayName = faultDescription.Name + "SendFaultReply",
                Action = faultDescription.Action,
            };

            Type[] substitute = { faultDescription.DetailType };
            Type faultType = typeof(FaultException<>).MakeGenericType(substitute);
            if (isMessageContract)
            {
                faultReply.Content = new SendMessageContent()
                {
                    Message = (InArgument)(InArgument.Create(faultType, ArgumentDirection.In)),
                };
            }
            else
            {
                InArgument argument = (InArgument)(InArgument.Create(faultType, ArgumentDirection.In));
                SendParametersContent faultReplyParameterContent = new SendParametersContent();
                faultReplyParameterContent.Parameters.Add(faultDescription.Name, argument);
                faultReply.Content = faultReplyParameterContent;
            }

            return faultReply;
        }
Exemple #23
0
            private static CodeAttributeDeclaration CreateAttrDecl(OperationContractGenerationContext context, FaultDescription fault)
            {
                CodeTypeReference type = (fault.DetailType != null) ? context.Contract.ServiceContractGenerator.GetCodeTypeReference(fault.DetailType) : fault.DetailTypeReference;

                if ((type == null) || (type == voidTypeReference))
                {
                    return(null);
                }
                CodeAttributeDeclaration declaration = new CodeAttributeDeclaration(context.ServiceContractGenerator.GetCodeTypeReference(typeof(FaultContractAttribute)));

                declaration.Arguments.Add(new CodeAttributeArgument(new CodeTypeOfExpression(type)));
                if (fault.Action != null)
                {
                    declaration.Arguments.Add(new CodeAttributeArgument("Action", new CodePrimitiveExpression(fault.Action)));
                }
                if (fault.HasProtectionLevel)
                {
                    declaration.Arguments.Add(new CodeAttributeArgument("ProtectionLevel", new CodeFieldReferenceExpression(new CodeTypeReferenceExpression(typeof(ProtectionLevel)), fault.ProtectionLevel.ToString())));
                }
                if (!XmlName.IsNullOrEmpty(fault.ElementName))
                {
                    declaration.Arguments.Add(new CodeAttributeArgument("Name", new CodePrimitiveExpression(fault.ElementName.EncodedName)));
                }
                if (fault.Namespace != context.Contract.Contract.Namespace)
                {
                    declaration.Arguments.Add(new CodeAttributeArgument("Namespace", new CodePrimitiveExpression(fault.Namespace)));
                }
                return(declaration);
            }
 public System.Web.Services.Description.FaultBinding GetFaultBinding(FaultDescription fault)
 {
   return default(System.Web.Services.Description.FaultBinding);
 }
Exemple #25
0
 public System.Web.Services.Description.FaultBinding GetFaultBinding(FaultDescription fault)
 {
     return(default(System.Web.Services.Description.FaultBinding));
 }
		public override PolicyAssertionCollection GetFaultBindingAssertions (FaultDescription fault)
		{
			throw new NotImplementedException ();
		}
Exemple #27
0
 public System.Web.Services.Description.OperationFault GetOperationFault(FaultDescription fault)
 {
     return(default(System.Web.Services.Description.OperationFault));
 }
 public override PolicyAssertionCollection GetFaultBindingAssertions(FaultDescription fault)
 {
     return(s_noPolicy);
 }
 public abstract PolicyAssertionCollection GetFaultBindingAssertions(FaultDescription fault);
 public WsdlNS.OperationFault GetOperationFault(FaultDescription fault)
 {
     return this.wsdlOperationFaults[fault];
 }
 public override PolicyAssertionCollection GetFaultBindingAssertions(FaultDescription message)
 {
     return(this.faultBindingAssertions[message]);
 }
 internal void AddFault(FaultDescription faultDescription, WsdlNS.OperationFault wsdlOperationFault)
 {
     this.wsdlOperationFaults.Add(faultDescription, wsdlOperationFault);
     this.faultDescriptions.Add(wsdlOperationFault, faultDescription);
 }
 internal void AddFaultBinding(FaultDescription faultDescription, FaultBinding wsdlFaultBinding)
 {
     this.wsdlFaultBindings.Add(faultDescription, wsdlFaultBinding);
     this.faultDescriptionBindings.Add(wsdlFaultBinding, faultDescription);
 }
 private static void ImportFaultSoapAction(WsdlContractConversionContext contractContext, FaultDescription fault, FaultBinding wsdlFaultBinding)
 {
     string str = SoapHelper.ReadSoapAction(wsdlFaultBinding.OperationBinding);
     if (((contractContext != null) && (WsdlImporter.WSAddressingHelper.FindWsaActionAttribute(contractContext.GetOperationFault(fault)) == null)) && (str != null))
     {
         fault.Action = str;
     }
 }
 internal XmlMembersMapping ImportFaultElement(FaultDescription fault, out XmlQualifiedName elementName)
 {
     XmlReflectionMember[] members = new XmlReflectionMember[1];
     System.ServiceModel.Description.XmlName name = fault.ElementName;
     string ns = fault.Namespace;
     if (name == null)
     {
         XmlTypeMapping mapping = this.parent.importer.ImportTypeMapping(fault.DetailType, this.IsEncoded);
         name = new System.ServiceModel.Description.XmlName(mapping.ElementName, this.IsEncoded);
         ns = mapping.Namespace;
         if (name == null)
         {
             throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(System.ServiceModel.SR.GetString("SFxFaultTypeAnonymous", new object[] { this.Operation.Name, fault.DetailType.FullName })));
         }
     }
     elementName = new XmlQualifiedName(name.DecodedName, ns);
     members[0] = XmlSerializerHelper.GetXmlReflectionMember(null, name, ns, fault.DetailType, null, false, this.IsEncoded, false);
     string mappingKey = "fault:" + name.DecodedName + ":" + ns;
     return this.ImportMembersMapping(name.EncodedName, ns, members, false, this.IsRpc, mappingKey);
 }
 private OperationFault CreateWsdlOperationFault(FaultDescription fault)
 {
     OperationFault wsdlOperationMessage = new OperationFault {
         Name = fault.Name
     };
     WSAddressingHelper.AddActionAttribute(fault.Action, wsdlOperationMessage, base.PolicyVersion);
     return wsdlOperationMessage;
 }
        WsdlNS.FaultBinding CreateWsdlFaultBinding(FaultDescription faultDescription, Binding binding, WsdlNS.OperationBinding wsdlOperationBinding)
        {
            WsdlNS.FaultBinding wsdlFaultBinding = new WsdlNS.FaultBinding();
            wsdlOperationBinding.Faults.Add(wsdlFaultBinding);
            if (faultDescription.Name != null)
                wsdlFaultBinding.Name = faultDescription.Name;

            return wsdlFaultBinding;
        }
		public override PolicyAssertionCollection GetFaultBindingAssertions (FaultDescription fault)
		{
			return binding_assertions;
		}
 XmlQualifiedName ExportFaultElement(FaultDescription fault, XmlSerializerOperationBehavior.Reflector.OperationReflector operationReflector)
 {
     XmlQualifiedName elementName;
     XmlMembersMapping mapping = operationReflector.ImportFaultElement(fault, out elementName);
     if (operationReflector.IsEncoded)
         SoapExporter.ExportMembersMapping(mapping);
     else
         XmlExporter.ExportMembersMapping(mapping);
     return elementName;
 }
Exemple #40
0
 public WsdlNS.FaultBinding GetFaultBinding(FaultDescription fault)
 {
     return(_wsdlFaultBindings[fault]);
 }
 XmlQualifiedName ExportFaultElement(FaultDescription fault)
 {
     XmlSchemaType xsdType;
     XmlQualifiedName typeName = ExportType(fault.DetailType, fault.Name, operation.Name, out xsdType);
     XmlQualifiedName elementName;
     if (XmlName.IsNullOrEmpty(fault.ElementName))
     {
         elementName = DataContractExporter.GetRootElementName(fault.DetailType);
         if (elementName == null)
             throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.GetString(SR.SFxFaultTypeAnonymous, operation.Name, fault.DetailType.FullName)));
     }
     else
         elementName = new XmlQualifiedName(fault.ElementName.EncodedName, fault.Namespace);
     ExportGlobalElement(elementName.Name, elementName.Namespace, true/*isNillable*/, typeName, xsdType, this.exporter.GeneratedXmlSchemas);
     return elementName;
 }
 public static FaultDescription CreateFaultDescription(OperationDescription operation, Type faultType, string overridingAction)
 {
     string name = NamingHelper.TypeName(faultType) + "Fault";
     string action = overridingAction ?? (NamingHelper.GetMessageAction(operation, false) + name);
     FaultDescription description = new FaultDescription(action) {
         Namespace = operation.DeclaringContract.Namespace,
         DetailType = faultType
     };
     description.SetNameOnly(new System.ServiceModel.Description.XmlName(name));
     return description;
 }
Exemple #43
0
        static OperationDescription GetOrCreateOperation(
            ContractDescription cd, MethodInfo mi, MethodInfo serviceMethod,
            OperationContractAttribute oca,
            Type asyncReturnType,
            bool isCallback,
            Type givenServiceType)
        {
            string name = oca.Name ?? (oca.AsyncPattern ? mi.Name.Substring(5) : mi.Name);

            OperationDescription od = cd.Operations.FirstOrDefault(o => o.Name == name && o.InCallbackContract == isCallback);

            if (od == null)
            {
                od          = new OperationDescription(name, cd);
                od.IsOneWay = oca.IsOneWay;
                if (oca.HasProtectionLevel)
                {
                    od.ProtectionLevel = oca.ProtectionLevel;
                }

                if (HasInvalidMessageContract(mi, oca.AsyncPattern))
                {
                    throw new InvalidOperationException(String.Format("The operation {0} contains more than one parameters and one or more of them are marked with MessageContractAttribute, but the attribute must be used within an operation that has only one parameter.", od.Name));
                }

#if !MOONLIGHT
                var xfa = serviceMethod.GetCustomAttribute <XmlSerializerFormatAttribute> (false);
                if (xfa != null)
                {
                    od.Behaviors.Add(new XmlSerializerOperationBehavior(od, xfa));
                }
#endif
                var dfa = serviceMethod.GetCustomAttribute <DataContractFormatAttribute> (false);
                if (dfa != null)
                {
                    od.Behaviors.Add(new DataContractSerializerOperationBehavior(od, dfa));
                }

                od.Messages.Add(GetMessage(od, mi, oca, true, isCallback, null));
                if (!od.IsOneWay)
                {
                    var md = GetMessage(od, mi, oca, false, isCallback, asyncReturnType);
                    od.Messages.Add(md);
                    var mpa = mi.ReturnParameter.GetCustomAttribute <MessageParameterAttribute> (true);
                    if (mpa != null)
                    {
                        var mpd = md.Body.Parts.FirstOrDefault(pd => pd.Name == mpa.Name);
                        if (mpd != null)
                        {
                            md.Body.Parts.Remove(mpd);
                            md.Body.ReturnValue = mpd;
                            mpd.Name            = mpa.Name;
                        }
                        else if (md.Body.ReturnValue == null)
                        {
                            throw new InvalidOperationException(String.Format("Specified message part '{0}' in MessageParameterAttribute on the return value, was not found", mpa.Name));
                        }
                    }
                }
                var knownTypeAtts =
                    cd.ContractType.GetCustomAttributes(typeof(ServiceKnownTypeAttribute), false).Union(
                        mi.GetCustomAttributes(typeof(ServiceKnownTypeAttribute), false)).Union(
                        serviceMethod.GetCustomAttributes(typeof(ServiceKnownTypeAttribute), false));
                foreach (ServiceKnownTypeAttribute a in knownTypeAtts)
                {
                    foreach (Type t in a.GetTypes(givenServiceType))
                    {
                        od.KnownTypes.Add(t);
                    }
                }
                foreach (FaultContractAttribute a in mi.GetCustomAttributes(typeof(FaultContractAttribute), false))
                {
                    var fname = a.Name ?? a.DetailType.Name + "Fault";
                    var fns   = a.Namespace ?? cd.Namespace;
                    var fd    = new FaultDescription(a.Action ?? cd.Namespace + cd.Name + "/" + od.Name + fname)
                    {
                        DetailType = a.DetailType, Name = fname, Namespace = fns
                    };
#if !NET_2_1
                    if (a.HasProtectionLevel)
                    {
                        fd.ProtectionLevel = a.ProtectionLevel;
                    }
#endif
                    od.Faults.Add(fd);
                }
                cd.Operations.Add(od);
            }
            else if ((oca.AsyncPattern && od.BeginMethod != null && od.BeginMethod != mi ||
                      !oca.AsyncPattern && od.SyncMethod != null && od.SyncMethod != mi) && od.InCallbackContract == isCallback)
            {
                throw new InvalidOperationException(String.Format("contract '{1}' cannot have two operations for '{0}' that have the identical names and different set of parameters.", name, cd.Name));
            }

            if (oca.AsyncPattern)
            {
                od.BeginMethod = mi;
            }
            else
            {
                od.SyncMethod = mi;
            }
            od.IsInitiating  = oca.IsInitiating;
            od.IsTerminating = oca.IsTerminating;

            if (mi != serviceMethod)
            {
                foreach (object obj in mi.GetCustomAttributes(typeof(IOperationBehavior), true))
                {
                    od.Behaviors.Add((IOperationBehavior)obj);
                }
            }

            if (serviceMethod != null)
            {
                foreach (object obj in serviceMethod.GetCustomAttributes(typeof(IOperationBehavior), true))
                {
                    od.Behaviors.Add((IOperationBehavior)obj);
                }
            }
#if !NET_2_1
            if (od.Behaviors.Find <OperationBehaviorAttribute>() == null)
            {
                od.Behaviors.Add(new OperationBehaviorAttribute());
            }
#endif
            // FIXME: fill KnownTypes, Behaviors and Faults.

            if (isCallback)
            {
                od.InCallbackContract = true;
            }
            else
            {
                od.InOrdinalContract = true;
            }

            return(od);
        }
 internal void AddFaultBinding(FaultDescription faultDescription, FaultBinding wsdlFaultBinding)
 {
     this.wsdlFaultBindings.Add(faultDescription, wsdlFaultBinding);
     this.faultDescriptionBindings.Add(wsdlFaultBinding, faultDescription);
 }
            static CodeAttributeDeclaration CreateAttrDecl(OperationContractGenerationContext context, FaultDescription fault)
            {
                CodeTypeReference exceptionTypeReference = fault.DetailType != null?context.Contract.ServiceContractGenerator.GetCodeTypeReference(fault.DetailType) : fault.DetailTypeReference;

                if (exceptionTypeReference == null || exceptionTypeReference == voidTypeReference)
                {
                    return(null);
                }
                CodeAttributeDeclaration faultContractAttr = new CodeAttributeDeclaration(context.ServiceContractGenerator.GetCodeTypeReference(typeof(FaultContractAttribute)));

                faultContractAttr.Arguments.Add(new CodeAttributeArgument(new CodeTypeOfExpression(exceptionTypeReference)));
                if (fault.Action != null)
                {
                    faultContractAttr.Arguments.Add(new CodeAttributeArgument("Action", new CodePrimitiveExpression(fault.Action)));
                }
                if (fault.HasProtectionLevel)
                {
                    faultContractAttr.Arguments.Add(new CodeAttributeArgument("ProtectionLevel",
                                                                              new CodeFieldReferenceExpression(
                                                                                  new CodeTypeReferenceExpression(typeof(ProtectionLevel)), fault.ProtectionLevel.ToString())));
                }
                // override name with encoded value specified in wsdl; this only works beacuse
                // our Encoding algorithm will leave alredy encoded names untouched
                if (!XmlName.IsNullOrEmpty(fault.ElementName))
                {
                    faultContractAttr.Arguments.Add(new CodeAttributeArgument("Name", new CodePrimitiveExpression(fault.ElementName.EncodedName)));
                }
                if (fault.Namespace != context.Contract.Contract.Namespace)
                {
                    faultContractAttr.Arguments.Add(new CodeAttributeArgument("Namespace", new CodePrimitiveExpression(fault.Namespace)));
                }
                return(faultContractAttr);
            }
                internal XmlMembersMapping ImportFaultElement(FaultDescription fault, out XmlQualifiedName elementName)
                {
                    // the number of reflection members is always 1 because there is only one fault detail type
                    XmlReflectionMember[] members = new XmlReflectionMember[1];

                    XmlName faultElementName = fault.ElementName;
                    string faultNamespace = fault.Namespace;
                    if (faultElementName == null)
                    {
                        XmlTypeMapping mapping = _parent._importer.ImportTypeMapping(fault.DetailType);
                        faultElementName = new XmlName(mapping.ElementName, false /*isEncoded*/);
                        faultNamespace = mapping.Namespace;
                        if (faultElementName == null)
                            throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.Format(SR.SFxFaultTypeAnonymous, this.Operation.Name, fault.DetailType.FullName)));
                    }

                    elementName = new XmlQualifiedName(faultElementName.DecodedName, faultNamespace);

                    members[0] = XmlSerializerHelper.GetXmlReflectionMember(null /*memberName*/, faultElementName, faultNamespace, fault.DetailType,
                        null /*additionalAttributesProvider*/, false /*isMultiple*/, false /*isWrapped*/);

                    string mappingKey = "fault:" + faultElementName.DecodedName + ":" + faultNamespace;
                    return ImportMembersMapping(faultElementName.EncodedName, faultNamespace, members, false /*hasWrapperElement*/, this.IsRpc, mappingKey);
                }
Exemple #47
0
 public OperationFault GetOperationFault(FaultDescription fault)
 {
     return(this.wsdlOperationFaults[fault]);
 }
			GetFaultBindingAssertions (FaultDescription fault);
Exemple #49
0
 internal void AddFaultBinding(FaultDescription faultDescription, WsdlNS.FaultBinding wsdlFaultBinding)
 {
     _wsdlFaultBindings.Add(faultDescription, wsdlFaultBinding);
     _faultDescriptionBindings.Add(wsdlFaultBinding, faultDescription);
 }
Exemple #50
0
 internal void AddFault(FaultDescription faultDescription, OperationFault wsdlOperationFault)
 {
     this.wsdlOperationFaults.Add(faultDescription, wsdlOperationFault);
     this.faultDescriptions.Add(wsdlOperationFault, faultDescription);
 }
Exemple #51
0
 public override PolicyAssertionCollection GetFaultBindingAssertions(FaultDescription fault)
 {
     throw new NotImplementedException();
 }
Exemple #52
0
 private void ExportFaultBinding(FaultDescription fault, bool isEncoded, OperationBinding operationBinding)
 {
     SoapHelper.CreateSoapFaultBinding(fault.Name, this.endpointContext, this.endpointContext.GetFaultBinding(fault), isEncoded);
 }
 public FaultBinding GetFaultBinding(FaultDescription fault)
 {
     return this.wsdlFaultBindings[fault];
 }
Exemple #54
0
 GetFaultBindingAssertions(FaultDescription fault);
		static OperationDescription GetOrCreateOperation (
			ContractDescription cd, MethodInfo mi, MethodInfo serviceMethod,
			OperationContractAttribute oca,
			Type asyncReturnType,
			bool isCallback)
		{
			string name = oca.Name ?? (oca.AsyncPattern ? mi.Name.Substring (5) : mi.Name);

			OperationDescription od = cd.Operations.FirstOrDefault (o => o.Name == name);
			if (od == null) {
				od = new OperationDescription (name, cd);
				od.IsOneWay = oca.IsOneWay;
				if (oca.HasProtectionLevel)
					od.ProtectionLevel = oca.ProtectionLevel;
				od.Messages.Add (GetMessage (od, mi, oca, true, isCallback, null));
				if (!od.IsOneWay)
					od.Messages.Add (GetMessage (od, mi, oca, false, isCallback, asyncReturnType));
				foreach (ServiceKnownTypeAttribute a in cd.ContractType.GetCustomAttributes (typeof (ServiceKnownTypeAttribute), false))
					foreach (Type t in a.GetTypes ())
						od.KnownTypes.Add (t);
				foreach (ServiceKnownTypeAttribute a in serviceMethod.GetCustomAttributes (typeof (ServiceKnownTypeAttribute), false))
					foreach (Type t in a.GetTypes ())
						od.KnownTypes.Add (t);
				foreach (FaultContractAttribute a in mi.GetCustomAttributes (typeof (FaultContractAttribute), false)) {
					var fname = a.Name ?? a.DetailType.Name + "Fault";
					var fns = a.Namespace ?? cd.Namespace;
					var fd = new FaultDescription (a.Action ?? cd.Namespace + cd.Name + "/" + od.Name + fname) { DetailType = a.DetailType, Name = fname, Namespace = fns };
#if !NET_2_1
					if (a.HasProtectionLevel)
						fd.ProtectionLevel = a.ProtectionLevel;
#endif
					od.Faults.Add (fd);
				}
				cd.Operations.Add (od);
			}
			else if (oca.AsyncPattern && od.BeginMethod != null && od.BeginMethod != mi ||
				 !oca.AsyncPattern && od.SyncMethod != null && od.SyncMethod != mi)
				throw new InvalidOperationException (String.Format ("contract '{1}' cannot have two operations for '{0}' that have the identical names and different set of parameters.", name, cd.Name));

			if (oca.AsyncPattern)
				od.BeginMethod = mi;
			else
				od.SyncMethod = mi;
			od.IsInitiating = oca.IsInitiating;
			od.IsTerminating = oca.IsTerminating;

			if (mi != serviceMethod)
				foreach (object obj in mi.GetCustomAttributes (typeof (IOperationBehavior), true))
					od.Behaviors.Add ((IOperationBehavior) obj);

			if (serviceMethod != null) {
				foreach (object obj in serviceMethod.GetCustomAttributes (typeof(IOperationBehavior),true))
					od.Behaviors.Add ((IOperationBehavior) obj);
			}
#if !NET_2_1
			if (od.Behaviors.Find<OperationBehaviorAttribute>() == null)
				od.Behaviors.Add (new OperationBehaviorAttribute ());
#endif
			// FIXME: fill KnownTypes, Behaviors and Faults.

			if (isCallback)
				od.InCallbackContract = true;
			else
				od.InOrdinalContract = true;

			return od;
		}
 public WsdlNS.OperationFault GetOperationFault(FaultDescription fault)
 {
     return(_wsdlOperationFaults[fault]);
 }
 public override PolicyAssertionCollection GetFaultBindingAssertions(FaultDescription fault)
 {
     lock (this.faultBindingAssertions)
     {
         if (!this.faultBindingAssertions.ContainsKey(fault))
         {
             this.faultBindingAssertions.Add(fault, new PolicyAssertionCollection());
         }
     }
     return this.faultBindingAssertions[fault];
 }
 internal void AddFault(FaultDescription faultDescription, WsdlNS.OperationFault wsdlOperationFault)
 {
     _wsdlOperationFaults.Add(faultDescription, wsdlOperationFault);
     _faultDescriptions.Add(wsdlOperationFault, faultDescription);
 }
 public FaultBinding GetFaultBinding(FaultDescription fault)
 {
     return(this.wsdlFaultBindings[fault]);
 }
 private void ExportFault(FaultDescription fault)
 {
     Message message = new Message {
         Name = this.GetFaultMessageName(fault.Name)
     };
     XmlQualifiedName elementName = this.ExportFaultElement(fault);
     this.contractContext.WsdlPortType.ServiceDescription.Messages.Add(message);
     AddMessagePart(message, "detail", elementName, null);
     OperationFault operationFault = this.contractContext.GetOperationFault(fault);
     WsdlExporter.WSAddressingHelper.AddActionAttribute(fault.Action, operationFault, this.exporter.PolicyVersion);
     operationFault.Message = new XmlQualifiedName(message.Name, message.ServiceDescription.TargetNamespace);
 }