Microsoft MVP성태의 닷넷 이야기
WCF 질문드립니다. [링크 복사], [링크+제목 복사],
조회: 17232
글쓴 사람
이카루스 (iccaruss2 at hotmail.com)
홈페이지
첨부 파일
 

 WCF를 사용하여 SOAP 바디에 XML을 기술하여 메시지를 주고받고 있습니다..

 

원격 호출이 아닌 문서전송으로 모두 해결해야 합니다.

 

클라이언트가 전송을하고, 그에대한 응답메시지를 받게됩니다.

 

메시지를 보내서 재대로 메시지가 왔는지 출력을 해보았을때 메시지는 잘 오는걸 확인했습니다만.. SOAP 바디에 있는 XML을 파싱하는

 

방법을 모르겠군요.. 단기간내에 완벽히 이해를 못하고 오픈소스를 사용해서인지.. 잘 이해도 안가고 큰일입니다;;

 

일단 제가 짠 소스입니다.

 

 

 

 

[클라이언트]

 

 

    [ServiceContract]

    [XmlSerializerFormat]

    public interface IServiceDescription

    {

       [OperationContract(Action = "http://www.example.org/oceanwatch/ServiceDescriptionRequest", IsOneWay = true)]

        void ServDesc(ServDescReq request);

    }

 

    [MessageContract(IsWrapped=false)]

    public class ServDescReq

    {

        [MessageBodyMember]

        public ServDesc ServDesc;

        public ServDescReq() { }

        public ServDescReq(ServDesc report) { ServDesc = report; }

    }

 

    [XmlSchemaProvider(null, IsAny = true)]

    public class ServDesc : IXmlSerializable

    {

        string _namespace = "http://www.w3c.org/ssdl/ServiceDescriptionResponse";

 

        public ServDesc() { }

 

        public System.Xml.Schema.XmlSchema GetSchema()

        {

            return null;

        }

        public void ReadXml(XmlReader reader)

       {

            throw new Exception("The method or operation is not implemented.");

        }

        public void WriteXml(XmlWriter writer)

        {

            // SOAP 바디에 들어갈 XML, 상황에 따라서 더 복잡한 문서가 들어갈 수도 있습니다.

            writer.WriteStartElement("ssdl", "SSDL", _namespace);

            writer.WriteStartElement("Request", _namespace);

            writer.WriteStartElement("ssdl", "RequestDescription", _namespace);

            writer.WriteEndElement();

            writer.WriteEndElement();

        }

    }

 

위의 소스로 메시지를 생성하구요...

 

          using (ChannelFactory<IServiceDescription> channelNotification = new ChannelFactory<IServiceDescription>("Connect"))

            {

                channelNotification.Open();

                IServiceDescription manager = channelNotification.CreateChannel();

                ServDescReq request = new ServDescReq(new ServDesc());

 

                Console.ForegroundColor = ConsoleColor.Cyan;

                Console.WriteLine("EventSource에 보낼 ServiceDescription 요청(XML 문서)은 다음과 같습니다.");

                Console.ForegroundColor = ConsoleColor.White;

                Util.ShowMe(request);

                Console.ForegroundColor = ConsoleColor.Cyan;

                Console.WriteLine();

                Console.WriteLine();

                Console.WriteLine("EventSource에 보낼 ServiceDescription 요청(SOAP 문서)은 다음과 같습니다.");

                manager.ServDesc(request);

                Console.ResetColor();

                channelNotification.Close();

            }

위와 같이 서버에 메시지를 전송합니다.

 

 

 

 

 

 

 

 

 

[서버]

 

 

    [ServiceContract]

    [XmlSerializerFormat]

    public interface IServiceDescriptionRequest

    {

        [OperationContract(Action = "http://www.example.org/oceanwatch/ServiceDescriptionRequest", IsOneWay = true)]

        void ServDesc2(Message request);

    }

    public class ServiceDescriptionRequest : IServiceDescriptionRequest

    {

        public void ServDesc2(Message request)

        {

            Console.ForegroundColor = ConsoleColor.Cyan;

            Console.WriteLine("Subscriber에서 보낸 서비스 기술 요청(XML 원문)은 다음과 같습니다.");

            Console.ForegroundColor = ConsoleColor.White;

            Console.WriteLine(request);

            Console.WriteLine();

            Console.ForegroundColor = ConsoleColor.Cyan;

            Console.WriteLine("ServiceDescriptionResponse를 보냅니다. - Press any key to continue");

            Console.ResetColor();

        }

    }

위는 클라이언트의 메시지를 받는 인터페이스 이고요..

 

 

 

                using (ServiceHost serviceHost = new ServiceHost(typeof(ServiceDescriptionRequest)))

                {

                    Console.ForegroundColor = ConsoleColor.Cyan;

                    Console.WriteLine("Waiting Connect...");

                    Console.ResetColor();

                    serviceHost.Open();

                    Console.ReadLine();

                    serviceHost.Close();

                }

 

다음과 같이 호스트를 생성해서 클라이언트의 메시지를 받습니다.

 

 

일단 위 소스로 전송된 메시지를 찍어보면 보낸되로 출력되는것으로보아 작동은 잘 하고있는거 같은대요..

받은 Message 를 어떻게해야 파싱할 수 있는지요...








[최초 등록일: ]
[최종 수정일: 10/10/2007]


비밀번호

댓글 작성자
 



2007-10-05 06시38분
일단, 클라이언트와 서버 간의 OperationContract에 대한 Signature를 달리 가져가도록 결정하시는 것에 대한 책임은 지셔야겠지요. ^^

예제로 보여주신 부분에 대해서는, 2가지 방법이 있습니다.

Message를 파싱한다고 하셨으니, 직접 Message request에서 XmlDataDictionary를 받아서 request.GetReaderAtBodyContents를 이용해 XmlDictionaryReader를 반환받아 직접 파싱하는 방법이 있고요.

또 하나는 request.GetBody를 이용해서 제어하는 방법이 있습니다. GetBody의 경우에는 타입명을 요구하는 Generic 함수인데, 해당 타입과 클라이언트에 요청한 ServDesc 구조만 일치한다면 GetBody 스스로 쉽게 파싱을 하도록 놔둘 수 있습니다. (물론, IXmlSerializable을 이용해서 직접 ReadXml을 할 수도 있습니다.)

사실... OperationContract를 커스텀 하실 정도의 이해를 가지신 분이, 위와 같은 식의 답변을 정말 모르셔서 요구하신 것인지 의문이긴 합니다.

혹시나, 제가 질문에 대한 이해를 잘못한 것이 있다면 다시 한번 질문해 주십시오. ^^
정성태

1  2  3  4  5  6  7  8  9  10  11  [12]  13  14  15  ...
NoWriterDateCnt.TitleFile(s)
5683김민혁7/1/202213608HttpWebRequest POST 전송 관련해서 질문 드립니다. [4]파일 다운로드1
5682김기헌6/20/202212280안녕하세요 서로 다른 스레드에서 동일 인스턴스의 메소드를 호출할때 질문드립니다 [2]
5681미래는투...6/19/202212548VC++ 빌드 관련 문의 (h파일이 바뀌었는데 컴파일을 꼭 하지 않아도 되나요?) [1]
5680Syong6/12/202213659EXE파일에 속성값 추가하는 방법이 있나요? [2]파일 다운로드1
5679차가워6/8/202213068tcpip socket 여러 랜카드 사용 시 연결 문의 [1]
5678차가워6/7/202212979원자적 실행 문의 [3]
5677장성욱6/7/202212755블루투스 포트와 시리얼포트 연결시 에러 [2]
5675차가워5/29/202213795윈도우설정 프로세스사용계획 옵션과 c# 스레드 [1]
5674민우5/29/202214068C++ 의 RTTI, Reflection 으로 객체 멤버변수, 멤버함수 목록 추출 문의 [2]
5673조은현5/25/202214207안녕하세요 선생님! c#에서 TCP/IP의 keep alive 기능의 사용법에 대해서 질문드리고 싶어요! [2]파일 다운로드2
5672game...5/23/202214229안녕하세요 GC를 일시적으로 중단시키는 방법이 있을까요? [5]
5671한예지 donator5/20/202215185델리게이트와 함수포인터 선언 시, 차이점 질문 있습니다. [3]
5670유필재5/20/202215729c#에서 현재프로그램에서 사용한 인터넷사용량 측정이 가능한가요? [3]
5669한예지 donator5/19/202213856이벤트 접근 제한자 질문 있습니다. [2]
5667ocm5/14/202212712c# 콜백 메서드 [2]
5666김호영5/13/202212655c# winform에서 svg 이미지 사용 [1]
5665장성욱5/11/202212393C# 타이머 관련 질문 [5]
5664차가워5/11/202213628아스키로 구성된 바이트를 long으로 변환 문의 [1]
5663김석규5/11/202213267VSTO를 이용해 엑셀데이터를 저장할때, 최종 입력값을 인식하지 못합니다. [2]
5662한예지 donator5/10/202211808혹시 사이트 회원가입은 어떻게 하는 것인가요? [1]
5661한예지 donator5/10/202211476for문 안에 await가 있는 경우 질문드립니다. [3]
5660tky5/10/202212177특정 작업을 멀티스레딩으로 처리 할 경우 어떤 방법이 가장 효율적일까요? [2]
5659한예지 donator5/9/202212421Task, TaskAwaiter 질문 있습니다. [3]
5658한예지 donator5/9/202213735교재 689, 690쪽(async/await) 질문입니다. [5]
5657C#초보5/8/202212268초보 단순 질문 입니다.,ㅠ [1]
5656부탁드립...5/6/20221446332bit dll 을 64bit dll 화 [2]
1  2  3  4  5  6  7  8  9  10  11  [12]  13  14  15  ...