C# C SOAP客户端:发送通用XmlNode请求

C# C SOAP客户端:发送通用XmlNode请求,c#,xml,soap,C#,Xml,Soap,我有一个C项目,其中我使用集成的VisualStudio功能右键单击->添加->服务引用添加了一个SOAP服务引用 客户端类正确生成,没有错误。但是,服务的各种方法只接受一个generic System.Xml.XmlNode作为输入,而不是结构化对象 这在理论上应该不是问题,因为我有完整的XML文件和需要执行的查询。所以我试着这样做: NSIStdV20ServiceSoapClient client = new NSIStdV20ServiceSoapClient(); var getAll

我有一个C项目,其中我使用集成的VisualStudio功能右键单击->添加->服务引用添加了一个SOAP服务引用

客户端类正确生成,没有错误。但是,服务的各种方法只接受一个generic System.Xml.XmlNode作为输入,而不是结构化对象

这在理论上应该不是问题,因为我有完整的XML文件和需要执行的查询。所以我试着这样做:

NSIStdV20ServiceSoapClient client = new NSIStdV20ServiceSoapClient();
var getAllDataFlowQuery = File.ReadAllText(@"Query\get_all_dataflow.xml"); //file containing the query
XmlDocument doc = new XmlDocument();
doc.LoadXml(getAllDataFlowQuery);
var dataStructures = client.QueryStructure(doc); //this method accepts a System.Xml.XmlNode as parameter
然而,这不起作用,投掷

System.ServiceModel.FaultException: 'Error due to a non correct client message'
起初我认为这个查询是不正确的,但我尝试使用SoapUI执行完全相同的查询,它工作得非常好!我甚至尝试使用doc.InnerXml返回的确切XML来执行此操作,只是为了确保che-XmlDocument对象没有修改XML,并且可以正常工作

因此,基本上只有在从C调用该方法时,它才不起作用

如果您想自己尝试,该服务可以自由访问,WSDL如下:

您应该尝试使用以下负载调用QueryStructure方法:

<?xml version="1.0" encoding="UTF-8"?><soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:web="http://ec.europa.eu/eurostat/sri/service/2.0"><soapenv:Header /><soapenv:Body><web:QueryStructure><!--Optional:--><web:Query><RegistryInterface xsi:schemaLocation="http://www.SDMX.org/resources/SDMXML/schemas/v2_0/message SDMXMessage.xsd" xmlns="http://www.SDMX.org/resources/SDMXML/schemas/v2_0/message" xmlns:common="http://www.SDMX.org/resources/SDMXML/schemas/v2_0/common" xmlns:compact="http://www.SDMX.org/resources/SDMXML/schemas/v2_0/compact" xmlns:cross="http://www.SDMX.org/resources/SDMXML/schemas/v2_0/cross" xmlns:generic="http://www.SDMX.org/resources/SDMXML/schemas/v2_0/generic" xmlns:query="http://www.SDMX.org/resources/SDMXML/schemas/v2_0/query" xmlns:structure="http://www.SDMX.org/resources/SDMXML/schemas/v2_0/structure" xmlns:registry="http://www.SDMX.org/resources/SDMXML/schemas/v2_0/registry" xmlns:utility="http://www.SDMX.org/resources/SDMXML/schemas/v2_0/utility" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><Header><ID>JD014</ID><Test>true</Test><Truncated>false</Truncated><Name xml:lang="en">Trans46302</Name><Prepared>2001-03-11T09:30:47-05:00</Prepared><Sender id="BIS" /></Header><QueryStructureRequest resolveReferences="false"><registry:DataflowRef /></QueryStructureRequest></RegistryInterface></web:Query></web:QueryStructure></soapenv:Body></soapenv:Envelope>

正如我所说,这在SoapUI中非常有效,但在从C调用客户机方法时不起作用。好吧,似乎visual studio生成的客户机,即使它接受XmlNode作为输入,也会创建一些精确的所需外部结构:所有带有soapenv和web名称空间的外部节点

这意味着我必须将输入XML剥离到:

<?xml version="1.0" encoding="UTF-8"?><RegistryInterface xsi:schemaLocation="http://www.SDMX.org/resources/SDMXML/schemas/v2_0/message SDMXMessage.xsd" xmlns="http://www.SDMX.org/resources/SDMXML/schemas/v2_0/message" xmlns:common="http://www.SDMX.org/resources/SDMXML/schemas/v2_0/common" xmlns:compact="http://www.SDMX.org/resources/SDMXML/schemas/v2_0/compact" xmlns:cross="http://www.SDMX.org/resources/SDMXML/schemas/v2_0/cross" xmlns:generic="http://www.SDMX.org/resources/SDMXML/schemas/v2_0/generic" xmlns:query="http://www.SDMX.org/resources/SDMXML/schemas/v2_0/query" xmlns:structure="http://www.SDMX.org/resources/SDMXML/schemas/v2_0/structure" xmlns:registry="http://www.SDMX.org/resources/SDMXML/schemas/v2_0/registry" xmlns:utility="http://www.SDMX.org/resources/SDMXML/schemas/v2_0/utility" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><Header><ID>JD014</ID><Test>true</Test><Truncated>false</Truncated><Name xml:lang="en">Trans46302</Name><Prepared>2001-03-11T09:30:47-05:00</Prepared><Sender id="BIS" /></Header><QueryStructureRequest resolveReferences="false"><registry:DataflowRef /></QueryStructureRequest></RegistryInterface>

你试过client.QueryStructuredoc.DocumentElement吗?@dbc:是的,但那不是问题所在,请看下面我的答案。