복붙노트

[PYTHON] WCF와 파이썬

PYTHON

WCF와 파이썬

Windows Communication Foundation (WCF) 서비스를 호출 할 수있는 cpython (IronPython 아님) 클라이언트의 예제 코드가 있습니까?

해결법

  1. ==============================

    1.WCF는 통신 프로토콜을 통해 기능을 노출해야합니다. 아마도 가장 일반적으로 사용되는 프로토콜은 HTTP를 통한 SOAP 일 것입니다. 그걸 가정 해 봅시다. 그때 당신이 사용하고있는 것.

    WCF는 통신 프로토콜을 통해 기능을 노출해야합니다. 아마도 가장 일반적으로 사용되는 프로토콜은 HTTP를 통한 SOAP 일 것입니다. 그걸 가정 해 봅시다. 그때 당신이 사용하고있는 것.

    Python으로 다이브 (Dive Into Python)에서이 장을 살펴보십시오. 방법을 보여줄 것입니다. SOAP 호출을합니다.

    통신에 관계없이 파이썬에서 WCF 서비스를 호출하는 통일 된 방법이 없다는 것을 알고 있습니다. 실험 계획안.

  2. ==============================

    2.나는 비눗물을 사용했다.

    나는 비눗물을 사용했다.

    from suds.client import Client
    
    print "Connecting to Service..."
    wsdl = "http://serviceurl.com/service.svc?WSDL"
    client = Client(wsdl)
    result = client.service.Method(variable1, variable2)
    print result
    

    그것은 당신을 시작해야합니다. WCF 및 RESTful 레이어의 노출 된 서비스에 연결할 수 있습니다. 특히 네임 스페이스에 바인딩해야하는 경우 필요한 것을 수행하는 데 필요한 데이터 마스킹이 필요합니다.

  3. ==============================

    3.TL : DR : wsHttpBinding (SOAP 1.2)에서는 zeep을 사용합니다.

    TL : DR : wsHttpBinding (SOAP 1.2)에서는 zeep을 사용합니다.

    WCF 및 wsHttpBinding (SOAP 1.2)을 사용하여 누군가 suds (또는 suds-jurko와 관련하여)를 사용하는 데 문제가있는 경우

  4. ==============================

    4.WS-Addressing으로 WCF SOAP 1.2 서비스에 누군가가 접근 할 수 있도록 도와주세요. 주요 문제는 모든 메시지에 작업 이름을 삽입하는 것입니다.

    WS-Addressing으로 WCF SOAP 1.2 서비스에 누군가가 접근 할 수 있도록 도와주세요. 주요 문제는 모든 메시지에 작업 이름을 삽입하는 것입니다.

    파이썬 3 및 suds 포트 https://bitbucket.org/jurko/suds에 대한 예제입니다.

    예제에서는 HTTP 헤더를 기반으로하는 사용자 정의 인증을 사용합니다. 그대로 두겠습니다.

    TODO : WSDL에서 api_direct_url을 자동으로 가져옵니다 (지금은 하드 코딩되어 있습니다).

    from suds.plugin import MessagePlugin
    from suds.sax.text import Text
    from suds.wsse import Security, UsernameToken
    from suds.sax.element import Element
    from suds.sax.attribute import Attribute
    from suds.xsd.sxbasic import Import
    
    api_username = 'some'
    api_password = 'none'
    
    class api(object):
        api_direct_url = 'some/mex'
        api_url = 'some.svc?singleWsdl|Wsdl'
    
        NS_WSA = ('wsa', 'http://www.w3.org/2005/08/addressing')
    
        _client_instance = None
        @property
        def client(self):
            if self._client_instance:
                return self._client_instance
            from suds.bindings import binding
            binding.envns = ('SOAP-ENV', 'http://www.w3.org/2003/05/soap-envelope')
    
            api_inst = self
            class _WSAPlugin(MessagePlugin):
                def marshalled(self, context):
                    api_inst._marshalled_message(context)
    
            self._client_instance = Client(self.api_url,
                                 plugins=[_WSAPlugin()],
                                 headers={'Content-Type': 'application/soap+xml',
                                          'login':api_username,
                                          'password': api_password}
                                 )
            headers = []
            headers.append(Element('To', ns=self.NS_WSA).setText(self.api_direct_url))
            headers.append(Element('Action', ns=self.NS_WSA).setText('Blank'))
            self._client_instance.set_options(soapheaders=headers)
    
            cache = self._client_instance.options.cache
            cache.setduration(days=10)
            return self._client_instance
    
        def _marshalled_message(self, context):
            def _children(r):
                if hasattr(r, 'children'):
                    for c in r.children:
                        yield from _children(c)
                        yield c
            for el in _children(context.envelope):
                if el.name == 'Action':
                    el.text = Text(self._current_action)
                    return
    
        _current_action = None
        def _invoke(self, method, *args):
            try:
                self._current_action = method.method.soap.action.strip('"')
                return method(*args)
            finally:
                self._current_action = None
    
        def GetRequestTypes(self):
            return self._invoke(self.client.service.GetRequestTypes)[0]
    
        def GetTemplateByRequestType(self, request_type_id):
            js = self._invoke(self.client.service.GetTemplateByRequestType, request_type_id)
            return json.loads(js)
    
        def GetRequestStatus(self, request_guid):
            return self._invoke(self.client.service.GetRequestStatus, request_guid)
    
        def SendRequest(self, request_type_id, request_json):
            r = json.dumps(request_json, ensure_ascii=False)
            return self._invoke(self.client.service.SendRequest, request_type_id, r)
    
  5. ==============================

    5.직접적인 예제는 모르지만 WCF 서비스가 REST가 가능하다면 POX (Plain Old XML)를 통해 REST 메소드 / etc (서비스가있는 경우)를 통해 액세스 할 수 있습니다. 서비스를 제어하는 ​​경우 REST를 통해 엔드 포인트를 노출 할 수 있습니다.

    직접적인 예제는 모르지만 WCF 서비스가 REST가 가능하다면 POX (Plain Old XML)를 통해 REST 메소드 / etc (서비스가있는 경우)를 통해 액세스 할 수 있습니다. 서비스를 제어하는 ​​경우 REST를 통해 엔드 포인트를 노출 할 수 있습니다.

  6. ==============================

    6.tcp를 통한 바이너리 직렬화 통신이 필요하다면 Thrift와 같은 솔루션 구현을 고려해보십시오.

    tcp를 통한 바이너리 직렬화 통신이 필요하다면 Thrift와 같은 솔루션 구현을 고려해보십시오.

  7. ==============================

    7.파이썬에서 WCF를 호출하는 구체적인 예가 없다고해도 WCF를 사용하여 완전한 SOAP 호환 서비스를 만들 수 있어야합니다. 그렇다면 파이썬에서 일반적인 SOAP 서비스를 호출하는 방법에 대한 몇 가지 예를 찾아야한다.

    파이썬에서 WCF를 호출하는 구체적인 예가 없다고해도 WCF를 사용하여 완전한 SOAP 호환 서비스를 만들 수 있어야합니다. 그렇다면 파이썬에서 일반적인 SOAP 서비스를 호출하는 방법에 대한 몇 가지 예를 찾아야한다.

    가장 간단한 방법은 WCF에서 BasicHttpBinding을 사용하고 각 요청 및 응답과 함께 세션 토큰을 전달하여 자신의 세션을 지원할 수 있습니다.

  8. from https://stackoverflow.com/questions/276184/wcf-and-python by cc-by-sa and MIT license