0

I am using ASP.NET and C# to display a form for someone to complete and submit a request to an external company on a button click. The company provided a WSDL file which i was able to import into my Solution as a Web Reference. Once I added the reference it generated a bunch of classes which appears to create an XML file and from what I understand is what I need to do. I given an example of what an XML file submittion looks like but I am a little confused on how to the web reference and submit the request.

Here is the WSDL

I am trying call the complextype (method) ClaimSubmittalRequest This is what I was able to do in my C# code (get and set the fields):

        var submitClaim = new ThermalKing.SubmitClaimRequest
        {
            claimLanguage = "ENG",
            serviceVersion = "1.0",
            claimType = "PARTS",
            failureDate = new DateTime(2014, 11, 26),
            faultFound = "PERFORM A FREE INSPECTION"
        };

        var submitParts = new ThermalKing.eachPart
        {
            partNumber = "1234",
            partPrice = 100.78,
            partQuantity = 17
        };

Here is what the example XML File looks like:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:get="http://data-test.thermoking.com/ThermoKingWebServices/SubmitClaim/getSubmitClaimWSD">
   <soapenv:Header/>
   <soapenv:Body>
      <get:getSubmitClaim>
         <SubmitClaimRequest>

            <buName>Thermo King TSA</buName>
            <dealerNumber>P5358</dealerNumber>
            <userName></userName>
            <password></password>

            <transactionType>WARRANTY</transactionType>
            <claimType>Machine</claimType>

            <inventorySerialNumber>6001061225</inventorySerialNumber>

            <repairDate>2011-09-05T00:00:00.000-05:00</repairDate>
            <failureDate>2011-09-05T00:00:00.000-05:00</failureDate>

            <workOrderNumber>testProcede1</workOrderNumber>
            <conditionsFound>test</conditionsFound>
            <workPerformed>test</workPerformed>
            <claimNotes>test claim notes</claimNotes>

            <!-- will be optional fields in the future -->
              <faultLocation>FF</faultLocation>
              <faultFound>BLOWN/BURST</faultFound>
              <failureDetail xsi:nil="true"/>

            <smrClaim>N</smrClaim>
            <forceToDraft>Y</forceToDraft>
            <validateOnly>N</validateOnly>
            <commercialPolicy>N</commercialPolicy>

            <!-- will be optional fields in the future -->
              <fuelSurcharge>0</fuelSurcharge>
              <shopSupplies>0</shopSupplies>

            <claimCurrency>USD</claimCurrency>
            <workOrderSegment>1</workOrderSegment>
            <claimLanguage>ENG</claimLanguage>
            <serviceVersion>1.0</serviceVersion>

            <partsType>
               <!--1 or more repetitions:-->
               <eachPart>
                  <partType>IRREMOVED</partType>
                  <partNumber>416780</partNumber>
                  <partQuantity>1.0</partQuantity>
                  <partPrice>1.23</partPrice>
                  <partDescription>test part desc</partDescription>
               </eachPart>
               <eachPart>
                  <partType>NONIR</partType>
                  <partNumber>1</partNumber>
                  <partQuantity>1.0</partQuantity>
                  <partPrice>1</partPrice>
                  <partDescription>test non IR</partDescription>
               </eachPart>
               <eachPart>
                  <partType>IRINSTALLED</partType>
                  <partNumber>416780</partNumber>
                  <partQuantity>1.0</partQuantity>
                  <partPrice>1</partPrice>
                  <partDescription>test ir installed</partDescription>
               </eachPart>
            </partsType>

            <jobCodesType>
               <!--1 or more repetitions:-->
               <eachJobCode>
                  <jobCode>05051</jobCode>
                  <standardLaborHours>1</standardLaborHours>
                  <additionalLaborHours>.5</additionalLaborHours>
                  <laborRate>92.22</laborRate>
                  <ReasonForAdditionalLaborHours>test</ReasonForAdditionalLaborHours>
               </eachJobCode>
            </jobCodesType>

            <usageMetersType>
               <!--1 or more repetitions:-->
               <eachUsageMeter>
                  <usageAmount>1661</usageAmount>
                  <usageType>HoursInService</usageType>
                  <usageUOM>HOURS</usageUOM>
               </eachUsageMeter>
            </usageMetersType>


         </SubmitClaimRequest>
      </get:getSubmitClaim>
   </soapenv:Body>
</soapenv:Envelope>

How can I call the Complex Type Method in my C# code to send the request to the external company? Or is it easier just to create an XML file manually using C#?

UPDATED CODE:

    using (var client = new getSubmitClaimWSD_PortTypeClient())
    {
        SubmitClaimRequest request = new SubmitClaimRequest()
        {
            buName = "Thermo King TSA",
            dealerNumber = "PHSDF",
            userName = "Roger",
            password = "1234",
            transactionType = "WARRANTY",
            claimLanguage = "ENG",
            serviceVersion = "1.0",
            claimType = "PARTS",
            failureDate = new DateTime(2014, 11, 26),
            faultFound = "PERFORM A FREE INSPECTION",
            inventorySerialNumber = "12352341",
            repairDate = new DateTime(2014, 11, 26),
            workOrderNumber = "testProcede1",
            conditionsFound = "test",
            workPerformed = "test",
            claimNotes = "test claim notes",
            faultLocation = "FF",
            failureDetail = "test",
            smrClaim = "N",
            forceToDraft = "Y",
            validateOnly = "N",
            commercialPolicy = "N",
            fuelSurcharge = 0,
            shopSupplies = 0,
            claimCurrency = "USD",
            workOrderSegment = "1",
            partsType = new[]
            {
                new eachPart() {partNumber = "1234", partPrice = 100.78, partQuantity = 17, partType = "NONIR", partDescription = "test part desc"},
                new eachPart() {partNumber = "5678", partPrice = 200.90, partQuantity = 1, partType = "IRREMOVED", partDescription = "test part desc 2"}
            }
        };
        var response = client.getSubmitClaim(null, request);
        var rsp = response.response;
        Console.WriteLine("Status {0}, claim {1}; {2} {3}, {4} errors", rsp.status, rsp.claimNumber,
            rsp.workOrderNumber, rsp.workOrderSegment, rsp.errorsType.Length);
    }
4
  • Please see How to consume a web service. You don't ever send "XML files". Commented Dec 2, 2014 at 19:50
  • @JohnSaunders I read that article. So basically I do not need to create my own web service that is why i have the wsdl. I just have to add the wsdl as the web reference that then apply my updated code? Commented Dec 2, 2014 at 20:13
  • No, don't create your own service. The article creates a service just as a demonstration. Just do the part that uses the service. Your're already mostly there. Commented Dec 2, 2014 at 20:22
  • Neither of the things you have in the using blocks is the service. One is the request, and the other is part of the request. Commented Dec 2, 2014 at 20:26

1 Answer 1

1

Try something like this:

using (var client = new SubmitClaimService.getSubmitClaimWSD_PortTypeClient())
{
    SubmitClaimRequest request = new SubmitClaimRequest()
    {
        claimLanguage = "ENG",
        serviceVersion = "1.0",
        claimType = "PARTS",
        failureDate = new DateTime(2014, 11, 26),
        faultFound = "PERFORM A FREE INSPECTION",
        partsType =
            new[]
            {
                new eachPart() {partNumber = "1234", partPrice = 100.78, partQuantity = 17},
                new eachPart() {partNumber = "5678", partPrice = 200.90, partQuantity = 1}
            }
    };
    submitClaimResponse response = client.getSubmitClaim(request);
    var rsp = response.response;
    Console.WriteLine("Status {0}, claim {1}; {2} {3}, {4} errors", rsp.status, rsp.claimNumber,
        rsp.workOrderNumber, rsp.workOrderSegment, rsp.errorsType.Length);
}

I figured this out by right-clicking the service reference and choosing "View in object browser". Alternatively, you could bring up the Object Browser by using View->Object Browser, then navigate to the service reference.

Sign up to request clarification or add additional context in comments.

6 Comments

Thank you for helping me out. What did you do to add the service? When I add a service refference do I add the wsdl url in the url box?
Yes. Just paste in the URL: data-test.thermoking.com/ws/…
Okay, that's what I did too and there are no compiler errors or anything but I get an exception that states: There was no endpoint listening at data.thermoking.com:10141/ws/… that could accept the message. This is often caused by an incorrect address or SOAP action. See InnerException, if present, for more details
So the port got changed somehow. I fixed the port number and that got rid the above error but now on the line: var response = client.getSubmitClaim("true",request) I am getting an exception : The underlying connection was closed: The connection was closed unexpectedly.
Which version of Visual Studio are you using? Mine doesn't have a "true", just request.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.