1

我需要查询在 Reporting Services 中传递复杂参数作为输入的 web 服务。我怎样才能做到这一点?

在 Visual Studio 的查询设计器中,我正在执行如下查询:

<Query>
<SoapAction>http://mywebservice.com/Customers/GetCustomers</SoapAction>
<Method Name="GetCustomers" Namespace="http://mywebservice.com/Customers/">
<Parameters>
<Parameter Name="myParams" type="xml">
   <DefaultValue>
        <myParams>
           <IdCustomer>0</IdCustomer>
        </myParams>
    </DefaultValue>
</Parameter>
</Parameters>
</Method>
<ElementPath IgnoreNamespaces="true">*</ElementPath>
</Query>

WebService 期望它作为参数:

<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
  <soap:Body>
    <GetCustomer xmlns="http://mywebservice.com/Customers/">
      <myParams>
        <IdCustomer>int</IdCustomer>
        <IdCustomer>int</IdCustomer>
      </myParams>
    </GetCustomer>
  </soap:Body>
</soap:Envelope>

当我在 Visual Studio 2008 上尝试时,我收到以下错误消息:

对指定 URL 执行 Web 请求失败。Soap 故障:System.Web.Services.Protocols.SoapException:服务器无法处理请求。---> System.NullReferenceException:对象引用未设置为对象的实例。

4

1 回答 1

0

您应该查看在测试客户端中发送的 xml,以获取查询所需语法的示例。我建议使用Visual Studio 附带的wcftestclient 。运行测试后,您可以在 XML 选项卡上查看 xml(在 wcftestclient 的屏幕底部),并将查询的 <DefaultValue> 部分中的内容替换为相应的参数值。

该 Web 服务的查询应如下所示。请注意将取决于您自己的情况的命名空间:

<Query>
  <SoapAction>http://mywebservice.com/Customers/GetCustomers</SoapAction>
  <Method Name="GetCustomer" Namespace="http://mywebservice.com/Customers/">
    <Parameters>
      <Parameter Name="myParams" type="xml">
        <DefaultValue xmlns:a="http://schemas.datacontract.org/2004/07/MyWebServices">
          <a:IdCustomer>0</a:IdCustomer>
          <a:IdCustomer>1</a:IdCustomer>
        </DefaultValue>
      </Parameter>
    </Parameters>
  </Method>
</Query>

另外,我确实看到您有 <Parameter type="xml">。对我来说,我花了几个小时处理一个类似的查询,但缺少type="xml"。MSDN 上似乎没有很好地记录该属性。

于 2015-08-27T14:31:11.513 回答