【问题标题】:Incorrect packet format, calling SAP service from C# with WSDL file数据包格式不正确,使用 WSDL 文件从 C# 调用 SAP 服务
【发布时间】:2018-08-29 14:14:19
【问题描述】:

我正在尝试使用提供给我的 WSDL 文件调用服务。我收到“意外的数据包格式”错误。我已经使用 SOAPUI 测试了该服务,并且一切正常。当我从我的 C# 应用程序调用该服务时,我收到了上面提到的错误。

相关信息

  • 服务由 SAP 提供
  • 使用 .WSDL 文件导入服务
  • 在控制台应用程序内进行测试
  • 我已经测试了我的 SAP 小组提供的其他服务,效果很好。

代码

ZPC_DROP_DOWN_VALUESClient client = new ZPC_DROP_DOWN_VALUESClient();
client.ClientCredentials.UserName.UserName = "ERICO";
client.ClientCredentials.UserName.Password = "Password";
ZpcDropDownValues vals = new ZpcDropDownValues();
vals.Uom = "X";
ZpcDropDownValuesResponse Response = new ZpcDropDownValuesResponse();            

try
{
    Response = client.ZpcDropDownValues(vals);
}
catch (Exception ex)
{
    Console.WriteLine(ex.ToString());
}
Console.ReadKey();

这是堆栈跟踪:

System.ServiceModel.EndpointNotFoundException:在https://r3snd.yaskawa.com:8000/sap/bc/srt/rfc/sap/zpc_drop_down_values/410/zpc_drop_down_values/zpc_drop_down_values 处没有可以接受消息的端点侦听。这通常是由不正确的地址或 SOAP 操作引起的。有关更多详细信息,请参阅 InnerException(如果存在)。 ---> System.Net.WebException:无法解析远程名称:'r3snd.yaskawa.com' 在 System.Net.HttpWebRequest.GetRequestStream(TransportContext& 上下文) 在 System.Net.HttpWebRequest.GetRequestStream() 在 System.ServiceModel.Channels.HttpOutput.WebRequestHttpOutput.GetOutputStream() --- 内部异常堆栈跟踪结束 ---

服务器堆栈跟踪: 在 System.ServiceModel.Channels.HttpOutput.WebRequestHttpOutput.GetOutputStream() 在 System.ServiceModel.Channels.HttpOutput.Send(时间跨度超时) 在 System.ServiceModel.Channels.HttpChannelFactory`1.HttpRequestChannel.HttpChannelRequest.SendRequest(消息消息,TimeSpan 超时) 在 System.ServiceModel.Channels.RequestChannel.Request(消息消息,TimeSpan 超时) 在 System.ServiceModel.Dispatcher.RequestChannelBinder.Request(消息消息,TimeSpan 超时) 在 System.ServiceModel.Channels.ServiceChannel.Call(字符串操作,布尔单向,ProxyOperationRuntime 操作,Object[] 输入,Object[] 输出,TimeSpan 超时) 在 System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCallMessage methodCall, ProxyOperationRuntime 操作) 在 System.ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessage 消息)

在 [0] 处重新抛出异常: 在 System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg,IMessage retMsg) 在 System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData,Int32 类型) 在 ServicesFromSAP.TableReference.ZPC_DROP_DOWN_VALUES.ZpcDropDownValues(ZpcDropDownValuesRequest 请求) 在 C:\Users\eric_obermuller\source\repos\ServicesFromSAP\ServicesFromSAP\Connected Services\TableReference\Reference.cs:line 339 中的 ServicesFromSAP.TableReference.ZPC_DROP_DOWN_VALUESClient.ServicesFromSAP.TableReference.ZPC_DROP_DOWN_VALUES.ZpcDropDownValues(ZpcDropDownValuesRequest 请求) 在 C:\Users\eric_obermuller\source\repos\ServicesFromSAP\ServicesFromSAP\Connected Services\TableReference\Reference.cs: 345 中的 ServicesFromSAP.TableReference.ZPC_DROP_DOWN_VALUESClient.ZpcDropDownValues(ZpcDropDownValues ZpcDropDownValues1) 在 C:\Users\eric_obermuller\source\repos\ServicesFromSAP\ServicesFromSAP\Program.cs:line 33 中的 ServicesFromSAP.Program.Main(String[] args) 处

我不确定问题是什么。这项服务是为了测试/学习目的而提供给我的,所以我可以开始学习如何使用他们的服务。有什么我不知道的设置吗?

任何建议将不胜感激。不确定我是否需要将超时设置为更长或类似的东西。我到处寻找答案,看来这是一个个案问题。

【问题讨论】:

    标签: c# asp.net web-services service sap


    【解决方案1】:

    好吧,我想通了。最初在测试此应用程序时,请求实际上是作为 Http 请求发送给我的。

    App.Config 中的端点

    <endpoint address="http://R3SND.yaskawa.com:8000/sap/bc/srt/rfc/sap/zpc_drop_down_values/410/zpc_drop_down_values/zpc_drop_down_values"
                binding="customBinding" bindingConfiguration="ZPC_DROP_DOWN_VALUES"
                contract="TableReference.ZPC_DROP_DOWN_VALUES" name="ZPC_DROP_DOWN_VALUES" />
    

    当我尝试应用程序时,我收到一条错误消息,提示“无效的 URI Http,应使用 Https”。不太清楚发生了什么,我将端点地址更改为 Https 而不是 Http。这就是上面提到的错误发生的地方。

    在搞砸的时候,我把它改回 Http 并意识到错误被抛出,因为我使用的是 HttpsTransport 而不是 HttpTransport。

    Https 传输

    <httpsTransport authenticationScheme="Basic" />
    

    Http传输(正确的一个)

    <httpTransport authenticationScheme="Basic" />
    

    我希望这可以帮助其他人,因为这让我发疯了!

    感谢大家关注我的问题。

    【讨论】:

    • 能否提供完整的sn-p代码。我也遇到了丢失端点的相同错误。我不确定我应该给出什么端点?我的代码也在 SOAP UI 中工作。这对我很有帮助
    • 如果您将 wsdl 文件导入到项目中。您应该在 app.config 中看到上述代码。检查 http 传输部分并验证它与您的 wsdl 文件的正确类型匹配。
    • 是否需要在某处传递远程地址和端点?因为我与指定 EndPoint 相关
    猜你喜欢
    • 2013-03-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多