Sending XML file with .NET Client

Hi
Has anyone managed to send XML files to TN using a .NET Client? I have tried various ways to do this but always end up with a 401 Access Denied Exception. Posting the file in a browser with the same credentials works fine.

c# code below

WebClient client = new WebClientSIZE=2;
[/size]CredentialCache myCreds = new CredentialCacheSIZE=2;
[/size]NetworkCredential myCred = new NetworkCredential(“user”, “password”, “”);
myCreds.Add(
https://tnurl/receive, 443, “Basic”, myCred);
client.Credentials = myCreds;
client.Headers.Add(
“Content-Type”, "text/xml ");
client.UploadFile(url, “POST”, “c:\test.xml”);


have also tried adding the username and password in the header with

[SIZE=2]
client.Headers.Add(
“Authorization”, "Basic " +
Convert.ToBase64String(Encoding.ASCII.GetBytes(“ATUKPLC:ATUKPLC”[SIZE=2])));

but still doesn’t work. Also tried directly with the HttpWebRequest object but same result.

I have managed this with a Java client using the Apache HTTPClient API (which was also a struggle) but can’t get it with .NET.

Any suggestions welcome.

Thanks

[/size]
[/SIZE]

Please check the URL and that you invoked.

The TN gateway URL that should invoke is :
http://ISlocalhost:port/invoke/wm.tn/receive

Also make sure on the IS/TN side the particular user is allowed to send the documents to TN and check the service ACL also as you are getting access denied…There are some situations where change tn:receive service ACL to Anonymous.

HTH,
RMG

Hi
I substituted the URL in the post, it’s not the real one.

I’ve got this to work in the meantime, simple version below for use in an ASP.NET app

protected void Button1_Click(object sender, EventArgs e)
{
  string input = TextBox1.Text.Trim();

  byte[] byteSource = input == null ? null : Encoding.UTF8.GetBytes(input);
  Stream responseStream;
  string url = "https://[I]url.com[/i]/invoke/B2BGateway/receive";

  HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
  request.KeepAlive = false;
  request.Method = "POST";
  request.ContentType = "text/xml";
  NetworkCredential myCred = new NetworkCredential("[I]username[/i]", "[I]password[/i]");

  request.PreAuthenticate = true;
  request.ContentLength = byteSource.Length;
  request.Credentials = myCred;

  byte[] credBuf = new System.Text.UTF8Encoding().GetBytes(myCred.UserName + ":" + myCred.Password);
  request.Headers["Authorization"] = "Basic " + Convert.ToBase64String(credBuf);
  request.Headers["WWW-Authenticate"] = "Basic realm=\"webMethods\"";

  Stream requestStream = request.GetRequestStream();
  requestStream.Write(byteSource, 0, byteSource.Length);
  requestStream.Close();

  HttpWebResponse response = (HttpWebResponse)request.GetResponse();

  string returnCode = response.StatusCode.ToString();

  Label1.Text = returnCode;

}

Thanks

Cool…Thanks for the update!