views:

265

answers:

3

I'm trying isolate a problem I'm having making an XML RPC call:

XDocument doc = new XDocument();
doc.Add(new XElement("methodCall",
     new XElement("methodName", "send"),
  new XElement("params",
      new XElement("param", new XElement("value", new XElement("string", this.ApiKey))),
      new XElement("param", new XElement("value", new XElement("string", this.FromAddress))),
      new XElement("param", new XElement("value", new XElement("string", recipient))),
      new XElement("param", new XElement("value", new XElement("string", contents)))  
  )
 )
);

HttpWebRequest req = (HttpWebRequest)WebRequest.Create("http://urlremoved");
req.ContentType = "text/xml";
req.Method = "POST";

XmlTextWriter writer = new XmlTextWriter(req.GetRequestStream(), Encoding.UTF8);
doc.Save(writer);

HttpWebResponse response = (HttpWebResponse)req.GetResponse();
StreamReader reader = new StreamReader(response.GetResponseStream());
return reader.ReadToEnd();

This just stalls and never times out (even if I set timeouts on req.TimeOut and req.ReadWriteTimeout). I removed the url, mostly to keep the focus on just the code.

Is there anything wrong with the code that would prevent this call from being made?

A: 

What happens if you call writer.Flush(); after you save the XML?

I'm not sure why this doesn't time out, but maybe it doesn't time out as no request is being made due to the fact that writing is buffered?

Thorsten Dittmar
A: 

I ended up using http://www.xml-rpc.net/ instead of writing my own.

John Sheehan
A: 

I have a proble: Follows faultCode 4 faultString Too many parameters. could you tell me how to use asp.net receive the XML-RPC and parse the date of XML-RPC then storage it to the database.thanks

You should post a new question with more details including code samples.
John Sheehan