Microsoft MVP성태의 닷넷 이야기
웹서비스 WSDL 생성및 프록시 클래스 생성 관련 질문입니다. [링크 복사], [링크+제목 복사]
조회: 12216
글쓴 사람
초이
홈페이지
첨부 파일
 
(연관된 글이 1개 있습니다.)

안녕하세요 닷넷을 하면서 홈페이지 많이참고 하고 있습니다. ^^
감사합니다.

질문에 예제도 아직 작업중인 부분이라 정리가 좀 안되고 긴점 양해 부탁드립니다.
현재 웹서비스 (asmx) 기반으로 메세지 암호화 를 구현하였는데요.
아주 예전에 올려놓으신

https://www.sysnet.pe.kr/2/0/453
서버측 SoapExtension을 클라이언트에 알리고 싶다.

를 참고하여 제가 구현한 SoapExtension 클래스에서 사용하는 내용을 클라이언트 프록시 클래스에서도 나타내게끔 하려고합니다. (SoapExtensionImporter 활용 )
일단 웹서비스의 Input output 은 암호화된 스트링이 넘어 오므로, 해당 스트링의 암호화 / 복호화를 거쳐 ParamEncryptionExtension 에서 처리는 완료 하였습니다.
샘플 웹서비스 메소드는 다음과 같구요.

  [SoapHeader("myEncryptHeader", Direction = SoapHeaderDirection.In)]
  [ParamEncryptionExtension(EncryptParamNames = new string[] { "Test_Output" },
                       LogRequestResponse = true,
                       SerializeType = typeof(Protocol.Test_Output))]

 public XmlNode TestEncrypt(XmlNode input)
 {

input 에는 복호화된 xml 스트링이 넘어오고 ( 클라이언트는 암호화된 스트링을 보냄 ( 원본은 xml string ) )
해당 xml 스트링을 deserilaize 해서 구조체를 만들어 사용합니다.
마찬가지로 웹메소드 안에서 결과값인 특정 구조체를 serialize 해서 xmlnode 로 넘기면 ParamEncryptionExtension 에서 암호화 하여 스트링을 클라이언트 한테 넘겨주고요.

문제는 wsdl.exe 툴 로 생성된 프록시 클래스에서 해당 함수가 XmlNode 지만 어떤 xml type 으로 보내라.. 혹은 어떤 xml type 이 리턴된다 라는걸 알려주고싶은데,
웹서비스 wsdl 문서에서는 다음과 같이 any 타입으로만 표시가 되니 ( 당연한거지만요.. )
클라이언트는 수동으로 xml 을 만들어 보내줘야 하는 상황입니다.

<wsdl:types>
- <s:schema elementFormDefault="qualified" targetNamespace="http://localhost/">
- <s:element name="TestEncrypt">
- <s:complexType>
- <s:sequence>
- <s:element minOccurs="0" maxOccurs="1" name="input">
- <s:complexType mixed="true">
- <s:sequence>
  <s:any />
  </s:sequence>
  </s:complexType>
  </s:element>
  </s:sequence>
  </s:complexType>
  </s:element>

wsdl 파일 에 특정 구조체를 포함시켜주기 위해 (여기서는 TestEncrypt 메소드의 output 형식 )
다음과 같이 클래스를 선언하고,

    [XmlRootAttribute]
    public class TestOutput
    {
        [XmlElement]
        public string o_session_id;
        [XmlElement]
        public int nResult;
    }

SoapExtensionReflector 에서 다음과 같이 작성해주었더니,
 
      XmlTypeMapping mapping = ReflectionContext.ReflectionImporter.ImportTypeMapping(typeof(TestOutput));
      ReflectionContext.SchemaExporter.ExportTypeMapping(mapping);
           
      ParamEncryptionExtensionAttribute attr = (ParamEncryptionExtensionAttribute)attrs[0];

      ParamEncryptionOperationBinding operationBinding = new ParamEncryptionOperationBinding();
      operationBinding.SerializeType = attr.SerializeType.Name;
      operationBinding.Output = true;
 
      ReflectionContext.OperationBinding.Extensions.Add(operationBinding);

wsdl 파일의 types 에 제가 노출시키려던 Test_Output 이 다음과 같이 표시 되주고요,
전에 강좌에서 올려놓으셨던, operation 섹션에 OperationBinding 도 표시가 잘 됩니다.

<wsdl:types>
- <s:schema elementFormDefault="qualified" targetNamespace="http://localhost/">
   ... 생략 ...
- <s:complexType name="TestOutput">
- <s:sequence>
  <s:element minOccurs="0" maxOccurs="1" name="o_session_id" type="s:string" />
  <s:element minOccurs="1" maxOccurs="1" name="nResult" type="s:int" />
  </s:sequence>
  </s:complexType>
  </s:schema>
   ... 생략 ....
 </wsdl:types>


- <wsdl:operation name="TestEncrypt">
  <soap12:operation soapAction="http://localhost/TestEncrypt" style="document" />
  <enc:encryption Input="true" Output="true" SerializeType="Test_Output" />
- <wsdl:input>
  <soap12:body use="literal" />
  <soap12:header message="tns:TestEncryptTestSoapHeader" part="TestSoapHeader" use="literal" />
  </wsdl:input>
- <wsdl:output>
  <soap12:body use="literal" />
  </wsdl:output>
  </wsdl:operation>

하지만 이부분도 wsdl.exe 로 프록시 클래스를 생성하면

/// <remarks/>
// CODEGEN: 네임스페이스 'http://localhost"에서 선택적 WSDL 확장 요소 'encryption'이(가) 처리되지 않았습니다.
[System.CodeDom.Compiler.GeneratedCodeAttribute("wsdl", "4.0.30319.17929")]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]

SoapExtensionImporter 구현 및 Web.config 에 해당 클래스들은 다 포함하여주었습니다만
위와 같이 warning 만해주고 어트리뷰트는 코드에 생성되지 않구요.
물론 위에서 wsdl types 에 추가되었던 Test_Output 구조체도 프록시 클래스에선 찾아볼수 없습니다.
SoapExtensionImporter 구현은 msdn 을 참고 하여 다음과 같이 구현하였습니다.

public class EncryptionExtensionImporter : SoapExtensionImporter
    {
        public override void ImportMethod(CodeAttributeDeclarationCollection metadata)
        {
            ParamEncryptionOperationBinding myOpBinding = (ParamEncryptionOperationBinding)
                ImportContext.OperationBinding.Extensions.Find(typeof(ParamEncryptionOperationBinding));
            if (myOpBinding != null)
            {
                    CodeAttributeDeclaration attr = new CodeAttributeDeclaration( typeof(ParamEncryptionExtensionAttribute).FullName);
                    attr.Arguments.Add(new CodeAttributeArgument(new CodePrimitiveExpression(true)));
                    metadata.Add(attr);
            }
        }


결론적으로 제가 하고 싶은건 웹메소드의 Input Ouput 이 비록 XmlNode 타입이지만 클라이언트에서
해당 웹메소드의 Input Output 각각 XmlNode 에 어떤 구조체가 serialze 혹은 deserialze 된다 라는것을 알려줌과 동시에
해당 구조체도 wsdl.exe 에 의해서 프록시 클래스에 자동적으로 생생되게 하고 싶습니다.

그렇게 처리할수 있는 방법이 있을까요?
긴글 읽어주셔서 감사드리며 고견 부탁드립니다.


[연관 글]






[최초 등록일: ]
[최종 수정일: 1/4/2014]


비밀번호

댓글 작성자
 



2014-01-07 01시53분
저도 기억이 이젠 가물가물하군요. ^^; 하도 오래 전에 쓴 내용이라서. 일단 보면 서버 측에서는 WSDL에 직렬화 정보를 잘 포함시킨 것 같습니다. 보여주신 내용대로 enc:encryption 노드로 포함이 되었으니 남은 것은 클라이언트 측의 처리인데요. SoapExtensionImporter를 만드셨다고 했는데, 동작이 정상적으로 되는 것을 확인하셨나요? 그 부분이 정상적으로 동작하고 있다면 코드 생성 시에 WSDL의 내용을 읽어서 코드 생성에 참여할 수 있을 텐데요. 질문해 주신 내용은 클라이언트 측 WSDL 소스 코드 생성에 참여하는 것이 제대로 동작하는지만 테스트 해보면, 그 이후는 적절하게 코드 생성을 하면 되니까 보완하기 나름일 것 같습니다.
정성태

... 31  32  33  34  35  36  37  38  [39]  40  41  42  43  44  45  ...
NoWriterDateCnt.TitleFile(s)
4878heyh...8/25/201710044프로세스의 프로세스 찾기(?) [2]
4877강준8/24/20179271SQLite journal_mode=wal 관련하여 질문드립니다. [1]
4876heyh...8/23/20179484프로세스 초기화하기 [1]
4874ho8/22/20179577파일 확장자명을 이용해 파일의 실행 프로그램의 전체 경로를 얻어 올 수 있을까요? [1]
4875ho8/23/201710550    답변글 [답변]: 파일 확장자명을 이용해 파일의 실행 프로그램의 전체 경로를 얻어 올 수 있을까요? [1]
4873kmi8/21/201711354전역 변수를 쓰지 않고 여러 군데에서 같은 변수를 공용하는 방법이 궁금합니다. [4]
4872abcd8/18/201710027프로세스를 초기화 하는 명령어도 있나요? [1]
4871kmi8/17/201711346메모리 부족으로 종료되는 현상의 여러가지 이유가 무엇인지 궁금합니다. [2]
4870heyh...8/14/201710145프로그램 실행시 중복일 때 버튼 색깔 원래대로 돌리기 [1]
4868kmi8/4/20179460string[] 에 Reverse 적용방법 질문해봅니다 [3]
4867heyh...8/4/20178941EventHandler에 관한 [1]
486610년차8/3/20179379dsoframer axframer open시 기존 오픈되어있는 엑셀을 먹어버리는 현상 [1]
4865heyh...7/31/201710947클릭원스로 배포 한 프로젝트가 끝났는지 알 수 있는 방법 [8]
4864초보자7/28/20179947DllIImport질문 드립니다. [1]
4863다연아빠7/23/201710165전역 예외처리에 대해 질문있습니다. [3]
4861라르크7/17/201715420window form 예제 따라하는 중인데 12.3 서비스 응용 프로그램에서 진행이 안됩니다. [3]파일 다운로드1
4859heyh...7/10/201710074다른 환경에서 실행하기 [1]
4858heyh...7/10/20179918Clickonce update에 관한질문입니다. [1]
4857heyh...7/7/201710563제가 여태까지 작성한 보고서입니다. [2]파일 다운로드1
4856heyh...7/6/20179277성태님 다른질문입니다. [4]
4855JP7/6/20179957Dispose 패턴 구현시 Finalize 재정의에 대한 질문드립니다. [2]
4854heyh...7/6/20179405
4853heyh...7/5/20179513성태님이 작성한대로 해봤습니다. [1]파일 다운로드1
4852김레오7/4/201711671서드파티 dll 디버깅에 대해 질문드립니다. [2]
4851김현준7/3/201710786Datagridview VirtualMode 시 GC가 계속 호출되는 현상이 이해가 안갑니다. [2]
4850heyh...7/3/201710539성태님 밑에 질문드렸던 오류입니다. [1]파일 다운로드1
... 31  32  33  34  35  36  37  38  [39]  40  41  42  43  44  45  ...