【问题标题】:Troubles with WCF client (for a non .Net service)WCF 客户端的问题(对于非 .Net 服务)
【发布时间】:2011-09-10 23:37:55
【问题描述】:

在一个 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.

经过一番谷歌搜索,我得出结论,这是因为远程服务有两个方法 FirstMethodSecondMethod,两者都有一个复杂的 FirstMethodRequest 类型,具有属性“In”作为输入参数。但是,In 参数有两种不同的类型(分别为 firstMethodInTypesecondMethodInType)。

我使用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>

然后问题就消失了(当然对第二种方法的调用停止工作)

【问题讨论】:

    标签: c#-4.0 wcf-client


    【解决方案1】:

    最后,我要求客户更改其 WSDL 以避免这种名称冲突。 这解决了问题,可能是解决问题的最简单方法。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-11-29
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多