C#Web服务客户端:多个Web服务的方法相同(复杂)的返回类型? [英] C# web-service client: multiple web-service methods with same (complex) return type?

查看:164
本文介绍了C#Web服务客户端:多个Web服务的方法相同(复杂)的返回类型?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我小打小闹在建立一个客户端,此刻一个Java的B2B网络服务,我想我已经确定,我们已经有相当一段时间了问题的原因。不幸的是,我无法发布WSDL

I am chipping away at building a client for a Java B2B web-service at the moment and I think I have identified the cause of a problem we have been having for quite some time. Unfortunately I'm unable to post the WSDL.

显然,我的自动生成的代理代码(通过Wsdl.exe用:必须使用WSE 3.0由于WCF不支持密码摘要)是无法处理具有多个网络的方法具有相同的复杂返回类型的Web服务的WSDL

Apparently my auto-generated proxy code (via wsdl.exe: have to use WSE 3.0 due to WCF not supporting password digest) is not able to handle the web-service's WSDL having multiple web-methods with the same complex return type.

举个例子 - 一个Web服务的定义以下方法:

Take for example - a web-service that defines the following methods:

Public ComplexTypeX Blah();
Public ComplexTypeX Blue();
Public ComplexTypeX Foo();
Public ComplexTypeY Bar();

在我的Reference.cs文件,如果我注释掉调用胡说的任意两个所有代码()蓝()或富(),然后将剩余的未注释方法可以称为没有问题。不过,如果我有超过这三种方法中的一个没有被注释掉(比方说,布拉赫()和美孚()),那么我在收到以下错误消息的实例的Web服务客户端代码的

In my Reference.cs file, if I comment out all code that calls any two of Blah(), Blue() or Foo(), then the remaining uncommented method can be called no problem. However, if I have more than one of these three methods not commented out (say, Blah() and Foo()), then I get the following error message upon instantiation of the web-service client code:

方法布拉赫不能得到体现。

命名空间中的XML元素ComplexTypeX' HTTP://some.url '引用
A方法和类型。使用
WebMethodAttribute更改
方法的消息名称或使用
XmlRootAttribute改变
型的根元素。

"Method Blah can not be reflected." "The XML element 'ComplexTypeX' from namespace 'http://some.url' references a method and a type. Change the method's message name using WebMethodAttribute or change the type's root element using the XmlRootAttribute."

现在,肯定是有定义为Web服务的一部分,没有 ComplexTypeX 的方法,所以我只能假设.NET(或至少Wsdl.exe用)不允许你使用web服务,返回复杂的(用户自定义)类型的多个方法相同类型的,对吧?

Now, there is definitely no ComplexTypeX method defined as part of the web-service, so I can only assume that .NET (or at least wsdl.exe) does not allow you to use a web-service that returns complex (user-defined) types of the same type across multiple methods ... right?

推荐答案

我遇到了类似的问题,这里是我发现了什么:

I ran into a similar problem, and here is what I found:

我已经定义一个复杂类型返回作为响应:

I had defined a complex type to return as a response:

public class FooResponse {...}

[WebMethod]
public FooResponse Foo() {...}

请注意,这里的确切美孚/美孚+响应的名称配对是很重要的。当我改变了方法名如下,问题消失:

Note that here the exact name pairing of Foo/Foo+Response is important. When I changed the method name as follows, the problem went away:

public class FooResponse {...}

[WebMethod]
public FooResponse Fooxxx() {...}

我相信这是发生的事情是.NET尝试自动换行来自于Foo方法与元素命名FooResponse到来的响应。只要你想返回对象使用相同名称的产生歧义。试着改变你的响应对象,或者你的方法,以避免这个碰撞的名称的名称。

What I believe is happening is .NET is attempting to automatically wrap the response coming from the Foo method with an element named FooResponse. The use of that same name as the object you want to return creates ambiguity. Try changing the name of your response object, or the name of your method to avoid this collision.

这篇关于C#Web服务客户端:多个Web服务的方法相同(复杂)的返回类型?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆