473,385 Members | 1,470 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

How do I create an ATOM client in Csharp?

Blogger has posted this code:
===============================
using System;
using System.Net;
using System.Security.Cryptography;
using System.Text;
using System.Web.Services.Protocols;
using System.Xml;

public class AtomClient {
public static void Main(string[] arg) {
if (arg.Length != 3) {
Console.WriteLine("Usage: AtomClient user password url");
return;
}

string user = arg[0];
string password = arg[1];
string url = arg[2];

// Create a blog entry
entryType blog = new entryType();
blog.issued = DateTime.Now;
blog.title = "First Post!";

// Author
blog.author = new authorType();
blog.author.name = "Sam Ruby";
blog.author.url = "http://www.intertwingly.net/blog/";

// Generator
blog.generator = new generatorType();
blog.generator.url = "http://www.intertwingly.net/blog/";
blog.generator.Value = "WSDL C# Client";

// Fill in the content
XmlDocument d = new XmlDocument();
d.InnerXml = "<div xmlns='http://www.w3.org/1999/xhtml'>Hello World!</div>";
blog.content = new contentType[1];
blog.content[0] = new contentType();
blog.content[0].mode = contentTypeMode.xml;
blog.content[0].type = "application/xhtml+xml";
blog.content[0].Any = new XmlNode[1];
blog.content[0].Any[0] = d.DocumentElement;

// Create an 'atom' authorization header
Security auth = new Security();
UsernameToken unt = new UsernameToken();
auth.UsernameToken = new UsernameToken();
auth.UsernameToken.Nonce = new Random().Next().ToString();
auth.UsernameToken.Username=user;
auth.UsernameToken.Created=DateTime.Now.ToString(" u").Replace(' ','T');

// Fill in the password
SHA1 md = new SHA1CryptoServiceProvider();
string v = auth.UsernameToken.Nonce + auth.UsernameToken.Created + password;
byte[] digest = md.ComputeHash(Encoding.Default.GetBytes(v));
auth.UsernameToken.Password=new passwordType();
auth.UsernameToken.Password.Value=Convert.ToBase64 String(digest);
auth.UsernameToken.Password.Type="wsse:PasswordDig est";
auth.UsernameToken.Password.AnyAttr=new XmlAttribute[1];
auth.UsernameToken.Password.AnyAttr[0]=d.CreateAttribute("wsse:placeholder",
"http://schemas.xmlsoap.org/ws/2002/07/secext");

try {
// Post the request
AtomAPI api = new AtomAPI();
api.SecurityValue = auth;
api.Url = url;
api.POST(ref blog);
} catch (SoapException fault) {
System.Console.WriteLine(fault.Message);
} catch (WebException httpStatus) {
System.Console.WriteLine(httpStatus.Message);
}

}
}
Nov 16 '05 #1
2 2234

Hello, Anonieko!

================================================== ========================
public class AtomClient {
public static void Main(string[] arg) {
if (arg.Length != 3) {
Console.WriteLine("Usage: AtomClient user password url");
return;
}

string user = arg[0];
string password = arg[1];
string url = arg[2];
..
..
..
================================================== ==================================
Well, first of all, I hope that doesn't compile:
arg is local variable (actially, parameter) for the "main()" method
and the "main()" method shouldn't start with a capital letter
(main()!=Main())

If I understood you correctly, you should create 'user', 'password', and
'url' varibles
separately from the "main()" method (just like you did), but do the
assignment inside it (see code below).
I prefer creating the variables BEFORE all methods even though it is not
required,
as long as it is declared within the class, just makes code look better; I
also prefer
EXPLICITLY declaring variables as 'private', 'public', 'static' (if
necessary), etc
keywords and then call them as "this.<variablename>" or
"<classname>.<variablename>"
for static variables (same applies for methods) - again makes code look
better, at least to me...

================================================== ==================================
public class AtomClient {
private string
user="",
password="",
url="";
//initialization was not really required for this matter - see "main()"
method:

public static void main(string[] arg)
{
if (arg.Length != 3)
{
Console.WriteLine("Usage: AtomClient user password url");
Application.Exit();
}
else
{
this.user = arg[0];
this.password = arg[1];
this.url = arg[2];
}
}
//Here goes the rest of your code. Sorry, I didn't check it...
..
..
..
}
================================================== ========================

Hope this helps... :):):)
With best regards, Nurchi BECHED.
Nov 16 '05 #2
Nurchi BECHED wrote:
Hello, Anonieko!

================================================== ========================
public class AtomClient {
public static void Main(string[] arg) {
if (arg.Length != 3) {
Console.WriteLine("Usage: AtomClient user password url");
return;
}

string user = arg[0];
string password = arg[1];
string url = arg[2];
.
.
.
================================================== ==========================
======== Well, first of all, I hope that doesn't compile:
arg is local variable (actially, parameter) for the "main()" method
and the "main()" method shouldn't start with a capital letter
(main()!=Main())


This is C#, not Java or C++. We're doing Main() here ;-)

--
Joerg Jooss
jo*********@gmx.net

Nov 16 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Just close your eyes and see | last post by:
Hello All can any one help me where is the windows atom table and how to navigate it, and how to add and delete values from it thx
4
by: Sharon | last post by:
Hi, I'm using the remoting, and I have a remoting object that has a public event that other processes should register to it. But when the client process is registering to the remote event, it...
13
by: Sandeep Singh | last post by:
I am making socket client application in C# how can i get ip address of client who has connected to server
14
by: Ankit Aneja | last post by:
The code of classes given below is for server to which clients connect i want to get ip address of client which has connected pls help how can i get //listen class public class listen {
0
by: banjolibrarian | last post by:
I have been setting up RSS and Atom feeds for our library's podcasts. The RSS feed works fine, but when I subscribe to the Atom feed (via Bloglines), the link to the file itself defaults to...
0
by: aking | last post by:
J. Clifford Dyer wrote: ...................................................................................................................................
4
by: Billy Barth | last post by:
I would like to create a RSS feed from my Access Database. I have an Access table for news which has the article title, date, and story in it. What I would like to do is pull the data from there...
0
by: Andreas M. | last post by:
Hello, for a personal project I need to extend the ATOM specification by adding my own namespaced stuff. It must validate! Therefore I need to create an XSD. I came upon several problems: ...
25
by: Licheng Fang | last post by:
I mean, all the class instances that equal to each other should be reduced into only one instance, which means for instances of this class there's no difference between a is b and a==b. Thank...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.