SOAP Mesajı İçerisindeki ID Referans Sorununu Çözme
Bazı .net servislerinde istek veya cevap bazen gerçekte istediklerinden farklı olabiliyor.
Bu işlem ile bu istek mesajı düzenlenerek gönderilir.
Örnek Giriş Değeri
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:tns="http://sicil.webservices2.vedop2.ggm.gov.tr" xmlns:types="http://sicil.webservices2.vedop2.ggm.gov.tr/encodedTypes" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<soap:Body soap:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<tns:merkezBilgileriDetayTCKN>
<tckn xsi:type="xsd:string">xxx</tckn>
<kullaniciBilgi href="#id1"/>
</tns:merkezBilgileriDetayTCKN>
<q1:WSInfo id="id1" xsi:type="q1:WSInfo" xmlns:q1="http://webservices2.vedop2.ggm.gov.tr">
<girisKod xsi:nil="true"/>
<girisSifre xsi:nil="true"/>
<istekZaman xsi:nil="true"/>
<kullaniciIP xsi:nil="true"/>
<kullaniciKod>xx</kullaniciKod>
<kurumAd>xxxx</kurumAd>
<macAdres xsi:nil="true"/>
</q1:WSInfo>
</soap:Body>
</soap:Envelope>
XML
XSLT Dönüşüm Kodu
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:soapenv="http://schemas.xmlsoap.org/soap/encoding/" >
<xsl:key name="multiref-by-id" match="q1:WSInfo" xmlns:q1="http://webservisadresi.com" use="@id"/>
<xsl:template match="/">
<xsl:copy>
<xsl:apply-templates select="@*|*"/>
</xsl:copy>
</xsl:template>
<xsl:template match="*[starts-with(@href, '#')]">
<xsl:copy>
<xsl:apply-templates select="@* |
key('multiref-by-id', substring-after(@href, '#'))/@* |
key('multiref-by-id', substring-after(@href, '#'))/node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="@href[starts-with(., '#')] | q1:WSInfo[@id] | @soapenv:root" xmlns:q1="http://webservisadresi.com" />
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
XML
Örnek Çıkış Değeri
<?xml version="1.0" encoding="UTF-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:tns="http://xAdresi.com" xmlns:types="http://xAdresi.com/encodedTypes" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<soap:Body soap:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<tns:birMetotAdi>
<tckn xsi:type="xsd:string">xxx</tckn>
<kullaniciBilgi id="id1" xsi:type="q1:WSInfo">
<girisKod xmlns:q1="http://webservisadresi.com" xsi:nil="true"/>
<kullaniciIP xmlns:q1="http://webservisadresi.com" xsi:nil="true"/>
<kullaniciKod xmlns:q1="http://webservisadresi.com">xx</kullaniciKod>
<kurumAd xmlns:q1="http://webservisadresi.com">xxxx</kurumAd>
<macAdres xmlns:q1="http://webservisadresi.com" xsi:nil="true"/>
</kullaniciBilgi>
</tns:birMetotAdi>
</soap:Body>
</soap:Envelope>
XML
Benzer şekilde aynı işlem namespace'siz yapılmak istenirse aşağıdaki örnek kullanılabilir:
Örnek Giriş Değeri
<?xml version="1.0" encoding="UTF-8"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soapenv:Body>
<ns1:anaMetotAdiSorgulaResponse soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns:ns1="http://someAddress.com">
<anaMetotAdiSorgulaReturn href="#id0"/>
</ns1:anaMetotAdiSorgulaResponse>
<multiRef id="id0" soapenc:root="0" soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xsi:type="ns2:birMetotAdiBilgisi" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:ns2="http://someAddress.com">
<xTablosu soapenc:arrayType="ns2:birBaskaMetotAdiBilgisi[1]" xsi:type="soapenc:Array">
<xTablosu href="#id1"/>
</xTablosu>
<yTablosu soapenc:arrayType="ns2:birBaskaMetotAdiBilgisi[1]" xsi:type="soapenc:Array">
<yTablosu href="#id2"/>
</yTablosu>
<referanssizBirAlan xsi:type="ns2:referanssizBirAlan" xsi:nil="true"/>
</multiRef>
<multiRef id="id1" soapenc:root="0" soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xsi:type="ns4:birBaskaMetotAdiBilgisi" xmlns:ns4="http://someAddress.com" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/">
<aciklama xsi:type="xsd:string">Birtakım açıklamalar</aciklama>
<deger xsi:type="xsd:string">1033.65</deger>
<tip xsi:type="xsd:string">4</tip>
<unvan xsi:type="xsd:string" xsi:nil="true"/>
</multiRef>
<multiRef id="id2" soapenc:root="0" soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xsi:type="ns5:birBaskaMetotAdiBilgisi" xmlns:ns5="http://someAddress.com" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/">
<aciklama xsi:type="xsd:string">Bazı açıklamalar</aciklama>
<deger xsi:type="xsd:string">361.21</deger>
<tip xsi:type="xsd:string">3</tip>
<unvan xsi:type="xsd:string" xsi:nil="true"/>
</multiRef>
</soapenv:Body>
</soapenv:Envelope>
XML
XSLT Dönüşüm Kodu
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:soapenv="http://schemas.xmlsoap.org/soap/encoding/">
<xsl:key name="multiref-by-id" match="multiRef" use="@id"/>
<xsl:template match="/">
<xsl:copy>
<xsl:apply-templates select="@*|*"/>
</xsl:copy>
</xsl:template>
<xsl:template match="*[starts-with(@href, '#')]">
<xsl:copy>
<xsl:apply-templates select="@* |
key('multiref-by-id', substring-after(@href, '#'))/@* |
key('multiref-by-id', substring-after(@href, '#'))/node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="@href[starts-with(., '#')] | multiRef[@id] | @soapenv:root"/>
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
XML
Örnek Çıkış Değeri
<?xml version="1.0" encoding="UTF-8"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soapenv:Body>
<ns1:anaMetotAdiSorgulaResponse xmlns:ns1="http://someAddress.com" soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<anaMetotAdiSorgulaReturn id="id0" soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xsi:type="ns2:birMetotAdiBilgisi">
<xTablosu xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:ns2="http://someAddress.com" soapenc:arrayType="ns2:birBaskaMetotAdiBilgisi[1]" xsi:type="soapenc:Array">
<xTablosu id="id1" soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xsi:type="ns4:birBaskaMetotAdiBilgisi">
<aciklama xmlns:ns4="http://someAddress.com" xsi:type="xsd:string">Birtakım açıklamalar</aciklama>
<deger xmlns:ns4="http://someAddress.com" xsi:type="xsd:string">1033.65</deger>
<tip xmlns:ns4="http://someAddress.com" xsi:type="xsd:string">4</tip>
<unvan xmlns:ns4="http://someAddress.com" xsi:type="xsd:string" xsi:nil="true"/>
</xTablosu>
</xTablosu>
<yTablosu xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:ns2="http://someAddress.com" soapenc:arrayType="ns2:birBaskaMetotAdiBilgisi[1]" xsi:type="soapenc:Array">
<yTablosu id="id2" soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xsi:type="ns5:birBaskaMetotAdiBilgisi">
<aciklama xmlns:ns5="http://someAddress.com" xsi:type="xsd:string">Bazı açıklamalar</aciklama>
<deger xmlns:ns5="http://someAddress.com" xsi:type="xsd:string">361.21</deger>
<tip xmlns:ns5="http://someAddress.com" xsi:type="xsd:string">3</tip>
<unvan xmlns:ns5="http://someAddress.com" xsi:type="xsd:string" xsi:nil="true"/>
</yTablosu>
</yTablosu>
<referanssizBirAlan xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:ns2="http://someAddress.com" xsi:type="ns2:referanssizBirAlan" xsi:nil="true"/>
</anaMetotAdiSorgulaReturn>
</ns1:anaMetotAdiSorgulaResponse>
</soapenv:Body>
</soapenv:Envelope>
XML