如何解决嵌套类参数的帧查询以使用来自 SSRS 的 WCF 服务
尝试在 SSRS 中使用 WCF 服务。由于方法参数是嵌套类,因此无法构建查询。下面将 WCFService 定义和 QUERY 嵌入到 SS 中。
WCF 定义:
namespace WcfService1
{
[ServiceContract]
public interface IService1
{
[OperationContract]
int GetDataUsingDataContract1(CompositeType1 composite,int val);
// TODO: Add your service operations here
}
[DataContract]
public class CompositeType
{
bool boolValue = true;
string stringValue = "Hello ";
[DataMember]
public bool BoolValue
{
get { return boolValue; }
set { boolValue = value; }
}
[DataMember]
public string StringValue
{
get { return stringValue; }
set { stringValue = value; }
}
}
[DataContract]
public class CompositeType1
{
CompositeType _compositeType;
int _intValue = 1;
[DataMember]
public CompositeType compositeType
{
get { return _compositeType; }
set { _compositeType = value; }
}
[DataMember]
public int intValue
{
get { return _intValue; }
set { _intValue = value; }
}
}
}
在 SSRS 中查询以使用 WCF 服务
<Query>
<Method Name="GetDataUsingDataContract1" Namespace="http://tempuri.org/">
<Parameters>
<Parameter Name ="composite" Type="XML" xmlns="http://schemas.datacontract.org/2004/07/WcfService1">
<Parameter Name ="compositeType" Type="XML" xmlns="http://schemas.datacontract.org/2004/07/WcfService1">
<DefaultValue>
<BoolValue>1</BoolValue>
<StringValue> Testing</StringValue>
</DefaultValue>
</Parameter>
<Parameter Name="val"><DefaultValue>10</DefaultValue></Parameter>
</Parameter>
<Parameter Name="intval"><DefaultValue>10</DefaultValue></Parameter>
</Parameters>
</Method>
<SoapAction>http://tempuri.org/IService1/GetDataUsingDataContract</SoapAction>
</Query>
但是上面的查询不起作用。
解决方法
这是因为你查询的xml结构有问题,WCF服务收不到这个消息。根据你提供的接口,WCF服务收到的消息应该是这样的:
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
<s:Header>
<To s:mustUnderstand="1" xmlns="http://schemas.microsoft.com/ws/2005/05/addressing/none">http://localhost:8000/GettingStarted/CalculatorService</To>
<Action s:mustUnderstand="1" xmlns="http://schemas.microsoft.com/ws/2005/05/addressing/none">http://tempuri.org/IService1/GetDataUsingDataContract1</Action>
</s:Header>
<s:Body>
<GetDataUsingDataContract1 xmlns="http://tempuri.org/">
<composite xmlns:a="http://schemas.datacontract.org/2004/07/ConsoleApp136" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
<a:compositeType i:nil="true" />
<a:intValue>0</a:intValue>
</composite>
<val>1</val>
</GetDataUsingDataContract1>
</s:Body>
</s:Envelope>
需要注意的是,我们调用WCF服务并不是直接发送xml消息,而是通过代理类调用。有关它的信息,您可以参考此link。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。