Savon 2.11.1 在客户端实例化后设置 soap header Rails + SSRS

Savon 2.11.1 set soap header after client is instantiated Rails + SSRS

我正在尝试使用 Savon 2.11.1 将我的 rails 应用程序与 Sql 服务器报告服务 (SSRS) 集成。我正在使用 ReportServicesExecution2005 WSDL。我遇到的问题是我必须在实例化客户端后向 soap header 添加一个 session_id。这是因为 session_id 是客户端调用 load_report 后由 SSRS 生成的。

client = Savon.client(wsdl: "https://somewsdl.asmx?wsdl", basic_auth: ["user", "pass"])

此调用 returns 响应中的 session_id:

response = client.call(:load_report, message: {report: "path/to/report"} ) 

进行此调用时,soap header 需要在客户端中包含 session_id:

client.call(:set_execution_parameters, message: { report: "path/to/report", parameters: params  }  )

试过这个但没用:

client.call(:set_execution_parameters, soap_header: {"session_id" => @session_id}, message: { report: "path/to/report", parameters: params  }  ) 

我收到以下错误:

(soap:Client) The session identifier is missing. A session identifier is required for this operation. ---> Microsoft.ReportingServices.Diagnostics.Utilities.MissingSessionIdException: The session identifier is missing. A session identifier is required for this operation.

感谢您的帮助。

您应该使用 soap_header 散列来传递会话 ID,例如

response = client.call(:set_execution_parameters, :soap_header => { :session_id => sid })

干杯

我找到的解决方案(虽然笨拙)是通过 Savon 创建一个新客户端,并将现有客户端值加上新的 execution_id/session_Id 传递到构造函数中。这成功了。下面的代码示例。

初始 Savon 客户端:

@exeClient = Savon.client(wsdl: "some_wsdl.asmx?wsdl", basic_auth: ["user", "pass"], 
convert_request_keys_to: :camelcase, soap_header: {"execution_id" => ""} ) 

调用load_report得到execution_id:

@data = @exeClient.call(:load_report, message: {report: "/path/to/report"} )

访问execution_id:

@report = @data.to_hash

@execution_id = @report[:load_report_response][:execution_info][:execution_id]

创建可以通过 execution_id 访问 运行 报告的新客户端:

@newClient = Savon.client(wsdl: "/path/to/report/wsdl", basic_auth: ["user", "pass"], 
 :soap_header => {:"tns:TrustedUserHeader" => {"tns:UserName"=> "" , "tns:UserToken" => ""},  :"tns:ExecutionHeader" => {"tns:ExecutionID" => @execution_id}}) 

创建参数哈希:

param1 = { :Parameter_value =>{
    :"Name" => "nameOfParam",
    :"Value" => current_user.company_id
  }
}

调用setExecutionParameters:

response =  @newClient.call(:set_execution_parameters, message: { "Parameters" => param1} )

现在可以了。请注意,如何使用 Savon 指定名称空间很重要。如果操作不正确,某些标签上将不会指定命名空间;这将使 soap 调用失败。