0

My company posts invoices to both Ariba and Oracle Supplier Networks via HTTP POST. We've had an issue where we haven't been able to determine whether it comes from its settings or code.

Below is the code:

Public Function SendMime(pFiles As List(Of String)) As String
    'just use the text send option in HTTP connection
    If pFiles.Count = 1 And pFiles.Item(0).EndsWith(".xml") Then
        Return Send(My.Computer.FileSystem.ReadAllText(pFiles(0)))
    End If

    Dim Request As Net.HttpWebRequest

    Request = DirectCast(Net.WebRequest.Create(GetFirstURL()), Net.HttpWebRequest)
    Request.ContentType = "multipart/related;boundary=" & OuterBoundary & ";type=""text/xml"";start=""<" & _CID & ".1>"""
    Request.Method = "Post"
    Request.KeepAlive = True

    WriteRequest(Request, pFiles)

    Dim Response As Net.WebResponse
    Try
        Response = Request.GetResponse()
        Dim ResponseStream As Stream = Response.GetResponseStream()
        Dim ResponseReader As New StreamReader(ResponseStream)
        Return ResponseReader.ReadToEnd()
    Catch ex As System.Exception
        Return "error: " & ex.Message
    End Try
End Function

Private Sub WriteRequest(pRequest As Net.WebRequest, pFiles As List(Of String))
    Dim PartCount As Integer = 1

    _RequestStream = pRequest.GetRequestStream()
    _tempStream = New FileStream("C:\lastMIMEsent.txt", FileMode.Create)

    For Each File As String In pFiles
        WriteBoundary(OuterBoundary)
        If File.ToLower.EndsWith(".xml") Then
            GetXMLPart(File, PartCount)
        ElseIf File.ToLower.EndsWith(".pdf") Then
            GetPDFPart(File, PartCount)
        End If
        PartCount += 1
    Next

    WriteTrailer(OuterBoundary)

    _RequestStream.Close()
    _tempStream.Flush()
    _tempStream.Close()

End Sub

The send function is similar to the SendMime function, but with no attachments (cXML only). This code is shared between a Windows Service and a basic GUI test program.

edit: The error I get is:

Unable to connect to host

Where things get weird:

  • On the server running the service: Oracle works, Ariba does not, when the service calls the SendMime function.
  • On the server running the service: Both work, when the GUI utility calls the SendMime function.
  • On my work station: both work, regardless of whether it is the service or GUI calling the SendMime function
  • My first thought was Proxy, but both machines are behind the same proxy.
  • My second thought was Firewall issues, but we disabled the firewall with no success.
  • We can connect to the address via web browser as well.
  • We tried with different Active Directory accounts, with no change as well.
  • Both the service and the GUI utility are running .Net 4.5 (needed for some asynchronous parts of the service). They were not at one point, but upgrading the Utility made no difference.
  • The only difference I can find, is that my machine runs Windows 7 and the server runs Windows Server R2, but I can find no documentation stating that there should be a difference.

I've been trying to figure this out for a couple weeks, experimenting with different adjustments, and at this point, both I and the server team are out of ideas. Any advice, whether its red flags in my code or just known windows server issues, would be greatly appreciated.

Sandra Rossi
  • 11,934
  • 5
  • 22
  • 48
sjoachim
  • 95
  • 6
  • What error are you getting? Is there some code missing from the above? Where in the code is it failing? – MrGadget Feb 21 '16 at 19:57
  • @MrGadget The error is "unable to connect to host". I'll add that to the post. That is all the code, apart from what calls it, and the send function, which does essentially the same thing. I am not exactly sure which line is failing as i don't have a debugger on the server and it works fine on my machine, with or without the debugger. I know it's in here from the error handling in the calling function. – sjoachim Feb 22 '16 at 14:06
  • So it's not in the Send method for certain? That Try--Catch is firing? Can you store the result of GetFirstURL() and change the return in the Catch to something like `Return "SendMime error: " & URL & " " & ex.Message` To verify what you're trying to connect to from the server? – MrGadget Feb 22 '16 at 15:02
  • Honestly I'd think it was a permission issue, that the account the service is running under is behaving differently since you say a logged in user on the server running a GUI app succeeds...maybe a group policy or something. If you can have the service published as Debug instead of release, you can return ex.ToString() which will give you more detail and line numbers. – MrGadget Feb 22 '16 at 15:26

0 Answers0