skip to Main Content

c# 4.7.2 asp.net classic webservice, connecting to webserivce using proxy generated by wsdl.exe via winforms.

I have web apps successfully connecting to the webservice, but I have a tool I wrote in c#/winforms, for testing if webservices are alive and working at various levels (dev/prod/etc)

What is the easiest way to call an .asmx webservice via https?

This is what it looks like now, but I’m okay with abandoning the proxy if that’s easier

        AdStudent.ADStudent ws = new AdStudent.ADStudent();
        ws.Url = "https://jcdcadstudent.bob.org/adstudent.asmx";

        string str = ws.GetGuidString("Brown.Eric");
      

(Error = The underlying connection was closed: An unexpected error occurred on a send)

On the web apps, just changing the url works, but not from a winform.

2

Answers


  1. Chosen as BEST ANSWER

    The answer above did not work for me, I wound up doign it via soap, thusly

     static string GetData2(string url)
            {
                var httpClient = new HttpClient();
                httpClient.DefaultRequestHeaders.Accept.Add( new MediaTypeWithQualityHeaderValue( "text/xml" ) );
                httpClient.DefaultRequestHeaders.Add( "SOAPAction", "http://tempuri.org/GetGuidString" );
    
                           
                var soapXml= "<?xml version="1.0" encoding="utf-8" ?> " +
                    "<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">" +
                        "<soap:Body>"+
                            "<GetGuidString xmlns="http://tempuri.org/">"+
                                "<adUsername>Brown.Eric</adUsername>" +
                            "</GetGuidString>" +
                        " </soap:Body>" +
                   "</soap:Envelope>";
    
                var response = httpClient.PostAsync( "https://jcdc-aeef.jcdev.org/JCDCADStudent/ADStudent.asmx", new StringContent( soapXml, Encoding.UTF8, "text/xml" ) ).Result;
    
                var content = response.Content.ReadAsStringAsync().Result;
    
                return content;
            }
    

    Check this url for detail on what tripped me up on the SOAP

    C# .netcore 3.1, calling asmx web service from a winform

    Hope it helps somebody!


  2. I’ve been doing something similar in WinForms, but I was sending requests to API, not MVC webapp, so I don’t know if this will help, but I’ll paste here one method of my WinForm App that was sending request to API:

    private async void Timer1_Tick(object Sender, EventArgs e)
        {
            var infos = new FirstEntity();
            infos.Num = 3;
            infos.Temp = 21;
            var json = JsonConvert.SerializeObject(infos);
            var data = new StringContent(json, Encoding.UTF8, "application/json");
    
            var url = "https://localhost:7078/WeatherForecast";
            using var client = new HttpClient();
    
            var response = await client.PostAsync(url, data);
    
            var result = await response.Content.ReadAsStringAsync();
        }
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search