C# 生成的WCF代理为列表返回null

C# 生成的WCF代理为列表返回null,c#,visual-studio,wcf,soap,wsdl,C#,Visual Studio,Wcf,Soap,Wsdl,我们正在尝试为PHPSOAP服务实现WCF代理/客户机。 我们检索了WSDL并在命令行应用程序中创建了服务引用。 我们能够检索SOAP操作的结果,但事实证明,返回的列表总是以null结尾,当用fiddler轻敲电线或在SoapUI中测试时,我们可以清楚地看到返回的数据 我在类似的问题帖子中遵循了一些建议,并提出了一个最低限度的反序列化示例,似乎也有同样的问题 Message m=Message.CreateMessage(XmlReader.Create(“response.xml”)、int.

我们正在尝试为PHPSOAP服务实现WCF代理/客户机。 我们检索了WSDL并在命令行应用程序中创建了服务引用。 我们能够检索SOAP操作的结果,但事实证明,返回的列表总是以null结尾,当用fiddler轻敲电线或在SoapUI中测试时,我们可以清楚地看到返回的数据

我在类似的问题帖子中遵循了一些建议,并提出了一个最低限度的反序列化示例,似乎也有同样的问题

Message m=Message.CreateMessage(XmlReader.Create(“response.xml”)、int.MaxValue、MessageVersion.Soap11);
SoapReflectionImporter importer=新的SoapReflectionImporter(新的SoapAttributeOverrides(),”http://brokenns");
XmlTypeMapping=importer.ImportTypeMapping(typeof(getDeviceListResponse));
XmlSerializer serializer=新的XmlSerializer(映射);
getDeviceListResponse=(getDeviceListResponse)序列化程序。反序列化(m.GetReaderAtBodyContents());
Console.WriteLine(response.@return.deviceList==null?“列表为null”:“列表不为null”);
<列表为空
service.wsdl


返回设备列表
response.xml


作品
48
41
42
任何人都能发现服务wsdl中的错误,该错误在反序列化后会使我的列表为空吗

我曾经尝试过对生成的契约进行简单的来回序列化,但没有发现其中的问题,这让我相信这与名称空间有关,但忽略它们并没有帮助


sd
2323
67

以下功能可用于序列化:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;
using System.Xml.Serialization;

namespace ConsoleApplication1
{
    class Program
    {
        const string FILENAME = @"c:\temp\test.xml";
        static void Main(string[] args)
        {
            XmlReader reader = XmlReader.Create(FILENAME);
            XmlSerializer serializer = new XmlSerializer(typeof(Envelope));
            Envelope envelope = (Envelope)serializer.Deserialize(reader);

        }
    }
    [XmlRoot(ElementName = "Envelope", Namespace = "http://schemas.xmlsoap.org/soap/envelope/")]
    public class Envelope
    {
        [XmlElement(ElementName = "Body", Namespace = "http://schemas.xmlsoap.org/soap/envelope/")]
        public Body Body { get; set; }
    }
    public class Body
    {
        [XmlElement(ElementName = "getDeviceListResponse", Namespace = "http://brokenns")]
        public getDeviceListResponse getDeviceListResponse { get; set; }
    }
    public class getDeviceListResponse
    {
        [XmlElement(ElementName = "return", Namespace = "")]
        public Return Return { get; set; }
    }
    public class Return
    {
        public string message { get; set; }
        [XmlElement()]
        public List<deviceList> deviceList { get; set; }
    }
    public class deviceList
    {
        public int id { get; set; }
    }
}

 
使用系统;
使用System.Collections.Generic;
使用System.Linq;
使用系统文本;
使用System.Xml;
使用System.Xml.Serialization;
命名空间控制台应用程序1
{
班级计划
{
常量字符串文件名=@“c:\temp\test.xml”;
静态void Main(字符串[]参数)
{
XmlReader=XmlReader.Create(文件名);
XmlSerializer serializer=新的XmlSerializer(typeof(信封));
信封=(信封)序列化程序。反序列化(读取器);
}
}
[XmlRoot(ElementName=“信封”,命名空间=”http://schemas.xmlsoap.org/soap/envelope/")]
公共类信封
{
[XmlElement(ElementName=“Body”,命名空间=”http://schemas.xmlsoap.org/soap/envelope/")]
公共机构主体{get;set;}
}
公共阶级团体
{
[XmlElement(ElementName=“getDeviceListResponse”,命名空间=”http://brokenns")]
公共getDeviceListResponse getDeviceListResponse{get;set;}
}
公共类getDeviceListResponse
{
[xmlement(ElementName=“return”,Namespace=”“)]
公共返回{get;set;}
}
公共类报税表
{
公共字符串消息{get;set;}
[XmlElement()]
公共列表设备列表{get;set;}
}
公共阶级恶魔主义者
{
公共int id{get;set;}
}
}

正如我所提到的,我知道契约是在普通的XMLSerializer中工作的。它在自动生成的WSDL服务代理中不起作用。我发现了一个类似的问题,这让我想知道,在wcf契约中,如果没有包装元素,是否就不可能将重复元素与其他属性混合在一起……WSDL是不完整的。WSDL中存在错误。例如,没有type=“tns:Device”复杂元素事实上我对wsdl进行了裁剪,但在DeviceListResult类型的正上方有一个设备复杂元素。使用不同的前缀。一个是在WSDL中使用TNS。我尝试从WSDL模式创建类,但失败了。使用“svcutil file.WSDL”生成类从Visual Studio 2019 Enterprise命令提示符成功生成一个DeviceService.cs,其中包含类DeviceListResult并在其属性deviceList中引用类设备。原因可能是WCF将通用列表序列化为数组以通过网络发送。配置只是告诉svcutil创建一个代理,并为了方便起见将它们转换回公共列表。创建服务引用时,可以尝试修改集合类型。有关它的更多信息,您可以参考以下链接:在wcf代理中进行反序列化后,集合类型都不会更改列表为空的事实。是否要在.net中调用PHP SOAP服务?如果您想在.net中调用PHPSOAP服务,可以参考以下链接:该服务确实在另一端使用NuSoap,但该链接对我来说没有答案。
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;
using System.Xml.Serialization;

namespace ConsoleApplication1
{
    class Program
    {
        const string FILENAME = @"c:\temp\test.xml";
        static void Main(string[] args)
        {
            XmlReader reader = XmlReader.Create(FILENAME);
            XmlSerializer serializer = new XmlSerializer(typeof(Envelope));
            Envelope envelope = (Envelope)serializer.Deserialize(reader);

        }
    }
    [XmlRoot(ElementName = "Envelope", Namespace = "http://schemas.xmlsoap.org/soap/envelope/")]
    public class Envelope
    {
        [XmlElement(ElementName = "Body", Namespace = "http://schemas.xmlsoap.org/soap/envelope/")]
        public Body Body { get; set; }
    }
    public class Body
    {
        [XmlElement(ElementName = "getDeviceListResponse", Namespace = "http://brokenns")]
        public getDeviceListResponse getDeviceListResponse { get; set; }
    }
    public class getDeviceListResponse
    {
        [XmlElement(ElementName = "return", Namespace = "")]
        public Return Return { get; set; }
    }
    public class Return
    {
        public string message { get; set; }
        [XmlElement()]
        public List<deviceList> deviceList { get; set; }
    }
    public class deviceList
    {
        public int id { get; set; }
    }
}