从.NET调用SAP PI端点时,出现 "未识别的消息版本"。

问题描述 投票:1回答:2

我使用的是 webserviceinvoking 类来调用.NET与C#服务中的SAP PI。

我使用下面的方法来完成这个任务。

public object InvokeMethod(string serviceName, string methodName, params object[] args)
{
    System.ServiceModel.Channels.Binding defaultBinding = new BasicHttpBinding(BasicHttpSecurityMode.None);
    if (this.credentials != null)
    {
        ((BasicHttpBinding)defaultBinding).Security.Mode = BasicHttpSecurityMode.TransportCredentialOnly;
        ((BasicHttpBinding)defaultBinding).Security.Transport.ClientCredentialType = HttpClientCredentialType.Basic; //.Ntlm;
    }

    object obj = this.webServiceAssembly.CreateInstance(serviceName, false, BindingFlags.CreateInstance, null, new object[] { defaultBinding, new EndpointAddress(this.webServiceUri.ToString()) }, null, null);

    Type type = obj.GetType();

    if (this.credentials != null)
    {
        PropertyInfo piClientCreds = type.GetProperty("ClientCredentials");
        ClientCredentials creds = (ClientCredentials)piClientCreds.GetValue(obj, null);
        creds.UserName.UserName = this.credentials.UserName;
        creds.UserName.Password = this.credentials.Password;
    }

    return type.InvokeMember(methodName, BindingFlags.InvokeMethod, null, obj, args);
}

然而调用它时,我得到了一个Unrecognized message version. 异常:

{System.ServiceModel.CommunicationException: Unrecognized message version.

Server stack trace: 
   at System.ServiceModel.Channels.ReceivedMessage.ReadStartEnvelope(XmlDictionaryReader reader)
   at System.ServiceModel.Channels.BufferedMessage..ctor(IBufferedMessageData messageData, RecycledMessageState recycledMessageState, Boolean[] understoodHeaders, Boolean understoodHeadersModified)
   at System.ServiceModel.Channels.TextMessageEncoderFactory.TextMessageEncoder.ReadMessage(ArraySegment`1 buffer, BufferManager bufferManager, String contentType)
   at System.ServiceModel.Channels.MessageEncoder.ReadMessage(Stream stream, BufferManager bufferManager, Int32 maxBufferSize, String contentType)
   at System.ServiceModel.Channels.HttpInput.ReadChunkedBufferedMessage(Stream inputStream)
   at System.ServiceModel.Channels.HttpInput.ParseIncomingMessage(Exception& requestException)
   at System.ServiceModel.Channels.HttpChannelFactory.HttpRequestChannel.HttpChannelRequest.WaitForReply(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 SIOS_Sync_CRMAccount.SIOS_Sync_CRMAccount(SIOS_Sync_CRMAccountRequest request)
   at SIOS_Sync_CRMAccountClient.SIOS_Sync_CRMAccount.SIOS_Sync_CRMAccount(SIOS_Sync_CRMAccountRequest request)
   at SIOS_Sync_CRMAccountClient.SIOS_Sync_CRMAccount(DT_CRMAccount MT_Sync_CRMAccount_request)}

Wireshark XML输出到webservice。

<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
    <s:Body xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
        <MT_Sync_CRMAccount_request xmlns="http://microsoft.com/crm/accounts">
            <recordActionType xmlns="">1</recordActionType>
            <accountnumber xmlns="">3000016</accountnumber>
            <name xmlns="">Test CRM2SAP16</name>
        </MT_Sync_CRMAccount_request>
    </s:Body>
</s:Envelope>

任何帮助都是非常感激的。

c# web-services sap sap-xi sap-pi
2个回答
5
投票

SAP Pi 似乎有两个 URL's. 一个人的 WSDL 和调用的另一个。默认的绑定必须改变, 以便使其工作到在 port 列表中定义的服务 url 上。WSDL.

object obj = this.webServiceAssembly.CreateInstance(
               serviceName, 
               false, 
               BindingFlags.CreateInstance, 
               null, 
               new object[] { 
                              defaultBinding, 
                              new EndpointAddress(this.webServiceUri.ToString()) 
                            }, 
               null,  
               null);

2
投票

通常,我们(SAP PI团队)提供WSDL文件,它是从SAP PI生成的合作伙伴来消费的,而且我们还与合作伙伴一起分享终端URL,所以与你的SAP PI团队检查WSDL和终端URL。

还请注意,如果他们已经改变了任何与此流程相关的事情对象在SAP PI,他们需要为你提供新的WSDL,并确保用户能够访问SAP PI,从你的终端推送消息。

© www.soinside.com 2019 - 2024. All rights reserved.