webMethods

webMethods

Join this online group to communicate across IBM product users and experts by sharing advice and best practices with peers and staying up to date regarding product enhancements.

 View Only
Expand all | Collapse all

Sending XML file with .NET Client

  • 1.  Sending XML file with .NET Client

    Posted Fri November 20, 2009 09:46 AM

    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]


    #Integration-Server-and-ESB
    #B2B-Integration
    #webMethods


  • 2.  RE: Sending XML file with .NET Client

    Posted Fri November 20, 2009 04:11 PM

    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


    #B2B-Integration
    #Integration-Server-and-ESB
    #webMethods


  • 3.  RE: Sending XML file with .NET Client

    Posted Fri November 20, 2009 04:16 PM

    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


    #B2B-Integration
    #Integration-Server-and-ESB
    #webMethods


  • 4.  RE: Sending XML file with .NET Client

    Posted Fri November 20, 2009 04:23 PM