Creating client to call web service without wsdl in c #

I need to connect to a webservice without knowing wsdl; the only information I have is an example request like the one below, but I have no idea where to start in order to build this xml; for example, what is wsse: BinarySecurityToken? and I need to create prefixes like "wsu" or "wsse" too ???

The information below is on the test server, so there is any sensitive data here.

<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Header>
    <wsse:Security xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
        <wsse:UsernameToken wsu:Id="Username-123" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
            <wsse:Username>gen-emiswebmobile.e-mis.co.uk</wsse:Username>
        </wsse:UsernameToken>
        <wsu:Timestamp wsu:Id="Timestamp-1" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
            <wsu:Created>2017-06-29T22:42:44.870Z</wsu:Created>
            <wsu:Expires>2017-06-29T22:57:44.870Z</wsu:Expires>
        </wsu:Timestamp>
        <wsse:BinarySecurityToken wsu:Id="CertId-4468839874371617328" EncodingType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0#Base64Binary" ValueType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-x509-token-profile-1.0#X509v3" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">MIIFVjCCBD6gAwIBAgIHTvS0LmWypjANBgkqhkiG9w0BAQsFADCBtDELMAkGA1UEBhMCVVMxEDAOBgNVBAgTB0FyaXpvbmExEzARBgNVBAcTClNjb3R0c2RhbGUxGjAYBgNVBAoTEUdvRGFkZHkuY29tLCBJbmMuMS0wKwYDVQQLEyRodHRwOi8vY2VydHMuZ29kYWRkeS5jb20vcmVwb3NpdG9yeS8xMzAxBgNVBAMTKkdvIERhZGR5IFNlY3VyZSBDZXJ0aWZpY2F0ZSBBdXRob3JpdHkgL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aXN3ZWJtb2JpbGUuZS1taXMuY28udWuCIXd3dy5nZW4tZW1pc3dlYm1vYmlsZS5lLW1pcy5jby51azAdBgNVHQ4EFgQUfnm7SRUsh4sUkMHC41QY+Q3ysZ0wDQYJKoZIhvcNAQELBQADggEBAK3zIhwhU3N7bxGjRVTFsQDLvJBjrIeJiRHXTtPF8A/muYJdcapUTcz/cl8mu9hXN3po0WJQii2kttBQD7MAjHlIMDDY6iTDrEorqch0OUSc6tJe6KQlNdeE4Cng11/AlcTBNitxE8aNiC8PUsh4P4Se8jDNoa7ESSgv9MXpHUT+Dfx5wsM4CPkUMhdaQiPQPL4QzbwpphX+hD4DTGGkKR34HR91HLoUap/gOS97ZTUmUBtgOSSKGL+kVrs+HKA6+Zbv55ya0bYFHJikN/5R1XUgZX6l3VZJJvBnmFHETd2I6H/1/VKOiSoD4JNZf7cxfDRmi8cLixE6PdSM41ve6qw=</wsse:BinarySecurityToken>
        <Signature xmlns="http://www.w3.org/2000/09/xmldsig#">
            <SignedInfo>
                <CanonicalizationMethod Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#" />
                <SignatureMethod Algorithm="http://www.w3.org/2000/09/xmldsig#rsa-sha1" />
                <Reference URI="#Timestamp-1">
                    <Transforms>
                        <Transform Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#" />
                    </Transforms>
                    <DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha1" />
                    <DigestValue>WOHqa2p3/ZcVQ2FU36OEU9gfYaI=</DigestValue>
                </Reference>
            </SignedInfo>
            <SignatureValue>q/ZGfYAacr6Vv/LwfyAwyxXGLVkJ7qXJYkMvrCludwNRaENHNR1LekPwVuMGQ95uoKzk9npEnefHrCD1+JmufKltDtXLIZmhUJNryhOcUHzSoDLjdCAOJ+Ylccf73fhI7uHJr63NlbmV6IVzTrb3RPpfoJDpuDqyrkqS0l4HQI3BkzbDYR3Eo3ce8oUzfZ32xpLTQ/LceI6DsaHMCtimxjhAJDa1NuRDbsosHgxw8MEms1hc5VwR4s2/h6GJEkz5EXegWkm9CBNlpgceaFF7HMUPZqm7PUTHTrsmfN9uEZlp4iaUQrCBPNwsju3dbD1nOxNAxQeGvx5RNL0xvY5emg==</SignatureValue>
            <KeyInfo Id="KeyId-4468839874371617327">
                <wsse:SecurityTokenReference wsu:Id="STRId-3E04823056058230" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
                    <wsse:Reference ValueType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-x509-token-profile-1.0#X509v3" URI="#CertId-4468839874371617328" />
                </wsse:SecurityTokenReference>
            </KeyInfo>
        </Signature>
    </wsse:Security>
    <Action xmlns="http://www.w3.org/2005/08/addressing">MiG</Action>
    <MessageID xmlns="http://www.w3.org/2005/08/addressing">84CF41DA-133A-442D-979B-D76697AF71BF</MessageID>
    <To xmlns="http://www.w3.org/2005/08/addressing">https://185.13.72.96/Miggateway</To>
    <ReplyTo xmlns="http://www.w3.org/2005/08/addressing">
        <Address>http://www.w3.org/2005/08/addressing/anonymous</Address>
    </ReplyTo>
</soap:Header>
<soap:Body>
    <q1:migRequest xmlns:q1="http://www.healthcaregateway.co.uk/mig">
        <q1:serviceDefinition>
            <q1:name>MIG.DATAEXTRACTIONSERVICE.EhrExtractRequest</q1:name>
            <q1:version>0.0.2</q1:version>
        </q1:serviceDefinition>
        <q1:serviceHeader>
            <q1:source xmlns:q1="http://www.healthcaregateway.co.uk/mig">
                <q1:identifier>externaldevuser:urn:hgl:addressing:ods:N00001</q1:identifier>
            </q1:source>
            <q1:target xmlns:q1="http://www.healthcaregateway.co.uk/mig">
                <q1:nationalCode>urn:hgl:addressing:ods:A00005</q1:nationalCode>
            </q1:target>
        </q1:serviceHeader>
        <q1:serviceContent>
            <q1:ehrExtractRequestv2-0 xmlns:q1="http://www.healthcaregateway.co.uk/mig">
                <q1:id>4df5cdb1-4a20-42a5-b604-6033eec5224d</q1:id>
                <q1:consent>
                    <q1:value>Given</q1:value>
                </q1:consent>
                <q1:provenance>
                    <q1:creationTime>2013-07-15T14:37:28.7273043Z</q1:creationTime>
                    <q1:system>
                        <q1:id>BED045C0-BC58-4934-8E11-2FC08F730060</q1:id>
                        <q1:name>EMISWebCR1 50002</q1:name>
                    </q1:system>
                </q1:provenance>
                <q1:patient>
                    <q1:primaryIdentifier type="NHS">8888888888</q1:primaryIdentifier>
                </q1:patient>
                <q1:requestSpecification>
                    <q1:id>654d8e02-6b09-4754-a095-968c397db560</q1:id>
                    <q1:responseFormat>OPENHR</q1:responseFormat>
                    <q1:request>
                        <q1:name>scm.diagnosis</q1:name>
                        <q1:includeAssociatedText>true</q1:includeAssociatedText>
                    </q1:request>
                </q1:requestSpecification>
            </q1:ehrExtractRequestv2-0>
        </q1:serviceContent>
    </q1:migRequest>
</soap:Body>

      

+3


source to share


2 answers


You can look here for some sample code.

The xml you posted is a soap XML envelope and you can submit it as shown in the example (using LoadXml) and get a response. (in the xml you posted you are calling the MiG action with migRequest).

If you don't have a request for a soap envelope you will have to create one, which is the tricky part if you don't know what functions to call.
The structure of the request is like this: (there is also security in your example, which is not here)



<?xml version="1.0" encoding="utf-8"?>
 <soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
  <soap:Body>
    <MethodFoo>
      <param1>value</param1>
      <param2>value</param1>
    </MethodFoo>
  </soap:Body>
</soap:Envelope>

      

Look here for more information on the structure of the request messages.

+2


source


There are several ways to connect to a web service. Basically, you are using one of the classes to "send" the exact xml to the url.

Common ways are WebClient , HttpClient . It is relatively easy to send an XML to a URL.

If I understand you correctly, you are looking at ways to generate the Xml in the right format.

In one case, we performed a similar request as follows.

Take sample xml and convert it to template

eg,



<q1:system>
    <q1:id>BED045C0-BC58-4934-8E11-2FC08F730060</q1:id>
    <q1:name>EMISWebCR1 50002</q1:name>
</q1:system>

      

becomes

<q1:system>
    <q1:id>~system_id~</q1:id>
    <q1:name>~system_name~</q1:name>
</q1:system>

      

In the example above ~system_id~

, ~system_name~

are placeholders. In the application code, you will find and replace the actual values.

It looks like a "low key" ... but in the good old days (i.e. before we have xml all over the place) this was a popular approach :-)

Another Xml way is to build a C # class in an exact format. You populate your object with the appropriate values. Then you serialize your C # class to xml and send it to the url. There are several popular SO links for this: Generate C # class from XML

0


source







All Articles