c# - 数据包格式不正确,使用 WSDL 文件从 C# 调用 SAP 服务

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

我正在尝试使用提供给我的 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: There was no endpoint listening at https://r3snd.yaskawa.com:8000/sap/bc/srt/rfc/sap/zpc_drop_down_values/410/zpc_drop_down_values/zpc_drop_down_values that could accept the message. This is often caused by an incorrect address or SOAP action. See InnerException, if present, for more details. ---> System.Net.WebException: The remote name could not be resolved: 'r3snd.yaskawa.com' at System.Net.HttpWebRequest.GetRequestStream(TransportContext& context) at System.Net.HttpWebRequest.GetRequestStream() at System.ServiceModel.Channels.HttpOutput.WebRequestHttpOutput.GetOutputStream() --- End of inner exception stack trace ---

Server stack trace: at System.ServiceModel.Channels.HttpOutput.WebRequestHttpOutput.GetOutputStream() at System.ServiceModel.Channels.HttpOutput.Send(TimeSpan timeout) at System.ServiceModel.Channels.HttpChannelFactory`1.HttpRequestChannel.HttpChannelRequest.SendRequest(Message message, TimeSpan timeout) at System.ServiceModel.Channels.RequestChannel.Request(Message message, TimeSpan timeout) at System.ServiceModel.Dispatcher.RequestChannelBinder.Request(Message message, TimeSpan timeout) 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 ServicesFromSAP.TableReference.ZPC_DROP_DOWN_VALUES.ZpcDropDownValues(ZpcDropDownValuesRequest request) at ServicesFromSAP.TableReference.ZPC_DROP_DOWN_VALUESClient.ServicesFromSAP.TableReference.ZPC_DROP_DOWN_VALUES.ZpcDropDownValues(ZpcDropDownValuesRequest request) in C:\Users\eric_obermuller\source\repos\ServicesFromSAP\ServicesFromSAP\Connected Services\TableReference\Reference.cs:line 339 at ServicesFromSAP.TableReference.ZPC_DROP_DOWN_VALUESClient.ZpcDropDownValues(ZpcDropDownValues ZpcDropDownValues1) in C:\Users\eric_obermuller\source\repos\ServicesFromSAP\ServicesFromSAP\Connected Services\TableReference\Reference.cs:line 345 at ServicesFromSAP.Program.Main(String[] args) in C:\Users\eric_obermuller\source\repos\ServicesFromSAP\ServicesFromSAP\Program.cs:line 33

我不确定是什么问题。这项服务是出于测试/学习目的提供给我的,这样我就可以开始学习如何使用他们的服务。是否存在某种我不知道的设置?

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

最佳答案

好吧,我想通了这个问题。最初在测试此应用程序时,请求实际上是作为 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" />

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

谢谢大家看我的问题。

关于c# - 数据包格式不正确,使用 WSDL 文件从 C# 调用 SAP 服务,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52079599/

相关文章:

c# - 托管网络应用程序

c# - 制作一个函数来计算多个数组中的元素

c# - 当用户单击表头时,如何对 List<T> 进行排序?

c# - 如何在使用 C# 作为服务器代码的 ASP.NET Web 应用程序中使用 WF (Windows Workflow Foundation)

c# - 使用 List<T> 而不是 IEnumerable<T> 有什么好处?

c# - 将类型限制为特定类型

c# - 尝试访问数据库 C# asp.net 时源附近出现语法错误

WCF Web 服务 xml 序列化 [XmlAttributeAttribute()] 被忽略

vb.net - 使用 VB.NET 客户端从 Java Web 服务获取响应

jQuery 到 ASMX webservice xml 传输