1

i am trying to generate a soap request but cannot figure out what have i done wrong ...

Here is a documentation about how the request should look like: http://wiki.affiliatewindow.com/index.php/Affiliate_Service_API_v4

And here is what i have done:

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

My response is the content of the wsdl service (http://api.affiliatewindow.com/v4/AffiliateService?wsdl)

Any Help will be most welcomed

Aron
  • 15,464
  • 3
  • 31
  • 64
Matan L
  • 997
  • 3
  • 14
  • 35
  • 1
    For the benefit of others, please edit your question to include what exactly didn't work with this approach, and any related errors. – Didaxis Mar 11 '13 at 14:26
  • Did you fix it? Because i have the same problem with the same wsdl service. Thanks in advance. – vkampouris Sep 18 '14 at 11:34

1 Answers1

2

Erm...your first mistake was to actually to go the direction you did.

Since you have a WDSL. The SIMPLEST way to do this is to crack open the .net WSDL tools.

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

OR

How to: Add a Reference to a Web Service

Once you have that, you should be able to easily generate and send requests via the proxy.

Community
  • 1
  • 1
Aron
  • 15,464
  • 3
  • 31
  • 64