我正在尝试开发一个简单的Windows窗体应用程序,以便从最新版本的ESTES ShipmentTracking v1.1 Web服务请求跟踪信息。当我执行该请求时,程序将引发System.ServiceModel.CommunicationException
我正在使用Visual Studio 2019和.NET 4.6.2 C# Windows窗体应用程序。我使用添加服务引用过程配置了一个Connected Service
,并使用了ESTES_Track
命名空间。以下是我的基本代码:
ESTES_Track.EstesShipmentTracking_PortTypeClient trackClient = new EstesShipmentTracking_PortTypeClient();
trackClient.ClientCredentials.UserName.UserName = "MYUSERNAME";
trackClient.ClientCredentials.UserName.Password = "MYPASSWORD";
ESTES_Track.search trackSearch = new ESTES_Track.search();
trackSearch.requestID = "TRACK" + DateTime.Now.Ticks.ToString();
trackSearch.pro = "1710394802";
ESTES_Track.shipmentTrackingRequest trackRequest = new shipmentTrackingRequest(trackSearch);
ESTES_Track.shipmentTrackingResponse trackResponse = trackClient.shipmentTracking(trackRequest);
通信异常为:
Error in deserializing body of reply message for operation 'shipmentTracking'
There is an error in XML document (1, 575)
at System.ServiceModel.Dispatcher.XmlSerializerOperationFormatter.DeserializeBody(XmlDictionaryReader reader, MessageVersion version, XmlSerializer serializer, MessagePartDescription returnPart, MessagePartDescriptionCollection bodyParts, Object[] parameters, Boolean isRequest)
at System.ServiceModel.Dispatcher.XmlSerializerOperationFormatter.DeserializeBody(XmlDictionaryReader reader, MessageVersion version, String action, MessageDescription messageDescription, Object[] parameters, Boolean isRequest)
at System.ServiceModel.Dispatcher.OperationFormatter.DeserializeBodyContents(Message message, Object[] parameters, Boolean isRequest)
at System.ServiceModel.Dispatcher.OperationFormatter.DeserializeReply(Message message, Object[] parameters)
at System.ServiceModel.Dispatcher.ProxyOperationRuntime.AfterReply(ProxyRpc& rpc)
at System.ServiceModel.Channels.ServiceChannel.HandleReply(ProxyOperationRuntime operation, ProxyRpc& rpc)
at System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[] outs, TimeSpan timeout)
at System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCallMessage methodCall, ProxyOperationRuntime operation)
at System.ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessage message)
Exception rethrown at [0]:
at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg)
at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type)
at EstesTests.ESTES_Track.EstesShipmentTracking_PortType.shipmentTracking(shipmentTrackingRequest request)
at EstesTests.ESTES_Track.EstesShipmentTracking_PortTypeClient.shipmentTracking(shipmentTrackingRequest request) in C:\tests\EstesTests\Connected Services\ESTES_Track\Reference.cs:line 1394
at EstesTests.Program.TrackTest() in C:\tests\EstesTests\Program.cs:line 49
-=-=-=- edit -=-=-=-我可以使用SoapUI成功处理请求并获得有效响应。这使我相信我的问题是特定于Visual Studio项目的。
我的App.config文件如下所示:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.2" />
</startup>
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="estesrtshipmenttracking_base_ws_provider_soapws_EstesShipmentTracking_Binder">
<security mode="Transport">
<transport clientCredentialType="Basic"></transport>
</security>
</binding>
</basicHttpBinding>
</bindings>
<client>
<endpoint address="https://api.estes-express.com:443/ws/estesrtshipmenttracking.base.ws.provider.soapws:EstesShipmentTracking/estesrtshipmenttracking_base_ws_provider_soapws_EstesShipmentTracking_Port"
binding="basicHttpBinding" bindingConfiguration="estesrtshipmenttracking_base_ws_provider_soapws_EstesShipmentTracking_Binder"
contract="ESTES_Track.EstesShipmentTracking_PortType" name="estesrtshipmenttracking_base_ws_provider_soapws_EstesShipmentTracking_Port" />
</client>
</system.serviceModel>
</configuration>
-=-=-=-编辑-=-=-=-我明确地将其标记为“ESTES ShipmentTracking v1.1”的原因是,我非常确定这个问题我拥有的可能特定于此特定Web服务。如果某人已经拥有用于使用此Web服务的工作代码示例,则可能包含问题的解决方案。此外,我相信任何其他试图为ESTES开发航运客户端的人都会遇到这个问题。
-=-=-=-结论-=-=-=-我认为响应消息的XML内容不完全符合发布的v1.1 WSDL架构,反序列化异常特定于此Web服务实现版本。我在以前的v1.0版本中没有遇到过此问题。
1条答案
按热度按时间w51jfk4q1#
我今天遇到了同样的问题,并将其缩小到几个问题:
我写信给技术支持部门,但与此同时,我能够通过使用自定义消息检查器来操作响应,如这里所述https://blogs.msdn.microsoft.com/dsnotes/2015/04/14/wcf-simple-way-to-modify-serialized-response/。
您可以像这样将其添加到您的客户端:
希望他们能解决这个问题。如果出现其他问题,您可以在AfterReceiveReply中添加其他更改: