我需要在ruby中使用SOAP创建客户(我们希望使用Rails项目的Acumatica )。
目前,我使用Savon的代码如下所示:
client = Savon.client(wsdl: 'wsdl.wsdl') # sample wsdl path
response = client.call :login, message: { name: '', password: '' }
auth_cookies = response.http.cookies
class ServiceRequest
def to_s
builder = Builder::XmlMarkup.new
builder.instruct!(:xml, encoding: 'UTF-8')
# ... problem is here, I don't know how XML request should look like
builder
end
end
p client.call :submit, message: ServiceRequest.new, cookies: auth_cookies问题是,我不知道XML请求应该是什么样子。
C#请求如下所示(只是文档中的一个示例):
PO302000result = context.PO302000Submit(
new Command[]
{ new Value { Value = "PORE000079", LinkedCommand =
PO302000.DocumentSummary.ReceiptNbr},
new Value { Value = "OK", LinkedCommand =
PO302000.AddPurchaseOrderLine.ServiceCommands.DialogAnswer,
PO302000.Actions.AddPOOrderLine, new Key { Value = "='PORG000084'", FieldName = Commit = true },
PO302000.AddPurchaseOrderLine.OrderNbr.FieldName, ObjectName =
PO302000.AddPurchaseOrderLine.OrderNbr.ObjectName },
new Key { Value = "='CPU00004'", FieldName =
PO302000.AddPurchaseOrderLine.InventoryID.FieldName, ObjectName =
PO302000.AddPurchaseOrderLine.InventoryID.ObjectName },
new Value{ Value = "True", LinkedCommand =
PO302000.AddPurchaseOrderLine.Selected, Commit = true },
PO302000.Actions.AddPOOrderLine2
new Key{ Value = "='CPU00004'", FieldName =
PO302000.DocumentDetails_.InventoryID.FieldName, ObjectName =
PO302000.DocumentDetails_.InventoryID.ObjectName},
new Value{ Value = "1.00", LinkedCommand =
PO302000.DocumentDetails_.ReceiptQty, Commit = true},
// the next part of code is needed if you use Serial items
PO302000.BinLotSerialNumbers.ServiceCommands.NewRow,
new Value { Value = "R01", LinkedCommand =
PO302000.BinLotSerialNumbers.Location },
PO302000.Actions.Save
} );但我不知道这段代码会产生什么样的XML。看起来我们有带有值的命令数组,然后是操作名。但是这种代码呈现的是什么XML呢?也许有些C#或Java人员可以复制由这种代码呈现的xml请求示例?
非常感谢。
发布于 2015-01-21 17:32:24
实际上,‘mumbo-soap4r’或'soap2r‘或'soap4r’不适用于Acumatica。他们太老了,太多才多艺。
最后,我使用Savon (版本2)。我正在使用XmlMarkup类创建消息。但是我如何知道我应该创建什么XML呢?为了知道这一点,我在.net中创建soap请求,然后我看到什么是正确的XML请求,然后我才使用Savon创建soap请求。工作太多了,但我现在不知道更好的方法。它起作用了。
为了使Savon能够使用Acumatica,我设置了下一个选项:
client = Savon.client do
wsdl 'http://path/Soap/AR303000.asmx?wsdl'
log true
namespaces 'xmlns:soap' => 'http://schemas.xmlsoap.org/soap/envelope/'
env_namespace 'soap'
namespace_identifier nil
element_form_default ''
end别忘了把饼干递给我
response = client.call(:login, message: { name: '', password: '' })
auth_cookies = response.http.cookies构建您的客户创建xml,然后提交
m = build_create_submit(customer_name)
response = client.call(:submit, message: m, cookies: auth_cookies)
# get customer id of newly created customer
customer_id = response.try(:hash).try(:[], :envelope).
try(:[], :body).
try(:[], :submit_response).
try(:[], :submit_result).
try(:[], :content).
try(:[], :customer_summary).
try(:[], :customer_id).
try(:[], :value)发布于 2015-01-13 14:53:13
基本上,手动生成XML包是个坏主意,您应该有一些包装器,这需要简化您的代码。
发布于 2015-01-13 17:32:04
最后我所做的是:
gem install 'mumboe-soap4r' # not soap4r,
# because soap4r is old and bugged with newer rubies然后我跑了
wsdl2ruby.rb --wsdl customer.wsdl --type client在这里,wsdl2ruby.rb与mumbo-soap4r宝石一起安装。将customer.wsdl替换为您的wsdl路径,可以是URL或文件系统路径。
运行此命令后,将创建下一个文件:
default.rb
defaultMappingRegistry.rb
defaultDriver.rb
ScreenClient.rb使用这些文件,您可以编写类似于C#代码或php代码的代码,以便与acumatica交互:
require_relative 'defaultDriver'
require 'soap/wsdlDriver'
# this is my helper method to make life easier
def prepare_value(value, command, need_commit = false, ignore = false)
value_command = Value.new
value_command.value = value
value_command.linkedCommand = command
value_command.ignoreError = ignore unless ignore.nil?
value_command.commit = need_commit unless need_commit.nil?
value_command
end
soap_client = SOAP::WSDLDriverFactory.new('customer.wsdl').create_rpc_driver
soap_client.login(name: '', password: '').loginResult
screen = soap_client.getSchema(nil)
soap_client.clear(nil)
content = screen.getSchemaResult
# p schema
p customer = content.customerSummary.customerID
p customer_name = content.customerSummary.customerName
country = content.generalInfoMainAddress.country
customer_class = content.generalInfoFinancialSettings.customerClass
commands = ArrayOfCommand.new
commands << prepare_value('ABBA', customer_name)
commands << prepare_value('US', country)
commands << prepare_value('MERCHANT', customer_class)
commands << content.actions.insert
commands << customer.clone # to return
p commands
p soap_client.submit(commands)希望它能帮到别人。
https://stackoverflow.com/questions/27909810
复制相似问题