1

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

以下是有关请求外观的文档: 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

任何帮助都将受到欢迎

4

1 回答 1

2

呃……你的第一个错误是实际上去你做的方向。

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

在 Visual Studio 中从 WSDL 文件创建 Web 服务代理。

或者

如何:添加对 Web 服务的引用

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

于 2013-03-10T14:23:22.340 回答