3

我正在使用一个webserviceinvoking类从带有 C# 服务的 .NET 调用 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);
}

但是,调用它会给我一个无法识别的消息版本。例外:

{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 输出到 web 服务:

<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>

任何帮助深表感谢。

4

2 回答 2

6

SAP Pi seems to have two URL's. One for the WSDL and the other for the call. The default binding has to be changed in order to get it working to the service url defined in the port list from the WSDL.

object obj = this.webServiceAssembly.CreateInstance(
               serviceName, 
               false, 
               BindingFlags.CreateInstance, 
               null, 
               new object[] { 
                              defaultBinding, 
                              new EndpointAddress(this.webServiceUri.ToString()) 
                            }, 
               null,  
               null);
于 2013-10-23T10:57:00.703 回答
3

通常,我们(SAP PI 团队)提供从 SAP PI 生成的 WSDL 文件给合作伙伴以供使用,并且我们还与合作伙伴共享端点 URL 以及 WSDL,因此请与您的 SAP PI 团队核对 WSDL 和端点 URL。

另请注意,如果他们在 SAP PI 上更改了与此流相关的任何事物/对象,他们需要为您提供新的 WSDL,并确保用户有权访问 SAP PI 以从您的端推送消息。(其他适用的领域。,证书)。

于 2013-10-24T05:43:16.620 回答