【问题标题】:SOAP request in .net.net 中的 SOAP 请求
【发布时间】:2013-03-10 13:59:59
【问题描述】:

我正在尝试生成一个肥皂请求,但无法弄清楚我做错了什么......

以下是有关请求外观的文档: http://wiki.affiliatewindow.com/index.php/Affiliate_Service_API_v4

这就是我所做的:

        StringBuilder reqBuilder = new StringBuilder(1000);
        reqBuilder.Append("<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:ns1=\"http://api.affiliatewindow.com/\">");
        reqBuilder.Append("<soapenv:Header>");
        reqBuilder.Append("<ns1:UserAuthentication soapenv:mustUnderstand=\"1\" soapenv:actor=\"http://api.affiliatewindow.com\">");
        reqBuilder.Append("<ns1:iId>***********</ns1:iId>");
        reqBuilder.Append("<ns1:sPassword>**************</ns1:sPassword>");
        reqBuilder.Append("<ns1:sType>affiliate</ns1:sType>");
        reqBuilder.Append("</ns1:UserAuthentication>");
        reqBuilder.Append("</soapenv:Header>");
        reqBuilder.Append("<soapenv:Body>");
        reqBuilder.Append("<ns1:getTransactionList>");
        reqBuilder.Append("<ns1:dStartDate>" + dateTimePickerFrom.Value.ToString("yyyy-MM-dd")+ "</ns1:dStartDate>");
        reqBuilder.Append("<ns1:dEndDate>" + dateTimePickerTo.Value.ToString("yyyy-MM-dd") + "</ns1:dEndDate>");
        reqBuilder.Append("<ns1:sDateType>transaction</ns1:sDateType>");
        reqBuilder.Append("</ns1:getTransactionList>");
        reqBuilder.Append("</soapenv:Body>");
        reqBuilder.Append("</soapenv:Envelope>");

        string strSoapMessage = reqBuilder.ToString();
        HttpWebRequest req = (HttpWebRequest)WebRequest.Create(new Uri(@"http://api.affiliatewindow.com/v4/AffiliateService?wsdl"));
        req.ContentType = "text/xml; charset=utf-8";
        req.Method = "POST";
        req.Accept = "text/xml";
        req.Headers.Add("SOAPAction", "getTransactionList");

        byte[] reqBytes = System.Text.Encoding.UTF8.GetBytes(strSoapMessage);
        req.ContentLength = reqBytes.Length;

        Stream reqStream = req.GetRequestStream();
        reqStream.Write(reqBytes, 0, reqBytes.Length); reqStream.Close();

        HttpWebResponse response = req.GetResponse() as HttpWebResponse;
        Stream responsedata = response.GetResponseStream();
        StreamReader responsereader = new StreamReader(responsedata);
        string response1 = responsereader.ReadToEnd();

        string saveFileName = "test.xml";
        XmlDocument xmlFile = new XmlDocument();
        xmlFile.LoadXml(response1);
        xmlFile.Save(saveFileName);

我的回复是wsdl服务的内容(http://api.affiliatewindow.com/v4/AffiliateService?wsdl)

欢迎任何帮助

【问题讨论】:

  • 为了其他人的利益,请编辑您的问题,以包含此方法到底有什么问题以及任何相关错误。
  • 你修好了吗?因为我对相同的 wsdl 服务有同样的问题。提前致谢。

标签: .net wcf web-services soap


【解决方案1】:

呃...你的第一个错误是实际上按照你做的方向前进。

因为您有 WDSL。最简单的方法是打开 .net WSDL 工具。

Create web service proxy in Visual Studio from a WSDL file.

How to: Add a Reference to a Web Service

一旦你有了它,你应该能够通过代理轻松地生成和发送请求。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-08-19
    • 2014-07-13
    • 1970-01-01
    • 1970-01-01
    • 2015-03-11
    • 1970-01-01
    相关资源
    最近更新 更多