Модераторы: gambit
  

Поиск:

Ответ в темуСоздание новой темы Создание опроса
> SoapExtension: не работает в коде прокси клиента 
:(
    Опции темы
mixerfixer
Дата 17.12.2013, 15:48 (ссылка) | (нет голосов) Загрузка ... Загрузка ... Быстрая цитата Цитата


Новичок



Профиль
Группа: Участник
Сообщений: 7
Регистрация: 24.2.2011

Репутация: нет
Всего: нет



Коллеги,

У меня классический asmx Web Service который вызывает веб службу поставщика. 
Я создал 2 идентичных soap extension чтобы перехватывать и записывать в базу XML обмен. Один я повесил на Web Method своего сервиса, а второй прописал в коде сгенеренном по wsdl поставщика - сразу перед определением его метода.

Проблема в том, что на вызов из soapUI моего метода soap extension срабатывает чётко, все пишет в базу. А вот на метод поставщика никакой реакции - ни в дебаг поинт не заходит ни отрабатывает.

WSDL поставщика добавляв как add service reference - advanced - add web reference 

Плз, подскажите какие тонкие моменты проверить? Могу показать куски кода по необходимости.

Заранее спасибо!
PM   Вверх
mixerfixer
Дата 17.12.2013, 18:00 (ссылка) | (нет голосов) Загрузка ... Загрузка ... Быстрая цитата Цитата


Новичок



Профиль
Группа: Участник
Сообщений: 7
Регистрация: 24.2.2011

Репутация: нет
Всего: нет



Таки приведу свой код:

 - код обоих soap extension идентичен и равен
Код

public class CLSoapTracer : SoapExtension
    {
        Stream oldStream;
        Stream newStream;
        string filename;
        private NameValueCollection SoapLogging;

        // Save the Stream representing the SOAP request or SOAP response into
        // a local memory buffer.
        public override Stream ChainStream(Stream stream)
        {
            oldStream = stream;
            newStream = new MemoryStream();
            return newStream;
        }

        // When the SOAP extension is accessed for the first time, the XML Web
        // service method it is applied to is accessed to store the file
        // name passed in, using the corresponding SoapExtensionAttribute.   
        public override object GetInitializer(LogicalMethodInfo methodInfo, SoapExtensionAttribute attribute)
        {
            return ((CLTraceExtensionAttribute)attribute).Filename;
        }

        // The SOAP extension was configured to run using a configuration file
        // instead of an attribute applied to a specific Web service
        // method.
        public override object GetInitializer(Type WebServiceType)
        {
            // Return a file name to log the trace information to, based on the
            // type.
            SoapLogging = WebConfigurationManager.GetSection("SoapLogging") as NameValueCollection;
            return SoapLogging["LogFile"];
        }

        // Receive the file name stored by GetInitializer and store it in a
        // member variable for this specific instance.
        public override void Initialize(object initializer)
        {
            filename = (string)initializer;
        }

        //  If the SoapMessageStage is such that the SoapRequest or
        //  SoapResponse is still in the SOAP format to be sent or received,
        //  save it out to a file.
        public override void ProcessMessage(SoapMessage message)
        {
            switch (message.Stage)
            {
                case SoapMessageStage.BeforeSerialize:
                    break;
                case SoapMessageStage.AfterSerialize:
                    WriteOutput(message);
                    break;
                case SoapMessageStage.BeforeDeserialize:
                    WriteInput(message);
                    break;
                case SoapMessageStage.AfterDeserialize:
                    break;
                default:
                    throw new Exception("invalid stage");
            }
        }

        public void WriteOutput(SoapMessage message)
        {
            string soapString = (message is SoapServerMessage) ? "SoapResponse" : "SoapRequest";
            newStream.Position = 0;
            //read to end
            StreamReader XmlContentReader = new StreamReader(newStream);
            DBAdapter DbAdapter = new DBAdapter();
            DbAdapter.LogSoapMessage(XmlContentReader.ReadToEnd(), soapString, "we <-> they");
            //set stream position back to start
            newStream.Position = 0;

            Copy(newStream, oldStream);
        }

        public void WriteInput(SoapMessage message)
        {
            Copy(oldStream, newStream);
            string soapString = (message is SoapServerMessage) ? "SoapRequest" : "SoapResponse";
            newStream.Position = 0;

            StreamReader XmlContentReader = new StreamReader(newStream);
            DBAdapter DbAdapter = new DBAdapter();
            //read to end
            DbAdapter.LogSoapMessage(XmlContentReader.ReadToEnd(), soapString, "we <-> they");
            //set stream position back to start
            newStream.Position = 0;
        }

        void Copy(Stream from, Stream to)
        {
            TextReader reader = new StreamReader(from);
            TextWriter writer = new StreamWriter(to);
            writer.WriteLine(reader.ReadToEnd());
            writer.Flush();
        }
    }

    // Create a SoapExtensionAttribute for the SOAP Extension that can be
    // applied to a Web service method.
    [AttributeUsage(AttributeTargets.Method)]
    public class CLTraceExtensionAttribute : SoapExtensionAttribute
    {
        private NameValueCollection SoapLogging = WebConfigurationManager.GetSection("SoapLogging") as NameValueCollection;
        private string filename = "";
        private int priority;

        public override Type ExtensionType
        {
            get { return typeof(CLSoapTracer); }
        }

        public override int Priority
        {
            get { return priority; }
            set { priority = value; }
        }

        public string Filename
        {
            get
            {
                return SoapLogging["LogFile"]; ;
            }
            set
            {
                filename = value;
            }
        }
    }


- на метод своего сервиса вешаю вот так:
Код

[WebMethod(Description = "sendRequest function", EnableSession = true)]
        [CLTraceExtension]
        public string sendRequest(ReportTypes ReportType, PersonIdentifier Person)


 - на метод поставщика вешаю так (в Reference.cs, там где по wsdl сгенерился код клиента к их службе)

Код

        [System.Web.Services.Protocols.SoapDocumentMethodAttribute("", RequestNamespace="http://some_ns/", ResponseNamespace="http://some_ns/", Use=System.Web.Services.Description.SoapBindingUse.Literal, ParameterStyle=System.Web.Services.Protocols.SoapParameterStyle.Wrapped)]
        [return: System.Xml.Serialization.XmlElementAttribute("return", Form=System.Xml.Schema.XmlSchemaForm.Unqualified)]
        [CLTraceExtension]
        public response findInfo([System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified)] request arg0) {

PM   Вверх
  
Ответ в темуСоздание новой темы Создание опроса
Прежде чем создать тему, посмотрите сюда:
Любитель
Mymik
mr.DUDA

Используйте теги [code=csharp][/code] для подсветки кода. Используйтe чекбокс "транслит" если у Вас нет русских шрифтов.

Если Вам понравилась атмосфера форума, заходите к нам чаще! С уважением, Любитель, Mymik, mr.DUDA.

 
1 Пользователей читают эту тему (1 Гостей и 0 Скрытых Пользователей)
0 Пользователей:
« Предыдущая тема | Разработка под ASP.NET | Следующая тема »


 




[ Время генерации скрипта: 0.0654 ]   [ Использовано запросов: 21 ]   [ GZIP включён ]


Реклама на сайте     Информационное спонсорство

 
По вопросам размещения рекламы пишите на vladimir(sobaka)vingrad.ru
Отказ от ответственности     Powered by Invision Power Board(R) 1.3 © 2003  IPS, Inc.