提问人:Sagat 提问时间:3/28/2023 更新时间:3/28/2023 访问量:199
WCF 客户端在反序列化操作“userAuthentication”的回复消息正文时出错
WCF Client Error in deserializing body of reply message for operation 'userAuthentication'
问:
我快疯了!收到此错误后,我隔离了代码并回到了基础。我创建了一个 .Net Framework 4.7.1 库,其中包含一个用于外部 SOAP 服务(在 php 中创建)的客户端,负责通过服务引用与 SOAP 服务建立通信并向其发出一些请求。
我创建了一个基本的 WinForms 应用程序,它唯一要做的就是向外部服务调用 userAuthentication 方法,该方法返回一个复杂的“Key”对象。当我从此应用程序调用它时,服务会正确返回响应,并且客户端能够反序列化响应。
当我在应用程序中发出完全相同的请求时,我只能通过扩展性库进行完全访问,服务将返回响应,但客户端无法正确反序列化响应。
在与外部服务通信的 DLL 中,我已经添加了一个 IEndpointBehavior 来获取服务返回的响应,并且无论源应用程序如何,我都可以获得相同的响应。我尝试在响应到达 soap 客户端的反序列化部分之前重新创建响应。
据我了解,我已经分析过,运行时使用的 DLL 在两个应用程序中是相同的......我不知道还能尝试什么,我正在考虑创建一个SOAP服务来与另一个SOAP服务:)
下面是一些代码
初始化和 userAuthentication 调用方法:
EndpointAddress endpoint = new EndpointAddress("https://url/webservice/ws-srv.php");
BasicHttpBinding binding = new BasicHttpBinding();
binding.ReceiveTimeout = new TimeSpan(0, 20, 0);
binding.MaxBufferSize = int.MaxValue;
binding.MaxBufferPoolSize = int.MaxValue;
binding.MaxReceivedMessageSize = int.MaxValue;
binding.MessageEncoding = WSMessageEncoding.Text;
// HTTPS
if (endpoint.Uri.Scheme == Uri.UriSchemeHttps)
{
binding.Security.Mode = BasicHttpSecurityMode.Transport;
binding.Security.Transport.ClientCredentialType = HttpClientCredentialType.None;
}
// Picks up configuration from the config file.
ChannelFactory<iPortalDocWSPortType> factory
= new ChannelFactory<iPortalDocWSPortType>(binding, endpoint);
// Add the client side behavior programmatically to all created channels.
factory.Endpoint.Behaviors.Add(new MessageDiagnosticsEndpointBehavior());
// Inicialize services
//_iPortalDocServices = new iPortalDocWS.iPortalDocWSPortTypeClient(binding, endpoint);
_iPortalDocServices = factory.CreateChannel();
_iPortalDocServicesValidation = _iPortalDocServices.userAuthentication("user", "password");
从 wsdl 文件自动生成的 Reference 类的一部分:
namespace PPS.EXT.iPortalDoc.iPortalDocWS {
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "4.0.0.0")]
[System.ServiceModel.ServiceContractAttribute(Namespace="http://www.iportalmais.pt", ConfigurationName="iPortalDocWS.iPortalDocWSPortType")]
public interface iPortalDocWSPortType {
[System.ServiceModel.OperationContractAttribute(Action="", ReplyAction="*")]
[System.ServiceModel.XmlSerializerFormatAttribute(Style=System.ServiceModel.OperationFormatStyle.Rpc, SupportFaults=true, Use=System.ServiceModel.OperationFormatUse.Literal)]
[System.ServiceModel.ServiceKnownTypeAttribute(typeof(WorkflowInfo))]
[System.ServiceModel.ServiceKnownTypeAttribute(typeof(Macro))]
[System.ServiceModel.ServiceKnownTypeAttribute(typeof(Group))]
[System.ServiceModel.ServiceKnownTypeAttribute(typeof(CTE))]
[System.ServiceModel.ServiceKnownTypeAttribute(typeof(CTE_Individuos))]
[System.ServiceModel.ServiceKnownTypeAttribute(typeof(Location))]
[System.ServiceModel.ServiceKnownTypeAttribute(typeof(Action))]
[System.ServiceModel.ServiceKnownTypeAttribute(typeof(NameValue))]
[System.ServiceModel.ServiceKnownTypeAttribute(typeof(Result))]
[System.ServiceModel.ServiceKnownTypeAttribute(typeof(ActionRev))]
[System.ServiceModel.ServiceKnownTypeAttribute(typeof(Associated_Docs))]
[System.ServiceModel.ServiceKnownTypeAttribute(typeof(NameValueDescription))]
[return: System.ServiceModel.MessageParameterAttribute(Name="userAuthenticationReturn")]
PPS.EXT.iPortalDoc.iPortalDocWS.key userAuthentication(string username, string password);
}
/// <remarks/>
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.Xml", "4.8.4161.0")]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.SoapTypeAttribute(Namespace="http://www.iportalmais.pt")]
public partial class key : object, System.ComponentModel.INotifyPropertyChanged {
private bool resultField;
private string sessionidField;
private System.Nullable<int> userField;
private bool userFieldSpecified;
/// <remarks/>
public bool result {
get {
return this.resultField;
}
set {
this.resultField = value;
this.RaisePropertyChanged("result");
}
}
/// <remarks/>
public string sessionid {
get {
return this.sessionidField;
}
set {
this.sessionidField = value;
this.RaisePropertyChanged("sessionid");
}
}
/// <remarks/>
[System.Xml.Serialization.SoapElementAttribute(IsNullable=true)]
public System.Nullable<int> user {
get {
return this.userField;
}
set {
this.userField = value;
this.RaisePropertyChanged("user");
}
}
/// <remarks/>
[System.Xml.Serialization.SoapIgnoreAttribute()]
public bool userSpecified {
get {
return this.userFieldSpecified;
}
set {
this.userFieldSpecified = value;
this.RaisePropertyChanged("userSpecified");
}
}
public event System.ComponentModel.PropertyChangedEventHandler PropertyChanged;
protected void RaisePropertyChanged(string propertyName) {
System.ComponentModel.PropertyChangedEventHandler propertyChanged = this.PropertyChanged;
if ((propertyChanged != null)) {
propertyChanged(this, new System.ComponentModel.PropertyChangedEventArgs(propertyName));
}
}
}
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "4.0.0.0")]
public interface iPortalDocWSPortTypeChannel : PPS.EXT.iPortalDoc.iPortalDocWS.iPortalDocWSPortType, System.ServiceModel.IClientChannel {
}
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "4.0.0.0")]
public partial class iPortalDocWSPortTypeClient : System.ServiceModel.ClientBase<PPS.EXT.iPortalDoc.iPortalDocWS.iPortalDocWSPortType>, PPS.EXT.iPortalDoc.iPortalDocWS.iPortalDocWSPortType {
public iPortalDocWSPortTypeClient() {
}
public iPortalDocWSPortTypeClient(string endpointConfigurationName) :
base(endpointConfigurationName) {
}
public iPortalDocWSPortTypeClient(string endpointConfigurationName, string remoteAddress) :
base(endpointConfigurationName, remoteAddress) {
}
public iPortalDocWSPortTypeClient(string endpointConfigurationName, System.ServiceModel.EndpointAddress remoteAddress) :
base(endpointConfigurationName, remoteAddress) {
}
public iPortalDocWSPortTypeClient(System.ServiceModel.Channels.Binding binding, System.ServiceModel.EndpointAddress remoteAddress) :
base(binding, remoteAddress) {
}
public PPS.EXT.iPortalDoc.iPortalDocWS.key userAuthentication(string username, string password) {
return base.Channel.userAuthentication(username, password);
}
}
}
肥皂响应:
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://www.iportalmais.pt" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<s:Header xmlns:s="http://schemas.xmlsoap.org/soap/envelope/" />
<SOAP-ENV:Body>
<ns1:userAuthenticationResponse>
<userAuthenticationReturn xsi:type="ns1:key">
<result xsi:type="xsd:boolean">true</result>
<sessionid xsi:type="xsd:string">93ef68c08d321b79a5ec49fb0adb4970</sessionid>
<user xsi:type="xsd:int">10340</user>
</userAuthenticationReturn>
</ns1:userAuthenticationResponse>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
System.ServiceModel.CommunicationException: Error in deserializing body of reply message for operation 'userAuthentication'. ---> System.InvalidOperationException: There is an error in XML document (4, 6). ---> System.ArgumentException: The path is not of a legal form.\r\n at Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationReaderiPortalDocWSPortType.Read194_userAuthenticationResponse()\r\n at Microsoft.Xml.Serialization.GeneratedAssembly.ArrayOfObjectSerializer141.Deserialize(XmlSerializationReader reader)\r\n at System.Xml.Serialization.XmlSerializer.Deserialize(XmlReader xmlReader, String encodingStyle, XmlDeserializationEvents events)\r\n --- End of inner exception stack trace ---\r\n at System.Xml.Serialization.XmlSerializer.Deserialize(XmlReader xmlReader, String encodingStyle, XmlDeserializationEvents events)\r\n at System.Xml.Serialization.XmlSerializer.Deserialize(XmlReader xmlReader, String encodingStyle)\r\n at System.ServiceModel.Dispatcher.XmlSerializerOperationFormatte
r.DeserializeBody(XmlDictionaryReader reader, MessageVersion version, XmlSerializer serializer, MessagePartDescription returnPart, MessagePartDescriptionCollection bodyParts, Object[] parameters, Boolean isRequest)\r\n --- End of inner exception stack trace ---\r\n\r\nServer stack trace: \r\n at System.ServiceModel.Dispatcher.XmlSerializerOperationFormatter.DeserializeBody(XmlDictionaryReader reader, MessageVersion version, XmlSerializer serializer, MessagePartDescription returnPart, MessagePartDescriptionCollection bodyParts, Object[] parameters, Boolean isRequest)\r\n at System.ServiceModel.Dispatcher.XmlSerializerOperationFormatter.DeserializeBody(XmlDictionaryReader reader, MessageVersion version, String action, MessageDescription messageDescription, Object[] parameters, Boolean isRequest)\r\n at System.ServiceModel.Dispatcher.OperationFormatter.DeserializeBodyContents(Message message, Object[] parameters, Boolean isRequest)\r\n at System.ServiceModel.Dispatcher.OperationFormatter.DeserializeRepl
y(Message message, Object[] parameters)\r\n at System.ServiceModel.Dispatcher.ProxyOperationRuntime.AfterReply(ProxyRpc& rpc)\r\n at System.ServiceModel.Channels.ServiceChannel.HandleReply(ProxyOperationRuntime operation, ProxyRpc& rpc)\r\n at System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[] outs, TimeSpan timeout)\r\n at System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[] outs)\r\n at System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCallMessage methodCall, ProxyOperationRuntime operation)\r\n at System.ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessage message)\r\n\r\nException rethrown at [0]: \r\n at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg)\r\n at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type)\r\n
at PPS.EXT.iPortalDoc.Core.iPortalDocWS.iPortalDocWSPortType.userAuthentication(String username, String password)\r\n at PPS.EXT.iPortalDoc.Core.Classes.iPortalDocServices.Inicializa(Boolean forceUpdate) in E:\\TFS\\20230327\\iPortalDoc\\PPS.EXT.iPortalDoc.Core\\Classes\\iPortalDocServices.cs:line 87
InnerException: {“XML 文档 (4, 6) 中存在错误。 数据:{System.Collections.ListDictionaryInternal} HResult:-2146233079 帮助链接:空 InnerException: {“路径不是合法形式。 消息:“XML 文档 (4, 6) 中出现错误。 源:“System.Xml” StackTrace:“ 在 System.Xml.Serialization.XmlSerializer.Deserialize(XmlReader xmlReader、String encodingStyle、XmlDeserializationEvents 事件)\r\n 在 System.Xml.Serialization.XmlSerializer.Deserialize(XmlReader xmlReader,字符串编码样式)\r\n 在 System.ServiceModel.Dispatcher.XmlSerializerOperationFormatter.DeserializeBody(XmlDictionaryReader 读取器、 MessageVersion 版本、 XmlSerializer 序列化程序、 MessagePartDescription returnPart、MessagePartDescriptionCollection bodyParts, Object[] 参数, 布尔值 isRequest)” TargetSite: {System.Object 反序列化 (System.Xml.XmlReader, System.String, System.Xml.Serialization.XmlDeserializationEvents)}
答: 暂无答案
评论