Skip to content

Optionally remove "urn" prefix from wsa:MessageID #975

Open
@bastbnl

Description

@bastbnl

Hi,

I'm trying to connect an application to the Dutch Chamber of Commerce (KvK) dataservice using python 3.7.3 and zeep==3.4.0. This appears to be a bit of a pain.

The wsdl for this service is available via http://schemas.kvk.nl/contracts/kvk/dataservice/catalogus/2015/02/. No problems there yet.

wsa is added automatically, probably due to data found in the wsdl. The wsa headers are added twice when I add the WsAddressingPlugin via the plugins parameter at initialization of the Client instance. I'll try to add a reproducer later on.

There's a requirement in the docs saying the service is unable to process messages that contain a MessageID which is prefixed by urn. I think a lot of developers would be happier when the service would be able to process messages containing that prefix instead of documenting this issue, but that's out of my control. Here's an excerpt in Dutch, but I'm guessing that's not an issue for you ;)

LET OP: sommige IDE tooling zoals bijvoorbeeld Microsoft Visual Studio voegt “urn:” voor “uuid:”. De Handelsregister Dataservice controles zullen een request met deze syntax afwijzen!
(https://www.kvk.nl/sites/aansluitendataservice/index.html#/webservice-werkingsprincipes)

Is there a way to remove the urn prefix from the MessageID? Do I need to override the plugin somewhere?

Activity

bastbnl

bastbnl commented on Jun 12, 2019

@bastbnl
Author

Reproducer for the double wsa headers for python 3:

from lxml import etree

from requests import Session

from zeep import Client, Settings
from zeep.transports import Transport
from zeep.wsa import WsAddressingPlugin


def reproducer_for_double_wsa_headers():
    soap_client_settings = Settings(
        strict=False,
    )
    soap_request_session = Session()
    soap_client = Client(
        'http://schemas.kvk.nl/contracts/kvk/dataservice/catalogus/2015/02/KVK-KvKDataservice.wsdl',
        settings=soap_client_settings,
        transport=Transport(
            timeout=10,
            operation_timeout=10,
            session=soap_request_session,
        ),
        plugins=[
            WsAddressingPlugin(),
        ],
    )
    soap_message = soap_client.create_message(
        soap_client.service,
        'ophalenInschrijving',
        kvkNummer='11111111',
        klantreferentie='github-974', 
    )
    print(
        etree.tostring(
            soap_message,
            pretty_print=True,
            xml_declaration=True,
            encoding='utf-8',
        ).decode()
    )

Expected output:

<?xml version='1.0' encoding='utf-8'?>
<soap-env:Envelope xmlns:soap-env="http://schemas.xmlsoap.org/soap/envelope/">
  <soap-env:Header xmlns:wsa="http://www.w3.org/2005/08/addressing">
    <wsa:Action>http://es.kvk.nl/ophalenInschrijving</wsa:Action>
    <wsa:MessageID>uuid:3165ca25-b3f4-4619-9a50-00fdbb7afa50</wsa:MessageID>
    <wsa:To>https://example.com/</wsa:To>
  </soap-env:Header>
  <soap-env:Body>
    <ns0:ophalenInschrijvingRequest xmlns:ns0="http://schemas.kvk.nl/schemas/hrip/dataservice/2015/02">
      <ns0:klantreferentie>github-974</ns0:klantreferentie>
      <ns0:kvkNummer>11111111</ns0:kvkNummer>
    </ns0:ophalenInschrijvingRequest>
  </soap-env:Body>
</soap-env:Envelope>

Actual output:

<soap-env:Envelope xmlns:soap-env="http://schemas.xmlsoap.org/soap/envelope/">
  <soap-env:Header xmlns:wsa="http://www.w3.org/2005/08/addressing">
    <wsa:Action>http://es.kvk.nl/ophalenInschrijving</wsa:Action>
    <wsa:MessageID>uuid:686ab93e-9715-4719-a839-a1895dcb70ef</wsa:MessageID>
    <wsa:To>https://example.com/</wsa:To>
    <wsa:Action>http://es.kvk.nl/ophalenInschrijving</wsa:Action>
    <wsa:MessageID>uuid:5759ba8f-4ebe-4529-b540-bc4c6175f406</wsa:MessageID>
    <wsa:To>https://example.com/</wsa:To>
  </soap-env:Header>
  <soap-env:Body>
    <ns0:ophalenInschrijvingRequest xmlns:ns0="http://schemas.kvk.nl/schemas/hrip/dataservice/2015/02">
      <ns0:klantreferentie>github-974</ns0:klantreferentie>
      <ns0:kvkNummer>11111111</ns0:kvkNummer>
    </ns0:ophalenInschrijvingRequest>
  </soap-env:Body>
</soap-env:Envelope>
bastbnl

bastbnl commented on Jun 12, 2019

@bastbnl
Author

It gets a bit more confusing when you attempt to override via _soapheaders and use the plugins. You'll end up with additional headers found in _soapheaders.

renevdkooi

renevdkooi commented on Aug 3, 2019

@renevdkooi

@bastbnl were you able to fix this at any point? I'm trying to connect to the same service, but I'm not even getting a response form the service.

bastbnl

bastbnl commented on Aug 3, 2019

@bastbnl
Author

@renevdkooi I'm able to connect to the preprod environment and retrieve data, but not using zeep. Happy to discuss how I did it.

renevdkooi

renevdkooi commented on Aug 3, 2019

@renevdkooi

Would love to see how you did it or put me in the right direction. I tried with PHP, but got nothing working. So I tried moving to python and using this ZEEP, but don't seem to get any data.

Any way to contact you?

bastbnl

bastbnl commented on Aug 3, 2019

@bastbnl
Author

Sure, contact me via bastbnl@pm.me. It'll take me some time to respond though.

zeyadmbk

zeyadmbk commented on Mar 19, 2020

@zeyadmbk

Hi @bastbnl I'm working on a project that involves KvK dataservices and I'm using PHP. Although I'm able to connect but I'm struggling to retrieve any data and I always get "Not Authorized". I was able to get the data using SoapUI but not with PHP. So, I was thinking to use another language like Python and after researching I stumbled upon this post. So I'm wondering how were you able to solve this.

renevdkooi

renevdkooi commented on Mar 19, 2020

@renevdkooi

I was actually able to get this to work under php. It was easier than I thought. You can use normal soap requests, but you need to play with the security.

zeyadmbk

zeyadmbk commented on Mar 19, 2020

@zeyadmbk

@renevdkooi Thanks a lot for your feedback. I agree I reached out to KvK support and they said it something has to do with security and message signing but they cannot see any issue with the SOAP XML. Unfortunately they cannot help further with PHP. I've been playing around for days with the security but without any success. Would it possible if you can share some code sample that worked for you?

bastbnl

bastbnl commented on Mar 19, 2020

@bastbnl
Author

@zeyadmbk just letting you know I didn't use PHP, so I'm afraid I can't help with PHP code. I used the requests module to send the message because I was unable to find a way to provide the CSA using zeep.

Make sure you're signing Body, To, MessageID, Action and Timestamp in the message you're sending. Also make sure you're using http://www.w3.org/2005/08/addressing and not a newer version.

renevdkooi

renevdkooi commented on Mar 20, 2020

@renevdkooi

@zeyadmbk You can contact me at renevdkooi@hotmail.com

added a commit that references this issue on Dec 8, 2022
5fa24f3
Merinorus

Merinorus commented on Dec 8, 2022

@Merinorus

Hi,
I encountered the same problem. Will make a PR on this one! Feel free to review it.

added a commit that references this issue on Dec 9, 2022
1155d5b
gk965

gk965 commented on Mar 6, 2024

@gk965

Hi, this was already a while ago but I am trying to test the KvK dataservice using Postman and running into the authorization issue. A couple people in this thread mentioned they managed to figure it out so is it possible for me to contact someone to get some help?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      Participants

      @renevdkooi@zeyadmbk@Merinorus@bastbnl@gk965

      Issue actions

        Optionally remove "urn" prefix from wsa:MessageID · Issue #975 · mvantellingen/python-zeep