Problem getting my code using wsdl generated classes to produce correct soap message

90 Views Asked by At

I used WSDL to generate classes for creating a soap/XML message to a web service. WSDL: https://cmbhs.dshs.state.tx.us/cmbhswebservice/Service/DataDownloadService.asmx?wsdl

soap/xml request that works when using another language/HTTP submission:
<?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:Header>
    <CMBHSAuthenticationHeader xmlns="http://www.dshs.state.tx.us/cmbhs/">
      <CMBHSUserName>xxxx</CMBHSUserName>
      <CMBHSPassword>yyyy</CMBHSPassword>
    </CMBHSAuthenticationHeader>
  </soap:Header>
  <soap:Body>
    <Download xmlns="http://www.dshs.state.tx.us/cmbhs/">
        <organizationNbr>479</organizationNbr>
        <fromDate>##########</fromDate>
        <toDate>$$$$$$$$$$</toDate>
        <downloadType>##</downloadType>
        <downloadDateType>2</downloadDateType>
    </Download>
  </soap:Body>
</soap:Envelope>

What seems to make this complicated is the use of a mandatory authentication header.

My code is as follows(real ID, password removed):

using ConsoleApp7.us.tx.state.dshs.cmbhs;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Security.Policy;
using System.Text;
using System.Threading.Tasks;
using System.Web.Services.Description;
using static System.Collections.Specialized.BitVector32;

namespace ConsoleApp7
{
    internal class Program
    {
        static void Main(string[] args)
        {
            var service = new us.tx.state.dshs.cmbhs.DataDownloadService { Url= "https://cmbhs.dshs.state.tx.us/cmbhswebservice/Service/DataDownloadService.asmx" };
            CMBHSAuthenticationHeader myheader = new CMBHSAuthenticationHeader();
            myheader.CMBHSUserName = "xxxxxx";
            myheader.CMBHSPassword = "yyyyyy";
            Console.WriteLine("location 1");
            DateTime FromDate = new DateTime(2022, 10, 01);
            DateTime ToDate = new DateTime(2022, 10, 03);
            Console.WriteLine("location 2");
            DataDownloadResult  mydata = service.Download(449737,FromDate ,ToDate , 12, 02);
            Console.WriteLine("----START----");
            Console.WriteLine(mydata);
            Console.WriteLine("----END----");

        }
    }
}

When I run the code, the Location 1 and Location 2 messages are displayed but not the "----START----" message.

Can anyone tell me what is wrong or how to figure out what is wrong?

I have read extensively and tried a host of different object and variable names.

1

There are 1 best solutions below

0
bob alston On

Best recommendation was to switch to WCF. At the time I did not know I could use WCF to communicate with old soap/xml service. It works.

WCF allows for logging outbound message: https://learn.microsoft.com/en-us/dotnet/framework/wcf/diagnostics/configuring-message-logging This is really key as it tells me whether or not my message was actually sent. It was.

Learned to use Fiddler classic (free version) to see if I got any response.

No response til I changed "DownloadAsync" to "Download".

Had to expand max size of inbound messages for my app: The maximum message size quota for incoming messages (65536) has been exceeded

Last problem was not having proper backups of my app. I use IDrive - which was not setup to backup my Visual Studio apps (it is now) and a monthly backup to portable hard drive which fortunately was run after I switched to WCF but did not have the latest changes. In doing cleanup I INADVERTENLY deleted my app latest version. Now making more copies as I make changes and made sure IDrive was properly backing everything up.

Update 2023-04-08 8:05 pm- Original code was missing code tying header to service. Adding this line made it work:

service.CMBHSAuthenticationHeaderValue = myheader;