问题在ruby中使用Savon gem发送SOAP请求

时间:2013-04-15 01:31:45

标签: ruby ruby-on-rails-3 soap soapui savon

我正在使用Savon gem与一家名为vertex的税务公司的soap api进行沟通。 api端点可以在https://sandbox.ondemand.vertexinc.com/vertex-ws/listVertexServices.jsp找到。

由于一些SSL问题,我不得不将http适配器切换为使用curb。以下是我要提出的请求的代码:

class Tax
  HTTPI.adapter = :curb

  def self.lookup_tax_areas
    client = Savon.client(wsdl: "https://sandbox.ondemand.vertexinc.com:443/vertex-ws/services/LookupTaxAreas60?wsdl")
    response = client.call(:lookup_tax_areas60, xml: LOOKUPTAX)
  end

end

我收到以下错误消息:

Tax.lookup_tax_areas

  HTTPI GET request to sandbox.ondemand.vertexinc.com (curb)
  SOAP request: https://sandbox.ondemand.vertexinc.com/vertex-ws/services/LookupTaxAreas60
  SOAPAction: "LookupTaxAreas60", Content-Type: text/xml;charset=UTF-8, Content-Length: 676
<?xml version='1.0' encoding='UTF-8'?>
<!-- Sample Request for the Tax Areas Lookup Web Service -->
  <VertexEnvelope xmlns='urn:vertexinc:o-series:tps:6:0'
   xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'>
<Login>
  <UserName>name</UserName>
    <Password>password</Password>
</Login>
<TaxAreaRequest>
<TaxAreaLookup asOfDate='2008-01-01'>
  <PostalAddress>
    <City>HUNTSVILLE</City>
    <MainDivision>AL</MainDivision>
    <SubDivision>MADISON</SubDivision>
    <PostalCode>35801</PostalCode>
    <Country>USA</Country>
  </PostalAddress>
 </TaxAreaLookup>
</TaxAreaRequest>
</VertexEnvelope>

HTTPI POST request to sandbox.ondemand.vertexinc.com (curb)
SOAP response (status 500)
<?xml version='1.0' encoding='UTF-8'?><S:Envelope  xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">

<S:Body><S:Fault xmlns:ns4="http://www.w3.org/2003/05/soap-envelope">
<faultcode>S:Client</faultcode>  <faultstring>Couldn't create SOAP message due to 
exception: unexpected XML tag. expected: 
{http://schemas.xmlsoap.org/soap/envelope/}Envelope but found: {urn:vertexinc:o-
series:tps:6:0}VertexEnvelope</faultstring></S:Fault></S:Body></S:Envelope>
Savon::SOAPFault: (S:Client) Couldn't create SOAP message due to exception: unexpected 
XML tag. expected: {http://schemas.xmlsoap.org/soap/envelope/}Envelope but found: 
{urn:vertexinc:o-series:tps:6:0}VertexEnvelope
from /lib/savon/response.rb:70:in `raise_soap_and_http_errors!'
from /lib/savon/response.rb:13:in `initialize'
from /lib/savon/operation.rb:53:in `new'
from /lib/savon/operation.rb:53:in `call'
from /lib/savon/client.rb:36:in `call'
from /app/models/tax.rb:7:in `lookup_tax_areas'

使用SOAP UI,我得到的请求消息相当长,但这是一个缩减版本:

 <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"  xmlns:urn="urn:vertexinc:o-series:tps:6:0">
<soapenv:Header/>
<soapenv:Body>
  <urn:VertexEnvelope>
     <urn:Login>
        <!--Optional:-->
        <urn:UserName>test</urn:UserName>
        <!--Optional:-->
        <urn:Password>test</urn:Password>
        <!--Optional:-->
        <urn:TrustedId>?</urn:TrustedId>
     </urn:Login>
     <!--You have a CHOICE of the next 46 items at this level-->
     <urn:AccrualRequest documentNumber="?" postingDate="?" locationCode="?" returnAssistedParametersIndicator="?" returnGeneratedLineItemsIndicator="?" deliveryTerm="?" documentDate="?" transactionId="?" transactionType="?" simplificationCode="?" recoverableDate="?" postToJournal="true">
        <!--Optional:-->
        <urn:Currency isoCurrencyName="?" isoCurrencyCodeAlpha="?" isoCurrencyCodeNum="?"/>
        <!--Optional:-->
        <urn:OriginalCurrency isoCurrencyName="?" isoCurrencyCodeAlpha="?" isoCurrencyCodeNum="?"/>
        <!--Optional:-->
        <urn:Buyer isTaxExempt="false" exemptionReasonCode="?">
           <!--Optional:-->
           <urn:Company>?</urn:Company>
           <!--Optional:-->
           <urn:Division>?</urn:Division>
           <!--Optional:-->
           <urn:Department>?</urn:Department>
           <!--Optional:-->
           <urn:Recipient>
              <urn:RecipientCode classCode="?" isBusinessIndicator="?">?</urn:RecipientCode>
              <!--Zero or more repetitions:-->
              <urn:TaxRegistration isoCountryCode="?" mainDivision="?" hasPhysicalPresenceIndicator="?">
                 <!--Optional:-->
                 <urn:TaxRegistrationNumber>?</urn:TaxRegistrationNumber>
                 <!--0 to 4 repetitions:-->
                 <urn:NexusOverride locationRole="?" country="?" mainDivision="?" subDivision="?" city="?" district="?"/>
                 <!--Zero or more repetitions:-->
                 <urn:PhysicalLocation taxAreaId="?">
                    <!--Optional:-->
                    <urn:StreetAddress1>?</urn:StreetAddress1>
                    <!--Optional:-->
                    <urn:StreetAddress2>?</urn:StreetAddress2>
                    <!--Optional:-->
                    <urn:City>?</urn:City>
                    <!--Optional:-->
                    <urn:MainDivision>?</urn:MainDivision>
                    <!--Optional:-->
                    <urn:SubDivision>?</urn:SubDivision>
                    <!--Optional:-->
                    <urn:PostalCode>?</urn:PostalCode>
                    <!--Optional:-->
                    <urn:Country>?</urn:Country>
                 </urn:PhysicalLocation>
              </urn:TaxRegistration>
           </urn:Recipient>
           <!--Optional:-->
           <urn:Destination taxAreaId="?" locationCustomsStatus="?" locationCode="?" externalJurisdictionCode="?">
              <!--Optional:-->
              <urn:StreetAddress1>?</urn:StreetAddress1>
              <!--Optional:-->
              <urn:StreetAddress2>?</urn:StreetAddress2>
              <!--Optional:-->
              <urn:City>?</urn:City>
              <!--Optional:-->
              <urn:MainDivision>?</urn:MainDivision>
              <!--Optional:-->
              <urn:SubDivision>?</urn:SubDivision>
              <!--Optional:-->
              <urn:PostalCode>?</urn:PostalCode>
              <!--Optional:-->
              <urn:Country>?</urn:Country>
              <!--Optional:-->
              <urn:CurrencyConversion isoCurrencyName="?" isoCurrencyCodeAlpha="?" isoCurrencyCodeNum="?">?</urn:CurrencyConversion>
           </urn:Destination>
           <!--Optional:-->
           <urn:AdministrativeDestination taxAreaId="?" locationCustomsStatus="?" locationCode="?" externalJurisdictionCode="?">
              <!--Optional:-->
              <urn:StreetAddress1>?</urn:StreetAddress1>
              <!--Optional:-->
              <urn:StreetAddress2>?</urn:StreetAddress2>
              <!--Optional:-->
              <urn:City>?</urn:City>
              <!--Optional:-->
              <urn:MainDivision>?</urn:MainDivision>
              <!--Optional:-->
              <urn:SubDivision>?</urn:SubDivision>
              <!--Optional:-->
              <urn:PostalCode>?</urn:PostalCode>
              <!--Optional:-->
              <urn:Country>?</urn:Country>
              <!--Optional:-->
              <urn:CurrencyConversion isoCurrencyName="?" isoCurrencyCodeAlpha="?" isoCurrencyCodeNum="?">?</urn:CurrencyConversion>
           </urn:AdministrativeDestination>
           <!--Optional:-->
           <urn:ExemptionCertificate exemptionCertificateNumber="?">?</urn:ExemptionCertificate>
           <!--Zero or more repetitions:-->
           <urn:TaxRegistration isoCountryCode="?" mainDivision="?" hasPhysicalPresenceIndicator="?">
              <!--Optional:-->
              <urn:TaxRegistrationNumber>?</urn:TaxRegistrationNumber>
              <!--0 to 4 repetitions:-->
              <urn:NexusOverride locationRole="?" country="?" mainDivision="?" subDivision="?" city="?" district="?"/>
              <!--Zero or more repetitions:-->
              <urn:PhysicalLocation taxAreaId="?">
                 <!--Optional:-->
                 <urn:StreetAddress1>?</urn:StreetAddress1>
                 <!--Optional:-->
                 <urn:StreetAddress2>?</urn:StreetAddress2>
                 <!--Optional:-->
                 <urn:City>?</urn:City>
                 <!--Optional:-->
                 <urn:MainDivision>?</urn:MainDivision>
                 <!--Optional:-->
                 <urn:SubDivision>?</urn:SubDivision>
                 <!--Optional:-->
                 <urn:PostalCode>?</urn:PostalCode>
                 <!--Optional:-->
                 <urn:Country>?</urn:Country>
              </urn:PhysicalLocation>
           </urn:TaxRegistration>
        </urn:Buyer>
        <!--Optional:-->
           <!--Zero or more repetitions:-->
           <urn:TaxRegistration isoCountryCode="?" mainDivision="?" hasPhysicalPresenceIndicator="?">
              <!--Optional:-->
              <urn:TaxRegistrationNumber>?</urn:TaxRegistrationNumber>
              <!--0 to 4 repetitions:-->
              <urn:NexusOverride locationRole="?" country="?" mainDivision="?" subDivision="?" city="?" district="?"/>
              <!--Zero or more repetitions:-->
              <urn:PhysicalLocation taxAreaId="?">
                 <!--Optional:-->
                 <urn:StreetAddress1>?</urn:StreetAddress1>
                 <!--Optional:-->
                 <urn:StreetAddress2>?</urn:StreetAddress2>
                 <!--Optional:-->
                 <urn:City>?</urn:City>
                 <!--Optional:-->
                 <urn:MainDivision>?</urn:MainDivision>
                 <!--Optional:-->
                 <urn:SubDivision>?</urn:SubDivision>
                 <!--Optional:-->
                 <urn:PostalCode>?</urn:PostalCode>
                 <!--Optional:-->
                 <urn:Country>?</urn:Country>
              </urn:PhysicalLocation>
           </urn:TaxRegistration>
        </urn:Vendor>
        <!--1 or more repetitions:-->
        <urn:LineItem lineItemNumber="?" taxDate="?" isMulticomponent="?" locationCode="?" deliveryTerm="?" postingDate="?" costCenter="?" departmentCode="?" generalLedgerAccount="?" materialCode="?" projectNumber="?" usage="?" usageClass="?" vendorSKU="?" countryOfOriginISOCode="?" modeOfTransport="?" natureOfTransaction="?" intrastatCommodityCode="?" netMassKilograms="?" lineItemId="?" recoverableDate="?" titleTransfer="?" chainTransactionPhase="?">
           <!--Optional:-->
           <urn:Buyer isTaxExempt="false" exemptionReasonCode="?">
              <!--Optional:-->
              <urn:Company>?</urn:Company>
              <!--Optional:-->
              <urn:Division>?</urn:Division>
              <!--Optional:-->
              <urn:Department>?</urn:Department>
              <!--Optional:-->
              <urn:Recipient>
                 <urn:RecipientCode classCode="?" isBusinessIndicator="?">?</urn:RecipientCode>
                 <!--Zero or more repetitions:-->
                 <urn:TaxRegistration isoCountryCode="?" mainDivision="?" hasPhysicalPresenceIndicator="?">
                    <!--Optional:-->
                    <urn:TaxRegistrationNumber>?</urn:TaxRegistrationNumber>
                    <!--0 to 4 repetitions:-->
                    <urn:NexusOverride locationRole="?" country="?" mainDivision="?" subDivision="?" city="?" district="?"/>
                    <!--Zero or more repetitions:-->
                    <urn:PhysicalLocation taxAreaId="?">
                       <!--Optional:-->
                       <urn:StreetAddress1>?</urn:StreetAddress1>
                       <!--Optional:-->
                       <urn:StreetAddress2>?</urn:StreetAddress2>
                       <!--Optional:-->
                       <urn:City>?</urn:City>
                       <!--Optional:-->
                       <urn:MainDivision>?</urn:MainDivision>
                       <!--Optional:-->
                       <urn:SubDivision>?</urn:SubDivision>
                       <!--Optional:-->
                       <urn:PostalCode>?</urn:PostalCode>
                       <!--Optional:-->
                       <urn:Country>?</urn:Country>
                    </urn:PhysicalLocation>

     <urn:TaxAreaRequest>
        <!--Optional:-->
        <urn:TaxAreaLookup asOfDate="2008-01-01" lookupId="?">
           <!--You have a CHOICE of the next 3 items at this level-->
           <urn:TaxAreaId>?</urn:TaxAreaId>
           <urn:PostalAddress>
              <!--Optional:-->
              <urn:StreetAddress1>?</urn:StreetAddress1>
              <!--Optional:-->
              <urn:StreetAddress2>?</urn:StreetAddress2>
              <!--Optional:-->
              <urn:City>HUNTSVILLE</urn:City>
              <!--Optional:-->
              <urn:MainDivision>AL</urn:MainDivision>
              <!--Optional:-->
              <urn:SubDivision>MADISON</urn:SubDivision>
              <!--Optional:-->
              <urn:PostalCode>35801</urn:PostalCode>
              <!--Optional:-->
              <urn:Country>USA</urn:Country>
           </urn:PostalAddress>
           <urn:ExternalJurisdiction>
              <urn:ExternalJurisdictionCode>?</urn:ExternalJurisdictionCode>
              <urn:Country>?</urn:Country>
           </urn:ExternalJurisdiction>
        </urn:TaxAreaLookup>
     </urn:TaxAreaRequest>
     <urn:TaxAreaResponse>
        <!--Zero or more repetitions:-->
        <urn:TaxAreaResult taxAreaId="?" asOfDate="?" confidenceIndicator="?">
           <!--Zero or more repetitions:-->
           <urn:Jurisdiction jurisdictionLevel="?" jurisdictionId="?" effectiveDate="?" expirationDate="?" externalJurisdictionCode="?">?</urn:Jurisdiction>
           <!--Zero or more repetitions:-->
           <urn:PostalAddress>
              <!--Optional:-->
              <urn:StreetAddress1>?</urn:StreetAddress1>
              <!--Optional:-->
              <urn:StreetAddress2>?</urn:StreetAddress2>
              <!--Optional:-->
              <urn:City>?</urn:City>
              <!--Optional:-->
              <urn:MainDivision>?</urn:MainDivision>
              <!--Optional:-->
              <urn:SubDivision>?</urn:SubDivision>
              <!--Optional:-->
              <urn:PostalCode>?</urn:PostalCode>
              <!--Optional:-->
              <urn:Country>?</urn:Country>
           </urn:PostalAddress>
           <!--Zero or more repetitions:-->
           <urn:Status lookupResult="?">?</urn:Status>
        </urn:TaxAreaResult>
     </urn:TaxAreaResponse>
     <urn:FindTaxAreasRequest>
        <!--1 or more repetitions:-->
        <urn:TaxAreaLookup asOfDate="?" lookupId="?">
           <!--You have a CHOICE of the next 3 items at this level-->
           <urn:TaxAreaId>?</urn:TaxAreaId>
           <urn:PostalAddress>
              <!--Optional:-->
              <urn:StreetAddress1>?</urn:StreetAddress1>
              <!--Optional:-->
              <urn:StreetAddress2>?</urn:StreetAddress2>
              <!--Optional:-->
              <urn:City>?</urn:City>
              <!--Optional:-->
              <urn:MainDivision>?</urn:MainDivision>
              <!--Optional:-->
              <urn:SubDivision>?</urn:SubDivision>
              <!--Optional:-->
              <urn:PostalCode>?</urn:PostalCode>
              <!--Optional:-->
              <urn:Country>?</urn:Country>
           </urn:PostalAddress>
           <urn:ExternalJurisdiction>
              <urn:ExternalJurisdictionCode>?</urn:ExternalJurisdictionCode>
              <urn:Country>?</urn:Country>
           </urn:ExternalJurisdiction>
        </urn:TaxAreaLookup>
     </urn:FindTaxAreasRequest>
     <urn:FindTaxAreasResponse>
        <!--Zero or more repetitions:-->
        <urn:TaxAreaLookupResult lookupId="?">
           <!--Zero or more repetitions:-->
           <urn:TaxAreaResult taxAreaId="?" asOfDate="?" confidenceIndicator="?">
              <!--Zero or more repetitions:-->
              <urn:Jurisdiction jurisdictionLevel="?" jurisdictionId="?" effectiveDate="?" expirationDate="?" externalJurisdictionCode="?">?</urn:Jurisdiction>
              <!--Zero or more repetitions:-->
              <urn:PostalAddress>
                 <!--Optional:-->
                 <urn:StreetAddress1>?</urn:StreetAddress1>
                 <!--Optional:-->
                 <urn:StreetAddress2>?</urn:StreetAddress2>
                 <!--Optional:-->
                 <urn:City>?</urn:City>
                 <!--Optional:-->
                 <urn:MainDivision>?</urn:MainDivision>
                 <!--Optional:-->
                 <urn:SubDivision>?</urn:SubDivision>
                 <!--Optional:-->
                 <urn:PostalCode>?</urn:PostalCode>
                 <!--Optional:-->
                 <urn:Country>?</urn:Country>
              </urn:PostalAddress>
              <!--Zero or more repetitions:-->
              <urn:Status lookupResult="?">?</urn:Status>
           </urn:TaxAreaResult>
           <!--Optional:-->
           <urn:LookupException>
              <!--Optional:-->
              <urn:ExceptionType>?</urn:ExceptionType>
              <!--Optional:-->
              <urn:RootCause>?</urn:RootCause>
           </urn:LookupException>
        </urn:TaxAreaLookupResult>
     </urn:FindTaxAreasResponse>
     <urn:VersionRequest/>
     <urn:VersionResponse>
        <!--Optional:-->
        <urn:ProductVersions>
           <!--1 or more repetitions:-->
           <urn:ProductVersion productName="?">?</urn:ProductVersion>
        </urn:ProductVersions>
        <!--Optional:-->
        <urn:LibraryVersions>
           <!--1 or more repetitions:-->
           <urn:LibraryVersion libraryName="?" libraryOwner="?">?</urn:LibraryVersion>
        </urn:LibraryVersions>
        <!--Optional:-->
        <urn:DatabaseVersions>
           <!--1 or more repetitions:-->
           <urn:DatabaseVersion logicalName="?">
              <urn:SchemaVersion>?</urn:SchemaVersion>
              <urn:PlatformVersion vendorName="?">?</urn:PlatformVersion>
              <urn:DriverVersion driverName="?">?</urn:DriverVersion>
              <!--Optional:-->
              <urn:DataContentVersions>
                 <!--1 or more repetitions:-->
                 <urn:DataContentVersion contentName="?">?</urn:DataContentVersion>
              </urn:DataContentVersions>
           </urn:DatabaseVersion>
        </urn:DatabaseVersions>
        <!--Optional:-->
        <urn:ConfigurationVersion>?</urn:ConfigurationVersion>
        <!--Optional:-->
        <urn:MessageResourceVersion>?</urn:MessageResourceVersion>
        <!--Optional:-->
        <urn:OperatingSystemVersion operatingSystemName="?">?</urn:OperatingSystemVersion>
        <!--Optional:-->
        <urn:JavaVirtualMachineVersion jvmName="?">?</urn:JavaVirtualMachineVersion>
     </urn:VersionResponse>
     <!--Optional:-->
     <urn:ApplicationData>
        <!--Optional:-->
        <urn:Sender>?</urn:Sender>
        <!--Optional:-->
        <urn:MessageLogging returnLogEntries="?">
           <!--Zero or more repetitions:-->
           <urn:OverrideLoggingThreshold thresholdScope="?">?</urn:OverrideLoggingThreshold>
        </urn:MessageLogging>
        <!--Zero or more repetitions:-->
        <urn:LogEntry logLevel="?" instanceId="?" threadId="?" className="?">
           <urn:Message>?</urn:Message>
           <!--Optional:-->
           <urn:Exception>?</urn:Exception>
        </urn:LogEntry>
        <!--Optional:-->
        <urn:ResponseTimeMS>?</urn:ResponseTimeMS>
     </urn:ApplicationData>
  </urn:VertexEnvelope>

我得到了它的工作,谢谢你!

正确的格式是:

  "<soapenv:Envelope xmlns:soapenv='http://schemas.xmlsoap.org/soap/envelope/' xmlns:urn='urn:vertexinc:o-series:tps:6:0'>
 <soapenv:Header/>
 <soapenv:Body>
  <urn:VertexEnvelope>
     <urn:Login>
        <urn:UserName>test</urn:UserName>
        <urn:Password>test</urn:Password>
     </urn:Login>
     <urn:TaxAreaRequest>
        <urn:TaxAreaLookup asOfDate='2008-01-01' >
           <urn:PostalAddress>
              <urn:City>HUNTSVILLE</urn:City>
              <urn:MainDivision>AL</urn:MainDivision>
              <urn:SubDivision>MADISON</urn:SubDivision>
              <urn:PostalCode>35801</urn:PostalCode>
              <urn:Country>USA</urn:Country>
           </urn:PostalAddress>
        </urn:TaxAreaLookup>
     </urn:TaxAreaRequest>
  </urn:VertexEnvelope>
  </soapenv:Body>
</soapenv:Envelope>"

2 个答案:

答案 0 :(得分:2)

 "<soapenv:Envelope xmlns:soapenv='http://schemas.xmlsoap.org/soap/envelope/' xmlns:urn='urn:vertexinc:o-series:tps:6:0'>
<soapenv:Header/>
<soapenv:Body>
 <urn:VertexEnvelope>
 <urn:Login>
    <urn:UserName>test</urn:UserName>
    <urn:Password>test</urn:Password>
 </urn:Login>
 <urn:TaxAreaRequest>
    <urn:TaxAreaLookup asOfDate='2008-01-01' >
       <urn:PostalAddress>
          <urn:City>HUNTSVILLE</urn:City>
          <urn:MainDivision>AL</urn:MainDivision>
          <urn:SubDivision>MADISON</urn:SubDivision>
          <urn:PostalCode>35801</urn:PostalCode>
          <urn:Country>USA</urn:Country>
       </urn:PostalAddress>
    </urn:TaxAreaLookup>
 </urn:TaxAreaRequest>
 </urn:VertexEnvelope>
 </soapenv:Body>
</soapenv:Envelope>"

答案 1 :(得分:0)

您是否尝试过将CalculateTaxString与Vertex一起使用?我想知道它是否应该是这样的。任何帮助都会很棒。

"<soapenv:Envelope xmlns:soapenv='http://schemas.xmlsoap.org/soap/envelope/' xmlns:urn='urn:vertexinc:o-series:tps:6:0'>
<soapenv:Body>
 <urn:VertexEnvelope>
 <urn:Login>
    <urn:UserName>Dmainc</urn:UserName>
    <urn:Password>Monday1</urn:Password>
 </urn:Login>
 <urn:QuatationRequest documentDate='2008-01-01' transactionType="SALE">
    <urn:Currency/>
      <urn:Customer>
       <urn:CustomerCode classCode="2002"/>
       <urn:Destination>
          <urn:City>Huntsville</urn:City>
          <urn:MainDivision>AL</urn:MainDivision>
          <urn:SubDivision>Madison</urn:SubDivision>
          <urn:PostalCode>35801</urn:PostalCode>
          <urn:Country>USA</urn:Country>
       </urn:Destination>
      </urn:Customer>
      <urn:LineItem lineItemNumber="1" lineItemId="1" isMulticomponent="false">
        <urn:Product productClass="product class attribute value">product code value</urn:Product>
        <urn:Quantity>1.0</urn:Quantity>
        <urn:Freight>0</urn:Freight>
        <urn:UnitPrice>1000</urn:UnitPrice>
        <urn:ExtendedPrice>1000</urn:ExtendedPrice>
      </urn:LineItem> 
 </urn:QuatationRequest>
</urn:VertexEnvelope>
</soapenv:Body>
</soapenv:Envelope>"