开发者

Troubles with WCF client (for a non .Net service)

开发者 https://www.devze.com 2023-03-11 17:40 出处:网络
In a c# project, I have to query some web services which is not build with .Net (actually WebLogic). Where I can query most of the web services with no problem, I have difficulties with one. When I c

In a c# project, I have to query some web services which is not build with .Net (actually WebLogic).

Where I can query most of the web services with no problem, I have difficulties with one. When I call the method, I get the following error (stack trace removed) :

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.

After a bit of googling, I conclude this is due because the distant service have two methods FirstMethod and SecondMethod, both with a complex FirstMethodRequest type having a property "In" as input parameter. However, the In parameter have two distinct types(respectively firstMethodInType and secondMethodInType).

I use svcutil for building the proxy code. This actually generate the code :

Pseudo code :

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
{
}

Full code :

[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;
}

As I don't control the output code, how can I properly solv开发者_开发技巧e my problem ?

thx in advance

[Edit] Don't know if it's related, but here is an extract of the WSDL definition :

<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>

[Edit 2] Also, if the source WSDL / Schema is not valid or respectful to the W3C standards, please tells me. I can negotiate with the customer to rewrite its WS

[Edit 3] If I manually patch the wsdl to (renamed the second part) :

<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>

then the problem disappeared (but of course the call to the second method stop working)


Finally, I ask the customer to change its WSDL to avoid this name conflicts. This solved the problem and is probably the simplest way to solve the issue.

0

精彩评论

暂无评论...
验证码 换一张
取 消