Example #1
0
        public bool SendMessage(string uri, string action, string request, ref string response)
        {
            bool res = false;

            if (action == null)
            {
                return(res);
            }
            if (uri == null || uri.Length < 1)
            {
                return(res);
            }
            if (request == null || request.Length < 1)
            {
                return(res);
            }

            string soapInfo = string.Format("sending SOAP message to uri: {0} with action: {1}", uri, action);

            _log.Write("Begin " + soapInfo);

            try
            {
                //using (ChannelFactory<IAbstractContract> factory = new ChannelFactory<IAbstractContract>("ABSTRACT_CLIENT_ENDPOINT"))
                using (ConfigurableChannelFactory <IAbstractContract> factory = new ConfigurableChannelFactory <IAbstractContract>(_configFile))
                {
                    IAbstractContract proxy = factory.CreateChannel(new EndpointAddress(uri));
                    using (proxy as IDisposable)
                    {
                        using (OperationContextScope sc = new OperationContextScope(proxy as IContextChannel))
                        {
                            using (Message wcfRequest = SoapMessageHelper.CreateEmptyWCFMessage(
                                       SoapEnvelopeVersion.Soap11,
                                       WSAddressingVersion.None,
                                       action))
                            {
                                OperationContext.Current.OutgoingMessageProperties.Add(SwaEncoderConstants.SoapEnvelopeProperty, request);
                                using (Message wcfResponse = proxy.SendMessage(wcfRequest))
                                {
                                    response = SoapMessageHelper.DumpWCFMessage(wcfResponse);
                                    res      = true;
                                }
                            }
                        }
                    }
                }
            }
            catch (Exception err)
            {
                if (_log != null)
                {
                    _log.Write(err);
                }
                res = false;
            }

            _log.Write(string.Format("End {0}. Result: {1}", soapInfo, res));
            return(res);
        }
Example #2
0
        private void buttonMsgCall_Click(object sender, EventArgs e)
        {
            string uri     = this.textBoxMsgURI.Text.Trim();
            string action  = this.textBoxMsgAction.Text.Trim();
            string request = this.textBoxMsgSnd.Text.Trim();

            System.ServiceModel.Channels.Message wcfRequest  = null;
            System.ServiceModel.Channels.Message wcfResponse = null;

            try
            {
                ChannelFactory <IAbstractContract> factory = new ChannelFactory <IAbstractContract>("ABSTRACT_CLIENT_ENDPOINT");

                IAbstractContract proxy = factory.CreateChannel(new EndpointAddress(uri));
                using (proxy as IDisposable)
                {
                    using (OperationContextScope sc = new OperationContextScope(proxy as IContextChannel))
                    {
                        using (wcfRequest = SoapMessageHelper.CreateEmptyWCFMessage(
                                   SoapEnvelopeVersion.Soap11,
                                   WSAddressingVersion.None,
                                   action))
                        {
                            //List<SwaAttachment> attachmentList = new List<SwaAttachment>();
                            //OperationContext.Current.OutgoingMessageProperties.Add(SwaEncoderConstants.AttachmentProperty, attachmentList);
                            OperationContext.Current.OutgoingMessageProperties.Add(SwaEncoderConstants.SoapEnvelopeProperty, request);
                            wcfResponse = proxy.SendMessage(wcfRequest);
                        }
                    }
                }

                if (wcfResponse != null)
                {
                    string response = SoapMessageHelper.DumpWCFMessage(wcfResponse);
                    wcfResponse.Close();
                    this.textBoxMsgRcv.Text = response;
                }
            }
            catch (Exception err)
            {
                MessageBox.Show(this, err.ToString(), this.Text);
            }
        }