【问题标题】:C#: I want to create a simple SOAP clientC#:我想创建一个简单的 SOAP 客户端
【发布时间】:2018-04-12 08:59:24
【问题描述】:

我需要通过证书或更好的密钥库文件 (myfile.p12) 进行客户端身份验证。

我在 SoapUI 中使用了它,它在那里工作。我得到了有关可用请求的信息。

如果我尝试向我的空项目添加服务引用,它总是会失败。

There was an error downloading 'https://MYURL/api?wsdl/$metadata'.The request was aborted: Could not create SSL/TLS secure channel. Metadata contains a reference that cannot be resolved: 'https://MYURL/soapWebService/api?wsdl'. Could not establish secure channel for SSL/TLS with authority 'myurl:8443'. The request was aborted: Could not create SSL/TLS secure channel.

【问题讨论】:

  • https://MYURL/api?wsdl/$metadata 是否有服务运行?当您添加服务引用时,它会尝试连接并下载有关可用请求的元数据。或者可能有防火墙阻止请求?

标签: c# authentication soap


【解决方案1】:

我使用了以下代码

        var privCert = new X509Certificate2(@"c:\temp\test.p12", "testpass");

        // privCert.Verify() => FALSE!  WHY???
        if (privCert.Verify())  Console.WriteLine("true");
        else                    Console.WriteLine("false");

                    // create Web Request and set CLient Certificate für the authentication
        HttpWebRequest request = CreateWebRequest();
        request.ClientCertificates.Add(privCert);

        // Create SOAP Message for PING Command
        XmlDocument soapEnvelopeXml = new XmlDocument();
        soapEnvelopeXml.LoadXml(@"<?xml version=""1.0"" encoding=""utf-8""?>
                                <soap:Envelope xmlns:soap=""http://www.w3.org/2003/05/soap-envelope"" xmlns:ws=""http://ws.soap.transfer.services.sedna.ser.com/"">
                                    <soap:Header/>
                                    <soap:Body>
                                        <ws:ping>
                                            <sessionUUID>something</sessionUUID>
                                        </ws:ping>
                                    </soap:Body>
                                </soap:Envelope>");

        using (Stream stream = request.GetRequestStream())
        {
            soapEnvelopeXml.Save(stream);
        }


        Console.WriteLine("Credentials of request = " + request);


        // Send Command to Webservice
        try
        {
            using (WebResponse response = request.GetResponse())
            {
                using (StreamReader rd = new StreamReader(response.GetResponseStream()))
                {
                    string soapResult = rd.ReadToEnd();
                    Console.WriteLine(soapResult);
                }
            }
        }
        catch (Exception e)
        {

            Console.WriteLine(e.Message);
        }
        Console.WriteLine("\nTaste!");
        Console.ReadKey();
    }

    static HttpWebRequest CreateWebRequest()
    {
        HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create(@"https://doxapd01.zit.commerzbank.com:8443/soapWebService");
        webRequest.Headers.Add(@"SOAP:Action");
        webRequest.ContentType = "text/xml;charset=\"utf-8\"";
        webRequest.Accept = "text/xml";
        webRequest.Method = "POST";
        return webRequest;
    }

【讨论】:

    猜你喜欢
    • 2011-05-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-01-19
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多