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

Incorrect packet format, calling SAP service from C# with WSDL file

我正在尝试使用提供给我的 WSDL 文件来调用服务。我收到 "Unexpected Packet Format" 错误。我已经使用 SOAPUI 测试了该服务,一切正常。当我从我的 C# 应用程序调用该服务时,我收到上面提到的错误。

相关信息

代码

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

我不确定是什么问题。此服务是出于 testing/learning 目的提供给我的,因此我可以开始学习如何使用他们的服务。是否有某种我不知道的设置?

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

好的,我明白了。最初在测试此应用程序时,请求实际上是作为 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" />

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

虽然四处乱逛,但我将其改回 Http 并意识到抛出错误是因为我使用的是 HttpsTransport 而不是 HttpTransport。

Https 传输

<httpsTransport authenticationScheme="Basic" />

Http 传输(正确的一个)

<httpTransport authenticationScheme="Basic" />

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

谢谢大家看我的问题