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

Viewed 25

I like to use winforms to generate quick .exe tools for complex tasks, in this case checking to see if a .asmx webservice is responding.

in .net I did this via a wsdl generated proxy object.

Trying to do it in .net core.

static string GetData2(string url)
{
    var httpClient = new HttpClient();
    httpClient.DefaultRequestHeaders.Accept.Add( new MediaTypeWithQualityHeaderValue( "text/xml" ) );
    httpClient.DefaultRequestHeaders.Add( "SOAPAction", "http://jcdc-aeef.jcdev.org/JCDCADStudent/ADStudent.asmx" );

    
    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( "http://jcdc-aeef.jcdev.org/JCDCADStudent/ADStudent.asmx", new StringContent( soapXml, Encoding.UTF8, "text/xml" ) ).Result;

    var content = response.Content.ReadAsStringAsync().Result;

    return content;
}

But it's acting like my soap request is malformed

What is wrong with my soap requst?

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:Bodysoap:Faultsoap:ClientSystem.Web.Services.Protocols.SoapException: > Server did not recognize the value of HTTP Header SOAPAction: http://jcdc-aeef.jcdev.org/JCDCADStudent/ADStudent.asmx. at System.Web.Services.Protocols.Soap11ServerProtocolHelper.RouteRequest() at System.Web.Services.Protocols.SoapServerProtocol.RouteRequest(SoapServerMessage message) at System.Web.Services.Protocols.SoapServerProtocol.Initialize() at System.Web.Services.Protocols.ServerProtocolFactory.Create(Type type, HttpContext context, HttpRequest request, HttpResponse response, Boolean& abortProcessing)</soap:Fault></soap:Body></soap:Envelope>

Soap spec from .asmx page for webmethod. enter image description here

My webservice code is namespaced thusly [WebService( Namespace = "http://tempuri.org/" )]

1 Answers

Okay,

Here is what I was doing wrong.

I changed the

SOAPAction: "http://tempuri.org/GetGuidString"

to

"http://jcdc-aeef.jcdev.org/JCDCADStudent/ADStudent.asmx"

in my soap

And I should have left it exactly as the ASMX showed it to me.

I had a fundamental misunderstanding of the differences between soap namespaces and urls, which are not the same thing. (But totally look like they are).

If that statement confuses you, read this post. Read the whole thing. It seems not connected at first, but it really is.

What is tempuri.org?

Related