Как сделать мыльный клиент, использующий библиотеку gowsdl, для вызова протокола службы поддержки мыла? - PullRequest
0 голосов
/ 06 мая 2019

Я использую библиотеку https://github.com/hooklift/gowsdl, чтобы создать мыльный клиент для вызова службы и получения ответа от этой службы. Сервер http://www.dneonline.com/calculator.asmx?wsdl

Я использую расширение Wizdler в Chrome для просмотра конечной точки, действия мыла и поддерживаемого метода http.

enter image description here

Запрос XML

enter image description here

Ответ XML

enter image description here

/ SRC / soap_client.go

package src

import (
    "encoding/xml"
    "github.com/hooklift/gowsdl/soap"
)

type AddRequest struct {
    XMLName xml.Name `xml:"http://www.dneonline.com/calculator.asmx Calculator.CalculatorSoap"`

    IntA int `xml:"intA"`
    IntB int `xml:"intB"`
}

type AddResponse struct {
    XMLName xml.Name `xml:"http://www.dneonline.com/calculator.asmx Calculator.CalculatorSoap"`

    AddResponse AddResult `xml:"AddResponse"`
}

type AddResult struct {
    AddResult int `xml:"AddResult"`
}

type ISoapClient interface {
    Add(request *AddRequest) (*AddResponse, error)
}

type SoapClient struct {
    client *soap.Client
}

func NewSoapClient(client *soap.Client) *SoapClient {
    return &SoapClient{
        client: client,
    }
}

func (sap *SoapClient) Add(request *AddRequest) (*AddResponse, error) {
    response := new(AddResponse)
    err := sap.client.Call("Add", request, response)
    if err != nil {
        return nil, err
    }

    return response, nil
}

main.go

package main

import (
    "awesomeProject/src"
    "fmt"
    "github.com/hooklift/gowsdl/soap"
)

func main() {
    client := soap.NewClient(
        "http://www.dneonline.com/calculator.asmx",
    )
    request := src.AddRequest{
        IntA: 1,
        IntB: 1,
    }
    service := src.NewSoapClient(client)
    res, err := service.Add(&request)

    if err != nil {
        fmt.Println(err)
        return
    }

    fmt.Print(res.AddResponse)
}

Я хочу использовать действие Add в Calculator Конечной точке этой службы. Поэтому я попытался sap.client.Call("<name_of_action>", request, response), но не работает. Как правильно сделать? Спасибо

Ошибка при вызове этого кода выше:

System.Web.Services.Protocols.SoapException: сервер не распознал значение HTTP-заголовка SOAPAction: Добавить. в System.Web.Services.Protocols.Soap11ServerProtocolHelper.RouteRequest () в System.Web.Services.Protocols.SoapServerProtocol.RouteRequest (SoapServerMessage сообщение) в System.Web.Services.Protocols.SoapServerProtocol.Initialize () в System.Web.Services.Protocols.ServerProtocol.SetContext (Type type, Контекст HttpContext, запрос HttpRequest, ответ HttpResponse) в System.Web.Services.Protocols.ServerProtocolFactory.Create (Type type, Контекст HttpContext, запрос HttpRequest, ответ HttpResponse, Boolean & abortProcessing)

...