Just nu i M3-nätverket
Jump to content

Överättning av vb kod till C#


Richard Hellstenius

Recommended Posts

Richard Hellstenius

Halloj!

 

Jag har ett problem med en webservice som jag fått exempelkod till för anrop där exempelkoden är skriven i vb.

 

Jag tänkte då be någon vänlig själ här som är kung på programmering med hjälp av att översätta denna kod till c#. Gärna så utförligt som möjligt. Här kommer koden:

 

Dim objWsOrder_test As New wsOrder_test.clsWsOrder

 

' create an order object.

Dim objOrder As New wsOrder_test.Order1_1

 

' the object for the response from the order sending webservice

Dim objReturn As New wsOrder_test.Response

 

' create the order header

objOrder.oOrderH = New wsOrder_test.OrderHeader1_1

 

 

' declare the array for the order rows.

 

ReDim objOrder.oOrderR(0)

objOrder.oOrderR(0) = New wsOrder_test.OrderRows1_1

 

With objOrder.oOrderR(0)

.iOrderLineNumber = 1

.sEANArticleNumber = 1823912830

.sBPArticleNumber = "40700085"

.iNumberOfArticle = 2

.dReceiverPriceAtSender = 1500

End With

 

Try

' the documentation says that a security token is needed. create this.

Dim objSecTok As New wsOrder_test.SecurityToken

' values for test webservice, identify the customer.

objSecTok.customerNo = "" ' ert kundnr

objSecTok.password = "TEST"

objWsOrder_test.SecurityTokenValue = objSecTok

objReturn = objWsOrder_test.SendBPeDI(objOrder)

Catch ex As Exception

MsgBox(ex.ToString)

Exit Sub

End Try

 

' check what went wrong, if something went wrong, bError is true

If objReturn.bError = True Then

MsgBox("Error!")

Dim i As Integer

For i = 0 To UBound(objReturn.aField)

' show which field was wrong, which error code and then call the getErrorDescription function

' to get a description of the error.

MsgBox(objReturn.aErrorCode(i) & " " & objReturn.aField(i) & " - " & objWsOrder_test.GetErrorDescription(objReturn.aErrorCode(i)))

Next

Else

MsgBox("Success! Well done!")

End If

 

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.



×
×
  • Create New...