Web服务请求调用SOAP请求缺少空参数

我是Web服务和C#的新手,所以如果我的问题太简单,请原谅我。 我已经四处搜索但找不到答案 – 至少有一个基于我的关键字。

我试图通过C#(Visual Web Developer 2010 Express)调用Web服务,但我收到错误作为响应。 当我通过soapUI调用相同的Web服务时,我没有收到错误。 当我将来自C#的SOAP请求与来自soapUI的SOAP请求进行比较时,C#SOAP请求缺少故意为空的参数 。 当我从soapUI请求中取出空参数时,我得到相同的错误。 对我来说,答案是让C#发送参数,即使它是空的。 我通过将其设置为null或“”来尝试此操作,但无济于事。 有没有办法强制我的C#Web服务客户端发送一个空参数或者可能发送所有参数,即使它们没有值?

WSDL

                                                                           

C#SOAP(不起作用)

     edmsdev my_acl   spoonyfork my_password edmsdev     

soapUI SOAP(作品)

       edmsdev my_acl     spoonyfork  my_password        edmsdev     

EDRSearch XSD

                                                                                                                                     

C#代码

 ServiceReference1.UserCredentials uc = new ServiceReference1.UserCredentials(); uc.userName = "spoonyfork"; uc.password = "my_password"; uc.docbase = "edmsdev"; ServiceReference1.ACLUsersRequest aurt = new ServiceReference1.ACLUsersRequest(); aurt.aclName = "my_acl"; aurt.docbase = "edmsdev"; ServiceReference1.EDRSearchServiceSOAPImplClient client = new ServiceReference1.EDRSearchServiceSOAPImplClient(); ServiceReference1.ACLUsersResponse aure = new ServiceReference1.ACLUsersResponse(); aure = client.getACLUsers(aurt, uc); 

首先,您可以尝试将aclObjectId属性声明为序列化,即使它为null 。 为此,您需要找到class ACLUsersRequest的定义并添加

[System.Xml.Serialization.XmlElementAttribute(IsNullable=true)]

对于那个属性。 这它作为包含在SOAP请求中

其次,您可以简单地将该属性声明为string.Empty

 EDRSearchServiceSOAPImplClient client = new EDRSearchServiceSOAPImplClient(); var test = client.getACLUsers( new ACLUsersRequest() { aclName = "my_acl", docbase = "qwe", aclObjectId=string.Empty },//this should do the trick new UserCredentials() { userName = "lala", password = "123", docbase = "qwe" }); 

它作为包含在SOAP请求中,它等于

如果这两种方法都不起作用,那么您正在处理非常糟糕的Web服务提供者,并且需要实现自编写的客户端,该客户端将消息格式化为提供者强制的。

到目前为止,我唯一能找到的东西:

http://www.w3.org/TR/2007/REC-soap12-part2-20070427/

 4.2.1 Applications MAY process invocations with missing parameters but also MAY fail to process the invocation and return a fault. 

您是否手动生成了Web引用? 你能提供合适的WSDL吗? +我可以更新这个答案


          

对我来说,这看起来并不像SOAP级别有多个参数,只是说XML或字符串参数。 getAclUsers有多个参数吗?

我承认我的SOAP知识有限,但WSDL中没有任何内容列出任何参数……也许您正在序列化XML并且XML序列化选项是你应该看的东西?