繁体   English   中英

C# .netcore 3.1,从winform调用asmx web服务

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

我喜欢使用 winforms 为复杂的任务生成 quick.exe 工具,在这种情况下检查 a.asmx webservice 是否响应。

在 .net 中,我通过 wsdl 生成的代理 object 完成了此操作。

尝试在 .net 内核中执行此操作。

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;
}

但这就像我的 soap 请求格式错误

我的 soap 请求有什么问题?

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 规范来自 webmethod.asmx 页面。 在此处输入图像描述

因此,我的 web 服务代码被命名为 [WebService( Namespace = "http://tempuri.org/" )]

好的,

这是我做错了什么。

我改变了

SOAPAction:“http://tempuri.org/GetGuidString”

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

在我的 soap

我应该完全按照 ASMX 向我展示的那样离开它。

我对 soap 命名空间和 url 之间的区别有一个根本的误解,它们不是一回事。 (但看起来完全像)。

如果该声明使您感到困惑,请阅读这篇文章。 阅读全文。 起初似乎没有联系,但确实如此。

tempuri.org 是什么?

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM