Вопрос

So the XML request string I pass into Savon client.call is as below (note this works and I get a response):

<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:tem="http://tempuri.org/" 
xmlns:mun="http://schemas.datacontract.org/2004/07/External.Service.Bo">
   <soap:Header/>
   <soap:Body>
      <tem:GetInformationsForCoordinates>
         <tem:coordReq>
            <mun:Coordinates>
               <mun:Coordinate>
                  <mun:Id>1</mun:Id>
                  <mun:QualityIndex>90</mun:QualityIndex>
                  <mun:X>-110.5322</mun:X>
                  <mun:Y>35.2108</mun:Y>
               </mun:Coordinate>
            </mun:Coordinates>
         </tem:coordReq>
         <tem:analysisTypes>
            <mun:AnalysisType>Additional</mun:AnalysisType>
         </tem:analysisTypes>
      </tem:GetInformationsForCoordinates>
   </soap:Body>
</soap:Envelope>

Rather than pass that in as xml which isn't really feasible I want to pass a message so I can add multiple (possibly an array of co-ordinates), multiple analysis types easily etc.

Ruby code I have to do this so far is:

  coordinate = { Id: '1', QualityIndex: 90, X: -110.5322, Y: 35.2108}
  coordinates = {Coordinates: [coordinate] }
  coordinateReq = {coordReq: {coordinates: coordinates} }

I then pass coordinateReq to client.call - I can see in Ruby console the request below generated:

<env:Envelope xmlns:env="http://www.w3.org/2003/05/soap-envelope" xmlns:tns="http://tempuri.org/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <env:Body>
    <tns:GetInformationsForCoordinates>
      <coordReq>
        <coordinates>
          <Coordinates>
            <Id>1</Id>
            <QualityIndex>90</QualityIndex>
            <X>-110.5322</X>
            <Y>35.2108</Y>
          </Coordinates>
        </coordinates>
      </coordReq>
    </tns:GetInformationsForCoordinates>
  </env:Body>
</env:Envelope>

There are a few problems - is there a way I can add the namespance mun to the correct attributes similar to my string off XML (i.e Id/QualityIndex, etc). Also in my example with Ruby code coordinates is in lower case and then Coordinates is uppercase whilst it should be uppercase but not plural. Finally then I need to include analysisTypes (note lowercase a uppercase T) and then AnalysisType off which there could be multiple to the request and AnalysisType also needs the mun namespace.

Это было полезно?

Решение

instead of a symbol like

QualityIndex: 90

you need to specify a string like

'mun:QualityIndex' => 90

Другие советы

Worked as expected using Steffen answer - only thing to note was as I mentioned in my comment I did have to add the namespace as shown below (just in case anyone else comes across this question:

  namespaces = {
    "xmlns:mun" => "http://schemas.datacontract.org/2004/07/External.Service.Bo"
  }

and then in Savon.client the following (note the namespaces line is the key one:

 client = Savon.client(wsdl: WSDL_URL,
                        log: true, # set to true to switch on logging
                        namespaces: namespaces,
                        #etc more config set up
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top