[英]Error on Web Service request: The top XML element 'parameters' from namespace '' references distinct types
I have the following service interface that I have imported using the Visual Studio tool (it is a WCF Web Service).我有以下使用 Visual Studio 工具导入的服务接口(它是 WCF Web 服务)。
But when I try to consume the service AuthenticateJAAS (execute the web service), I get the following error:但是,当我尝试使用服务AuthenticateJAAS (执行 Web 服务)时,出现以下错误:
InvalidOperationException: The top XML element 'parameters' from namespace '' references distinct types XAFProject.Module.WS.MCWFUsers.mcwfUsersGetUserGroupsIn and XAFProject.Module.WS.MCWFUsers.mcwfUsersAuthenticateJAASIn. InvalidOperationException:命名空间“”中的顶部 XML 元素“参数”引用了不同的类型 XAFProject.Module.WS.MCWFUsers.mcwfUsersGetUserGroupsIn 和 XAFProject.Module.WS.MCWFUsers.mcwfUsersAuthenticateJAASIn。 Use XML attributes to specify another XML name or namespace for the element or types.使用 XML 属性为元素或类型指定另一个 XML 名称或命名空间。
I cannot change the namespace or the element name 'parameters', as it is from a WSDL that cannot be changed (third party).我无法更改名称空间或元素名称“参数”,因为它来自无法更改的 WSDL(第三方)。 When I remove the class GetUserGroupsRequest and related content from the Reference.cs, I can consume the web service AuthenticateJAAS without problems.当我从 Reference.cs 中删除类GetUserGroupsRequest和相关内容时,我可以毫无问题地使用 Web 服务AuthenticateJAAS 。 The generated XML is:生成的 XML 为:
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
<s:Body xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<AuthenticateJAAS xmlns="http://services.senior.com.br">
<user xmlns=""/>
<password xmlns=""/>
<encryption xmlns="">0</encryption>
<parameters xmlns="">
<flowInstanceID xsi:nil="true"/>
<flowName xsi:nil="true"/>
<pmUserName>******</pmUserName>
<pmUserPassword>******</pmUserPassword>
</parameters>
</AuthenticateJAAS>
</s:Body>
</s:Envelope>
Is there a way to use both methods/services (AuthenticateJAAS + GetUserGroupsRequest) without any error?有没有办法同时使用这两种方法/服务(AuthenticateJAAS + GetUserGroupsRequest)而不会出现任何错误? I was thinking that maybe, if I use namespace prefixes, I could manage to use both services, I think.我在想,如果我使用命名空间前缀,我想我可以设法同时使用这两种服务。
Here is the part of the code that I initialize the client and execute the service:这是我初始化客户端并执行服务的部分代码:
sapiens_SyncMCWFUsersClient mCWFUsersClient = new sapiens_SyncMCWFUsersClient();
mcwfUsersAuthenticateJAASIn parameters = new mcwfUsersAuthenticateJAASIn();
parametrosEntrada.pmUserName = "******";
parametrosEntrada.pmUserPassword = "******";
parametrosEntrada.pmEncrypted = 0;
AuthenticateJAASRequest request = new AuthenticateJAASRequest("", "", 0, parameters);
AuthenticateJAASResponse response = mCWFUsersClient.AuthenticateJAAS(request);
So far, I solved my problem by doing the following in the Reference.cs file.到目前为止,我通过在 Reference.cs 文件中执行以下操作解决了我的问题。 [System.ServiceModel.MessageBodyMemberAttribute(Namespace= "", Order=3, Name = "parameters")]
. [System.ServiceModel.MessageBodyMemberAttribute(Namespace= "", Order=3, Name = "parameters")]
。 Then, I changed the field name to anything but "parameter".然后,我将字段名称更改为“参数”以外的任何名称。 In this case public MCWFUsers.mcwfUsersGetUserGroupsIn parametersGetUserGroups;
在这种情况下public MCWFUsers.mcwfUsersGetUserGroupsIn parametersGetUserGroups;
That means that this will not reference distinct types inside cs file.这意味着这不会引用 cs 文件中的不同类型。
I changed this:我改变了这个:
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Tools.ServiceModel.Svcutil", "2.0.3")]
[System.ServiceModel.MessageContractAttribute(WrapperName="GetUserGroups", WrapperNamespace="http://services.senior.com.br", IsWrapped=true)]
public partial class GetUserGroupsRequest
{
[System.ServiceModel.MessageBodyMemberAttribute(Namespace= "", Order=0)]
public string user;
[System.ServiceModel.MessageBodyMemberAttribute(Namespace= "", Order=1)]
public string password;
[System.ServiceModel.MessageBodyMemberAttribute(Namespace= "", Order=2)]
public int encryption;
[System.ServiceModel.MessageBodyMemberAttribute(Namespace= "", Order=3)]
public MCWFUsers.mcwfUsersGetUserGroupsIn parameters;
public GetUserGroupsRequest()
{
}
public GetUserGroupsRequest(string user, string password, int encryption, MCWFUsers.mcwfUsersGetUserGroupsIn parameters)
{
this.user = user;
this.password = password;
this.encryption = encryption;
this.parameters = parameters;
}
}
to this对此
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Tools.ServiceModel.Svcutil", "2.0.3")]
[System.ServiceModel.MessageContractAttribute(WrapperName="GetUserGroups", WrapperNamespace="http://services.senior.com.br", IsWrapped=true)]
public partial class GetUserGroupsRequest
{
[System.ServiceModel.MessageBodyMemberAttribute(Namespace= "", Order=0)]
public string user;
[System.ServiceModel.MessageBodyMemberAttribute(Namespace= "", Order=1)]
public string password;
[System.ServiceModel.MessageBodyMemberAttribute(Namespace= "", Order=2)]
public int encryption;
[System.ServiceModel.MessageBodyMemberAttribute(Namespace= "", Order=3, Name = "parameters")]
public MCWFUsers.mcwfUsersGetUserGroupsIn parametersGetUserGroups;
public GetUserGroupsRequest()
{
}
public GetUserGroupsRequest(string user, string password, int encryption, MCWFUsers.mcwfUsersGetUserGroupsIn parameters)
{
this.user = user;
this.password = password;
this.encryption = encryption;
this.parametersGetUserGroups = parameters;
}
}
Edit: Nope, that didn't solve it, unfortunately.编辑:不,不幸的是,这并没有解决它。 I will keep trying.我会继续努力。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.