Click here to Skip to main content
15,887,083 members
Home / Discussions / Visual Basic
   

Visual Basic

 
GeneralRe: How to load a single record, and with a join Pin
Dave Kreskowiak9-Jul-15 12:08
mveDave Kreskowiak9-Jul-15 12:08 
GeneralRe: How to load a single record, and with a join Pin
jkirkerx9-Jul-15 12:31
professionaljkirkerx9-Jul-15 12:31 
QuestionPrint RDLC without preview using VB.NET Pin
emmapaq6-Jul-15 10:00
emmapaq6-Jul-15 10:00 
QuestionExcel VBA Function runtime error 1004: Application-defined or object-defined error Pin
Member 118122063-Jul-15 11:57
Member 118122063-Jul-15 11:57 
SuggestionRe: Excel VBA Function runtime error 1004: Application-defined or object-defined error Pin
Richard MacCutchan3-Jul-15 21:28
mveRichard MacCutchan3-Jul-15 21:28 
QuestionPublic Delegate Sub Action(Of T) (obj As T) Pin
Member 1171394230-Jun-15 20:23
Member 1171394230-Jun-15 20:23 
AnswerRe: Public Delegate Sub Action(Of T) (obj As T) Pin
Richard MacCutchan30-Jun-15 21:21
mveRichard MacCutchan30-Jun-15 21:21 
QuestionFirstData G4 V14 HMAC Header Pin
jkirkerx29-Jun-15 13:47
professionaljkirkerx29-Jun-15 13:47 
Perhaps there's someone out there that has done FirstData G4 SOAP V14 in VB, and can checkout or point out any mistakes I made.

So I get this error upon transmitting
The HTTP request is unauthorized with client authentication scheme 'Anonymous'. The authentication header received from the server was ''.
So I'm figuring my HMAC header authentication is way off, and i get a generic response back.

I have a XML version that works just fine. And the G4 Sandbox has a HMAC Calculator tool, that I can use to compare and generate the values.

Issue 1:
But I'm not sure if what I'm pasting in as content is correct, in order to validate the code block, 2 blocks below.
example: Not sure if this is the correct format of SOAP Content, so I can run the FirstData HMAC Generate to confirm my values are right.
I using the same code sort of, to generate the HMAC stuff.
I just can't get a match of values, I'm way off, so I'm thinking that the SOAP content I generating against is wrong, in size and all.
If I fix issue 1, perhaps the rest of my code works fine.
XML
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
    <s:Body s:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
        <q1:SendAndCommit xmlns:q1="http://secure2.e-xact.com/vplug-in/transaction/rpc-enc/Request">
            <SendAndCommitSource href="#id1"/>
        </q1:SendAndCommit>
        <q2:Transaction id="id1" xsi:type="q2:Transaction" xmlns:q2="http://secure2.e-xact.com/vplug-in/transaction/rpc-enc/encodedTypes">
            <ExactID xsi:type="xsd:string">AH2824-05</ExactID>
            <Password xsi:type="xsd:string">0g4tu7pj1hb88q5d8xa55dlhvhvwlm3r</Password>
            <Transaction_Type xsi:type="xsd:string">00</Transaction_Type>
            <DollarAmount xsi:type="xsd:string">99.20</DollarAmount>
            <Card_Number xsi:type="xsd:string">4111111111111111</Card_Number>
            <Expiry_Date xsi:type="xsd:string">1215</Expiry_Date>
            <CardHoldersName xsi:type="xsd:string">Joe Smoe</CardHoldersName>
            <CVDCode xsi:type="xsd:string">999</CVDCode>
            <Reference_No xsi:type="xsd:string">CA-Test4</Reference_No>
            <Client_IP xsi:type="xsd:string">::1</Client_IP>
            <Client_Email xsi:type="xsd:string">xxxxxxx@gmail.com</Client_Email>
            <Currency xsi:type="xsd:string">USD</Currency>
            <Address href="#id2"/>
        </q2:Transaction>
        <q3:Address_Type id="id2" xsi:type="q3:Address_Type" xmlns:q3="http://secure2.e-xact.com/vplug-in/transaction/rpc-enc/encodedTypes">
            <Address1 xsi:type="xsd:string">1234 Main Street</Address1>
            <Address2 xsi:type="xsd:string"/>
            <City xsi:type="xsd:string">Huntington Beach</City>
            <State xsi:type="xsd:string">CA</State>
            <Zip xsi:type="xsd:string">92648</Zip>
            <CountryCode xsi:type="xsd:string">US</CountryCode>
        </q3:Address_Type>
    </s:Body>
</s:Envelope>

Issue 2:
This is my BeforeSendRequest. Im not sure how to check the SOAP to make sure if the header has been altered properly before transmitting, but the handler does run.
VB
Public Function BeforeSendRequest( _
        ByRef request As Message,
        ByVal channel As IClientChannel) As Object Implements IClientMessageInspector.BeforeSendRequest

        Dim buffer As MessageBuffer = request.CreateBufferedCopy(Int32.MaxValue)
        request = buffer.CreateMessage

        Dim msg As Message = buffer.CreateMessage
        Dim encoder As ASCIIEncoding = New ASCIIEncoding

        Dim sb As StringBuilder = New StringBuilder
        Dim xmlSettings As New XmlWriterSettings
        xmlSettings.OmitXmlDeclaration = True

        Dim xmlWriter As XmlWriter = xmlWriter.Create(sb, xmlSettings)
        Dim writer As XmlDictionaryWriter = XmlDictionaryWriter.CreateDictionaryWriter(xmlWriter)

        msg.WriteStartEnvelope(writer)
        msg.WriteStartBody(writer)
        msg.WriteBodyContents(writer)
        xmlWriter.WriteEndElement()
        xmlWriter.WriteEndElement()

        writer.Flush()

        Dim body As String = sb.ToString.Replace(" />", "/>")
        Dim xml_bytes() As Byte = encoder.GetBytes(body)

        'SHA1 hash on XML string
        Dim sha1_crypto As SHA1CryptoServiceProvider = New SHA1CryptoServiceProvider
        Dim hash As String = BitConverter.ToString(sha1_crypto.ComputeHash(xml_bytes)).Replace("-", "")
        Dim hashed_content As String = hash.ToLower

        'assign values to hashing and header variables
        Dim m_method As String = "POST"
        Dim m_type As String = "application/xml"
        Dim m_time As String = DateTime.UtcNow.ToString("yyyy-MM-ddTHH:mm:ssZ")
        Dim m_hashData As String = m_method & vbLf & m_type & vbLf & hashed_content & vbLf & m_time & vbLf & _endPoint_Uri

        'Compute the HMAC and convert to a base64 hash
        Dim m_hmac_sha1 As HMAC = New HMACSHA1(Encoding.UTF8.GetBytes(_hmac))
        Dim m_hmac_data() As Byte = m_hmac_sha1.ComputeHash(Encoding.UTF8.GetBytes(m_hashData))
        Dim m_base64_hash As String = Convert.ToBase64String(m_hmac_data)

        Dim httpRequestMessage As HttpRequestMessageProperty
        Dim httpRequestMessageObject As Object = Nothing

        If request.Properties.TryGetValue(HttpRequestMessageProperty.Name, httpRequestMessageObject) Then

            httpRequestMessage = CType(httpRequestMessageObject, HttpRequestMessageProperty)
            httpRequestMessage.Headers("x-gge4-date") = m_time
            httpRequestMessage.Headers("x-gge4-content-sha1") = hashed_content
            httpRequestMessage.Headers("Authorization") = "GGE4_API " & _keyID & ":" & m_base64_hash

        Else

            httpRequestMessage = New HttpRequestMessageProperty
            httpRequestMessage.Headers("x-gge4-date") = m_time
            httpRequestMessage.Headers("x-gge4-content-sha1") = hashed_content
            httpRequestMessage.Headers("Authorization") = "GGE4_API " & _keyID & ":" & m_base64_hash
            request.Properties.Add(HttpRequestMessageProperty.Name, httpRequestMessage)

        End If

        Return Nothing

    End Function

Issue 3:

My Transmit Code, I'm quite sure I got this right this time. I made a Service Reference, and not a web reference this time. I sort of used the same code I used for paypal, but added the endpoint behavior, so the authentication header would be added in the Soap Request.
VB
Using client = New ServiceSoapClient(New BasicHttpsBinding(), remoteAddress)
                client.ChannelFactory.Endpoint.EndpointBehaviors.Add(New HMAC_SR_Header_Behavior(
                        uRequest.eXact.HMAC_ID,
                        uRequest.eXact.HMAC_Key,
                        m_endpointUri
                    )
                )

                Dim responseType As New TransactionResult
                responseType = client.SendAndCommit(ppRequest)
                ppResponse = responseType

            End Using

FYI:
The FirstData support site was useless. All they do there is mobile stuff, Perl, Ruby, Rest. I got crickets from the site, and deaf ears.

[edited] took my personal information out

modified 30-Jun-15 12:47pm.

AnswerRe: FirstData G4 V14 HMAC Header Pin
Jörgen Andersson29-Jun-15 20:17
professionalJörgen Andersson29-Jun-15 20:17 
GeneralRe: FirstData G4 V14 HMAC Header Pin
jkirkerx30-Jun-15 6:49
professionaljkirkerx30-Jun-15 6:49 
GeneralConclusion - XMLWriter, UTF16 and XML empty element short form. Pin
jkirkerx5-Jul-15 8:54
professionaljkirkerx5-Jul-15 8:54 
AnswerRe: FirstData G4 V14 HMAC Header - Issue 1: Pin
jkirkerx30-Jun-15 11:10
professionaljkirkerx30-Jun-15 11:10 
GeneralUpdate - got the calc to work now with the request message Pin
jkirkerx1-Jul-15 7:38
professionaljkirkerx1-Jul-15 7:38 
AnswerCan't get the hashed content right Pin
jkirkerx1-Jul-15 12:39
professionaljkirkerx1-Jul-15 12:39 
QuestionExecute multiple sql queries with one database hit Pin
satc27-Jun-15 19:53
satc27-Jun-15 19:53 
AnswerRe: Execute multiple sql queries with one database hit Pin
Sascha Lefèvre27-Jun-15 22:04
professionalSascha Lefèvre27-Jun-15 22:04 
GeneralRe: Execute multiple sql queries with one database hit Pin
satc27-Jun-15 22:49
satc27-Jun-15 22:49 
GeneralRe: Execute multiple sql queries with one database hit Pin
Sascha Lefèvre27-Jun-15 23:15
professionalSascha Lefèvre27-Jun-15 23:15 
GeneralRe: Execute multiple sql queries with one database hit Pin
satc27-Jun-15 23:28
satc27-Jun-15 23:28 
GeneralRe: Execute multiple sql queries with one database hit Pin
Sascha Lefèvre28-Jun-15 1:11
professionalSascha Lefèvre28-Jun-15 1:11 
GeneralRe: Execute multiple sql queries with one database hit Pin
Dave Kreskowiak28-Jun-15 2:17
mveDave Kreskowiak28-Jun-15 2:17 
GeneralRe: Execute multiple sql queries with one database hit Pin
satc28-Jun-15 2:20
satc28-Jun-15 2:20 
GeneralRe: Execute multiple sql queries with one database hit Pin
Dave Kreskowiak28-Jun-15 10:40
mveDave Kreskowiak28-Jun-15 10:40 
GeneralRe: Execute multiple sql queries with one database hit Pin
Dave Kreskowiak28-Jun-15 2:09
mveDave Kreskowiak28-Jun-15 2:09 
GeneralRe: Execute multiple sql queries with one database hit Pin
satc28-Jun-15 2:12
satc28-Jun-15 2:12 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.