यह देखते हुए कि एडवर्ड्स एक Google चीज है, और गो एक Google बात है, कब तक गो में लिखे गए एडवर्ड्स एपीआई का एक संस्करण है?गो में एसओएपी कॉल कैसे करें?
उस प्रश्न के साथ संबद्ध, दूसरा: क्या अभी तक कोई एसओएपी पुस्तकालय हैं?
यह देखते हुए कि एडवर्ड्स एक Google चीज है, और गो एक Google बात है, कब तक गो में लिखे गए एडवर्ड्स एपीआई का एक संस्करण है?गो में एसओएपी कॉल कैसे करें?
उस प्रश्न के साथ संबद्ध, दूसरा: क्या अभी तक कोई एसओएपी पुस्तकालय हैं?
Google APIs for Go एक काम प्रगति पर है।
मुझे अभी तक AdWords का कोई उल्लेख नहीं दिख रहा है। क्या आप वाकई वर्तमान Google एपीआई द्वारा कवर किया गया है? – Timm
मैं ऐडवर्ड्स एपीआई के बारे में जवाब दे सकता हूं क्योंकि मैंने कंपनी से कोई घोषणा नहीं की है और रिलीज से पहले समय की भविष्यवाणी करने से पहले ही बाहर से किया जा सकता है।
तो मैं आपके दूसरे प्रश्न का उत्तर दूंगा।
मैं जाओ में किसी भी सोप पुस्तकालय पता नहीं है (go-lang.cat-v.org एक संदर्भ के लिए प्रतीत नहीं होता है), लेकिन अधिकांश भाषाओं में के रूप में, सरल SOAP संदेश से निपटने के लिए एक तरह से बुनियादी http और xml पुस्तकालयों का उपयोग करने के लिए है।
parser := xml.NewDecoder(bytes.NewBufferString(in))
err = parser.DecodeElement(&envelope, nil)
:
resp, err := httpClient.Post(query, "text/xml; charset=utf-8", someXMLasBytes)
2) वांछित संरचना में एक xml.NewDecoder
का उपयोग कर इसे डिकोड करने के लिए:
दो महत्वपूर्ण कार्यों के एक पोस्ट क्वेरी करके उसका उत्तर मिल
1) कर रहे हैं
यहां गो (simplified from this) में किए गए एक SOAP क्वेरी का एक पूर्ण और टिप्पणी किया गया उदाहरण है:
package main
import (
"bytes"
"encoding/xml"
"fmt"
"io"
"io/ioutil"
"net/http"
"strings"
)
// The URL of the SOAP server
const MH_SOAP_URL = "http://sp.mountyhall.com/SP_WebService.php"
// this is just the message I'll send for interrogation, with placeholders
// for my parameters
const SOAP_VUE_QUERY_FORMAT = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?><SOAP-ENV:Envelope xmlns:SOAP-ENV=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:tns=\"urn:SP_WebService\" xmlns:soap=\"http://schemas.xmlsoap.org/wsdl/soap/\" xmlns:wsdl=\"http://schemas.xmlsoap.org/wsdl/\" xmlns:SOAP-ENC=\"http://schemas.xmlsoap.org/soap/encoding/\" ><SOAP-ENV:Body><mns:Vue xmlns:mns=\"uri:mhSp\" SOAP-ENV:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\"><numero xsi:type=\"xsd:string\">%d</numero><mdp xsi:type=\"xsd:string\">%s</mdp></mns:Vue></SOAP-ENV:Body></SOAP-ENV:Envelope>"
// Here I define Go structures, almost identical to the structure of the
// XML message we'll fetch
// Note that annotations (the string "return>item") allow to have a slightly
// different structure or different namings
type SoapItem struct {
Numero int
Nom string
Type string
PositionX int
PositionY int
PositionN int
Monde int
}
type SoapVue struct {
Items []SoapItem "return>item"
}
type SoapFault struct {
Faultstring string
Detail string
}
type SoapBody struct {
Fault SoapFault
ProfilResponse SoapProfil
VueResponse SoapVue
}
type SoapEnvelope struct {
XMLName xml.Name
Body SoapBody
}
// Here is the function querying the SOAP server
// It returns the whole answer as a Go structure (a SoapEnvelope)
// You could also return an error in a second returned parameter
func GetSoapEnvelope(query string, numero int, mdp string) (envelope *SoapEnvelope) {
soapRequestContent := fmt.Sprintf(query, numero, mdp)
httpClient := new(http.Client)
resp, err := httpClient.Post(MH_SOAP_URL, "text/xml; charset=utf-8", bytes.NewBufferString(soapRequestContent))
if err != nil {
// handle error
}
b, e := ioutil.ReadAll(resp.Body) // probably not efficient, done because the stream isn't always a pure XML stream and I have to fix things (not shown here)
if e != nil {
// handle error
}
in := string(b)
parser := xml.NewDecoder(bytes.NewBufferString(in))
envelope = new(SoapEnvelope) // this allocates the structure in which we'll decode the XML
err = parser.DecodeElement(&envelope, nil)
if err != nil {
// handle error
}
resp.Body.Close()
return
}
उपर्युक्त उदाहरण में आप हार्डकोडेड एक्सएमएल का उपयोग कर रहे हैं, वहां कोई पैकेज है जहां हम साबुन एक्सएमएल – user2383973
उत्पन्न कर सकते हैं। मैं उस टेम्पलेट को हार्डकोडेड एक्सएमएल से अधिक एक्सएमएल जेनरेट करता हूं। आप एन्कोडिंग/एक्सएमएल के साथ एक्सएमएल जेनरेट करने का प्रयास कर सकते हैं, लेकिन आपको जल्दी ही पता चलेगा कि हर सर्वर कुछ अलग चाहता है, इसलिए मेरे अनुभव में कम से कम आप एक्सएमएल के साथ मैन्युअल रूप से झुकाव से बेहतर हो जाते हैं जब तक आप सर्वर को जवाब देने के लिए नहीं मिलता आप लाइब्रेरी को इसके लिए जेनरेट करने के बजाय और लाइब्रेरी को ट्विक करने के बजाए बस इसे हार्डकोड करना चाहते हैं, जब तक कि यह लगातार उत्पन्न न हो जाए। – semi
मैं आसानी से http और xml संकुल का उपयोग करके एसओएपी कॉल कर सकता हूं। –
@dystroy: आप एक अच्छा मुद्दा बनाते हैं। हालांकि, मैं अभी गो में शुरू कर रहा हूं, इसलिए यह अभी तक एक समाधान नहीं है। – bugmagnet
क्या आप मुझे विस्तार से (उत्तर में) जाना चाहते हैं कि गो में आसानी से एसओएपी कॉल कैसे करें? –