在c#项目中,我必须查询一些不是用.Net(实际上是WebLogic)构建的Web服务。
我可以毫无问题地查询大多数Web服务,但我遇到了一个问题。当我调用该方法时,我收到以下错误(删除了堆栈跟踪):
System.InvalidOperationException: There was an error reflecting 'in'.
---> System.InvalidOperationException: The top XML element 'in' from namespace '' references distinct types MyReference.DistantWS.firstMethodInType and MyReference.DistantWS.secondMethodInType.
Use XML attributes to specify another XML name or namespace for the element or types.
经过一些谷歌搜索后,我得出结论这是因为远程服务有两种方法FirstMethod
和SecondMethod
,两种方法都有一个复杂的FirstMethodRequest
类型,其属性为“In”as输入参数。但是,In参数有两种不同的类型(分别为firstMethodInType
和secondMethodInType
)。
我使用svcutil
来构建代理代码。这实际上生成了代码:
伪代码:
class firstMethodRequest
{
public firstMethodintype @in; // First occurence of a "in" parameter
}
class firstMethodintype
{
}
class secondMethodRequest
{
public secondMethodintype @in; // Second occurence of a "in" parameter
}
class secondMethodintype
{
}
完整代码:
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "4.0.0.0")]
[System.ServiceModel.MessageContractAttribute(WrapperName="first-method", WrapperNamespace="http://mynamespace/ws/wsdl/first-method", IsWrapped=true)]
internal partial class firstMethodRequest
{
[System.ServiceModel.MessageBodyMemberAttribute(Namespace="", Order=0)]
public firstMethodintype @in;
public firstMethodRequest() { }
public firstMethodRequest(firstMethodintype @in) { this.@in = @in; }
}
[System.CodeDom.Compiler.GeneratedCodeAttribute("svcutil", "4.0.30319.1")]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(TypeName="first-method-in-type", Namespace="http://mynamespace")]
public partial class firstMethodintype
{
private string site_origineField;
}
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "4.0.0.0")]
[System.ServiceModel.MessageContractAttribute(WrapperName="second-method", WrapperNamespace="http://mynamespace/ws/wsdl/second-method", IsWrapped=true)]
internal partial class secondMethodRequest
{
[System.ServiceModel.MessageBodyMemberAttribute(Namespace="", Order=0)]
public secondMethodintype @in; // Problem is here
public secondMethodRequest() { }
public secondMethodRequest(secondMethodintype @in) { this.@in = @in; }
}
[System.CodeDom.Compiler.GeneratedCodeAttribute("svcutil", "4.0.30319.1")]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(TypeName="second-method-in-type", Namespace="http://mynamespace")]
public partial class secondMethodintype
{
private string site_origineField;
}
由于我不控制输出代码,我该如何正确解决问题?
事先提前[编辑] 不知道它是否相关,但这里是WSDL定义的摘录:
<message name="first-method-in">
<part name="in" type="tp:first-method-in-type"/>
</message>
<message name="second-method-in">
<part name="in" type="tp:second-method-in-type"/>
</message>
[编辑2] 此外,如果源WSDL / Schema无效或尊重W3C标准,请告诉我。我可以与客户协商重写其WS
[编辑3] 如果我手动修补wsdl(重命名为第二部分):
<message name="first-method-in">
<part name="in" type="tp:first-method-in-type"/>
</message>
<message name="second-method-in">
<part name="inSecond" type="tp:second-method-in-type"/>
</message>
然后问题消失了(但当然第二种方法的调用停止了)
答案 0 :(得分:0)
最后,我要求客户更改其WSDL以避免此名称冲突。 这解决了问题,可能是解决问题的最简单方法。