Skip to main content

AccessTr.neT


Xml Web Servisi Soap Sorgu İle Veri Transferi

Xml Web Servisi Soap Sorgu İle Veri Transferi

#5
    On Error GoTo ErrorHandler
   
    Dim xmlHttp As Object, xmlDoc As Object, xmlNodes As Object, node As Object
    Dim soapReq As String, soapResp As String
    Dim db As DAO.Database
    Dim tbl As DAO.Recordset
    Dim yil As String, ay As String, YakitTipi As String

    yil = Me.epSenesi.Value
    ay = Me.epAyi.Value
    YakitTipi = "Motorin"

    Set db = CurrentDb
    Set tbl = db.OpenRecordset("TbEpdk", dbOpenDynaset)

    'SOAP isteğini tanımlama
    Set xmlHttp = CreateObject("MSXML2.ServerXMLHTTP.6.0")
   
    soapReq = _
        "<?xml version=""1.0"" encoding=""utf-8""?>" & _
        "<soapenv:Envelope xmlns:soapenv=""http://schemas.xmlsoap.org/soap/envelope/"" xmlns:gen=""http://genel.service.ws.epvys.g222.tubitak.gov.tr/"">" & _
        "   <soapenv:Header/>" & _
        "   <soapenv:Body>" & _
        "      <gen:genelSorgu>" & _
        "         <sorguNo>71</sorguNo>" & _
        "         <parametreler>" & Format(yil, "yyyy") & "/" & Format(ay, "mm") & "</parametreler>" & _
        "      </gen:genelSorgu>" & _
        "   </soapenv:Body>" & _
        "</soapenv:Envelope>"
   
    'SOAP isteğini gönderme
    With xmlHttp
        .Open "POST", "https://lisansws.epdk.org.tr/services/bildirimPetrol8FirmaBulten.bildirimPetrol8FirmaBultenHttpSoap11Endpoint", False
        .setRequestHeader "Content-Type", "text/xml; charset=utf-8"
        .setRequestHeader "SOAPAction", "genelSorgu"
        .Send soapReq
    End With
   
    soapResp = xmlHttp.responseText
   
    Set xmlDoc = CreateObject("MSXML2.DOMDocument.6.0")
    xmlDoc.LoadXML soapResp
    xmlDoc.async = False

    Set xmlNodes = xmlDoc.getElementsByTagName("PetrolPiyasasiEnYuksekHacimliSekizFirmaninAkaryakitFiyatlari")
    For Each node In xmlNodes
        If node.SelectSingleNode("YakitTipi").Text = YakitTipi Then
            tbl.AddNew
            tbl!Fiyat = node.SelectSingleNode("Fiyat").Text
            tbl!Senesi = Format(yil, "yyyy")
            tbl!Ayi = Format(ay, "mm")
            tbl.Update
        End If
    Next node

    'MsgBox "Veriler başarıyla alındı ve tabloya kaydedildi.", vbInformation
   
    tbl.Close
    Set tbl = Nothing
    Set db = Nothing
    Set xmlHttp = Nothing
    Set xmlDoc = Nothing
    Exit Sub

ErrorHandler:
    MsgBox "Hata oluştu: " & Err.Description, vbCritical
benzeri bir kod deneyebilirsiniz. Kısa bir aralıkta bakmaya çalıştım fakat servis çalışmıyor hatası alıyorum ve servisleri vs inceleyecek fırsatım olmadı ne yazık ki ama konuda sürüncemede kalmasın diyerek en azından size fikir vermesi açısından paylaşmış olayım. Ancak belirttiğim gibi Soap sorgusu kulllanılan web servislerinde genel olarak isteğin doğrudan tarayıcı veya belirli bir istemci dışında yapılması engellenir bu nedenle Vba ile sonuç alamama ihtimaliniz var.
Cevapla

Bir hesap oluşturun veya yorum yapmak için giriş yapın

Yorum yapmak için üye olmanız gerekiyor

ya da

Bu Konudaki Yorumlar
RE: Xml Web Servisi Soap Sorgu İle Veri Transferi - Yazar: atoykan - 15/11/2024, 10:45
Task