douxing9567 2017-11-15 06:26
浏览 331
已采纳

用gowsdl进行SOAP调用

I am using gowsdl to consume a SOAP request in Go. I got WSDL and generated the code using that. In the auto-generated code, it generated stub and some code snippets are mentioned below.

  1. I have to make a SOAP call and have to pass GetAllPersons struct as an input to the service. Please help me how do we do that? I have the request xml but dont know how to update that in GetAllPersons struct?

    persons, err := service.GetAllPersons(request)
    
    type GetAllPersons struct {
        XMLName xml.Name `xml:"http://service.jaxws.journaldev.com getAllPersons"`
    }
    
  2. And as per Go specification, a variable is declared using the sybtax VariableName Type. What is the 3rd value xml:"http://service.jaxws.journaldev.com getAllPersons" in above struct?

  • 写回答

1条回答 默认 最新

  • dsjmrpym220113739 2017-11-22 05:26
    关注

    Below is the code that I figured out to get things done with the code generated by gowsdl.

    main(){
        basicauth := personService.BasicAuth{"",""}
        service := personService.NewPersonServiceImpl("", false, &basicauth)
    
        persons, err := service.GetAllPersons(&personService.GetAllPersons{})
    
        if err != nil {
            panic(err)
        }
        fmt.Println(persons)
        fmt.Printf("Alive?: %t
    ", persons.GetAllPersonsReturn[0].Name)
        fmt.Printf("Alive?: %t
    ", persons.GetAllPersonsReturn[1].Name)
        fmt.Printf("Alive?: %t
    ", persons.GetAllPersonsReturn[0].Id)
        fmt.Printf("Alive?: %t
    ", persons.GetAllPersonsReturn[1].Id)
        fmt.Printf("Alive?: %t
    ", persons.GetAllPersonsReturn[0].Age)
        fmt.Printf("Alive?: %t
    ", persons.GetAllPersonsReturn[1].Age)
        fmt.Printf(persons.GetAllPersonsReturn[0].Name)
    
        request := &personService.AddPerson{P: &personService.Person{Age: 24, Name: "Govinda", Id: 55555555}}
        trial, err := service.AddPerson(request)
        if err != nil {
            panic(err)
        }
    }
    

    For the 2nd question, thanks to Volker for mentioning the answer in comments. These strings after the type are called tags (see golang.org/ref/spec#Struct_types) and are used typically during (un)marshalling from serialisation formats like xml

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 下图接收小电路,谁知道原理
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭
  • ¥15 2020长安杯与连接网探