vendredi 11 septembre 2015

Calling non .Net Web service from a .Net application

I'm working on a .Net client application that will consume a non .Net web service via SOAP standard, to calculate and post Sales Tax information for items. There is no .asmx. The web service is authored and maintained by a different group. They provided a WSDL url and said all the XSD schemas I need are present in it. The problem is, it is nested and daisy chained using xsd:import tags, a few levels deep.

I have the web service added to my Visual Studio 2012 Windows Forms project by "Add Service Reference". Calling this web service was not straight forward as it had some additional security requirements.

The web service has 3 operations - HeartBeat, Calculate, Post.

With my very limited knowledge of WCF and some help from another expert, I was able to call the heartbeat function successfully; this was the easiest because it takes no parameters.

My struggle is, how to structure the input to call the other two functions - Calculate and Post ? They both take a strongly typed object as input. How do I construct such a strongly typed object? At the moment, as an experiment, I'm constructing an object based on the proxy classes VS2012 created for the service reference, initializing and populating them with some values manually. Should I use XSD.exe to generate classes for the schemas from WSDL and populate them with the input by deserializing?

Below is the SOAP call to the calculate function. This works when invoked from SoapUI.

<soap:Envelope xmlns:soap="http://ift.tt/18hkEkn" xmlns:v1="http://ift.tt/1O5KI7k">
    <soap:Header/>
    <soap:Body>
        <v1:calculate>
            <CalculateRequest>
                <Context>
                    <!--Optional:-->
                    <SendingApplication>SoapUI</SendingApplication>
                    <!--Optional:-->
                    <UserId>SoapUI</UserId>
                    <!--Zero or more repetitions:-->
                    <LocaleCode>en</LocaleCode>
                    <!--Optional:-->
                    <ApplicationName>SoapUI</ApplicationName>
                </Context>
                <TaxRequestor>
                    <Name>Person X</Name>
                    <!--Optional:-->
                    <!--Optional:-->
                    <AdministrativeAddress>
                        <Line1>888 River Dr</Line1>
                        <City>Queens</City>
                        <County>Queens County</County>
                        <State>NY</State>
                        <PostalCode>11001</PostalCode>
                        <CountryISO3Char>USA</CountryISO3Char>
                    </AdministrativeAddress>
                    <CompanyNumber>1</CompanyNumber>
                </TaxRequestor>
                <Transaction>
                    <!--1 or more repetitions:-->
                    <LineItem>
                        <LineNumber>1</LineNumber>
                        <!--Optional:-->
                        <Item>
                            <!--Optional:-->
                            <Identifier>10134</Identifier>
                            <!--Zero or more repetitions:-->
                            <Name LocaleCode="en-US">Product X</Name>
                            <!--Optional:-->
                            <TaxCode>9876</TaxCode>
                            <Department>
                                <!--Optional:-->
                                <Code>99</Code>
                                <!--Zero or more repetitions:-->
                                <Name LocaleCode="en-US">?</Name>
                            </Department>
                        </Item>
                        <!--Optional:-->
                        <Quantity>10</Quantity>
                        <!--Optional:-->
                        <UnitPrice>
                            <Amount>1000</Amount>
                        </UnitPrice>
                        <ShipFromAddress>
                            <Line1>888 River Dr</Line1>
                            <City>Queens</City>
                            <County>Queens County</County>
                            <State>NY</State>
                            <PostalCode>11001</PostalCode>
                            <CountryISO3Char>USA</CountryISO3Char>
                        </ShipFromAddress>
                        <ShipToAddress>
                            <Line1>1041 New York Rd</Line1>
                            <City>Newark</City>
                            <County>Essex</County>
                            <State>NJ</State>
                            <PostalCode>07054</PostalCode>
                            <CountryISO3Char>USA</CountryISO3Char>
                        </ShipToAddress>
                        <!--Zero or more repetitions:-->
                        <LineItemIdentifier>1</LineItemIdentifier>
                    </LineItem>
                    <LineItem>
                        <LineNumber>1</LineNumber>
                        <!--Optional:-->
                        <Item>
                            <!--Optional:-->
                            <Identifier>98765</Identifier>
                            <!--Zero or more repetitions:-->
                            <Name LocaleCode="en-US">Product X</Name>
                            <!--Optional:-->
                            <TaxCode>Some Tax Code</TaxCode>
                            <Department>
                                <!--Optional:-->
                                <Code>99</Code>
                            </Department>
                        </Item>
                        <!--Optional:-->
                        <Quantity>10</Quantity>
                        <!--Optional:-->
                        <UnitPrice>
                            <Amount>1000</Amount>
                        </UnitPrice>
                        <ShipFromAddress>
                            <Line1>888 River Dr</Line1>
                            <City>Queens</City>
                            <County>Queens County</County>
                            <State>NY</State>
                            <PostalCode>11001</PostalCode>
                            <CountryISO3Char>USA</CountryISO3Char>
                        </ShipFromAddress>
                        <ShipToAddress>
                            <Line1>1008 3rd St</Line1>
                            <City>Lewisville</City>
                            <County>Denton</County>
                            <State>TX</State>
                            <PostalCode>75010</PostalCode>
                            <CountryISO3Char>USA</CountryISO3Char>
                        </ShipToAddress>
                        <!--Zero or more repetitions:-->
                        <LineItemIdentifier>1</LineItemIdentifier>
                    </LineItem>
                </Transaction>
            </CalculateRequest>
        </v1:calculate>
    </soap:Body>
</soap:Envelope>

Please help with your advice and recommendations. Thank you. Using VS2012, .Net 4.5, C#



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire