Showing posts with label xml. Show all posts
Showing posts with label xml. Show all posts

10/24/2011

.NET Consuming Web Service with HttpRequest

Connecting to web services in Visual Studio 2010 can be a headache if configuration is not done properly. For instance, service references with authentication requires additional line of codes in web.config or app.config. These codes are placed between client header tags.

In some case, authentication may not be enough. Web service may require inputs and these inputs are send via XML structure. In my case, some input fields are nullable which creates xsi:nil="true" attribute in request.xml. It brokes the requested structure. There may be other cases that results in similar errors.

To solve the problem, I decided to call web service directly via HttpRequest.I downloaded and installed Soap Pro Trial edition to create exact request.xml. I added authentication code from app.config to request.xml for secure connection.
Then I wrote the following code:

HttpWebRequest req = (HttpWebRequest)WebRequest.Create("web service url ");
req.Headers.Add("SOAPAction", "\"thisl line can be found in first line of your request.xml"");
req.ContentType = "text/xml;charset=\"utf-8\"";
req.Accept = "text/xml";
req.Method = "POST";
//open request stream and unite with my stream which has the request.xml
using (Stream stm = req.GetRequestStream())
{
using (StreamWriter stmw = new StreamWriter(stm))
{
stmw.Write("xml string request.xml");
}
}
WebResponse response = req.GetResponse();

After getting the correct response the response.xml can be converted to a string.

Stream responseStream = response.GetResponseStream();
StreamReader resso = new StreamReader(responseStream);
string bobo = "";
bobo = resso.ReadToEnd();

Donot forget to close your streams at the end.




8/04/2010

Important Notes on Boxee

I want to share all the problems that I encountered while programming Boxee application.Before I started, I want to mention that I used notepad++ for my XML File. There should be lots of XML based editors, but choose a editor with python support if you can find.

1)You should create a shorcut of your application folder to Desktop, it will save my time a lot.

2)You should not use random id numbers for your control objects.

3)Never trust registry.xml file because everyone can manupilate its data.

4)You should write comments to your controls.This will help to recognize objects without opening it.

5)In order to save your file registry.xml:
mc.GetApp().GetLocalConfig().SetValue('lastplayed', label)

6)To change visibility of a control:
mc.GetActiveWindow().GetControl(1008).SetVisible(True)
The parameter must start with capital letter. (True, False)

7)Change bool value of control to true:
xbmc.executebuiltin('App.SetBool(1006,true)')
But the reverse is not correct. You should use reset to change bool to false:
xbmc.executebuiltin( 'App.Reset(1006)' )
I created resetAll() function in order not to implement same code repeatedly.

8)Get visibility information:
if mc.GetActiveWindow().GetControl(1000).IsVisible():

8)Set focus to a control:
mc.GetActiveWindow()..GetControl(2989).SetFocus()

9)Connect XML link with a list
mc.GetActiveWindow().GetList(3001).SetContentURL(strChannelMostWatched)

10)Add parameters to string:
strChannelPrograms = 'http://testm.kure.tv/user/XmlFeed.aspx?command=getChannelPrograms&par1=%s&kalite=%s'%(kanalnum,kalite)