使用Sap WebService – 请求发送两次并且每次都失败

我正在努力消耗一个sap webservice。 我已经通过很多教程和msdn上的许multithreading,但我无法找到解决我的问题的方法:

运行我的程序最终会出现此错误:

CommunicationException not handled. -> unknown Messageversion System.ServiceModel.CommunicationException wurde nicht behandelt. HResult=-2146233087 Message=Unbekannte Nachrichtenversion. Source=mscorlib StackTrace: Server stack trace: bei System.ServiceModel.Channels.ReceivedMessage.ReadStartEnvelope(XmlDictionaryReader reader) bei System.ServiceModel.Channels.BufferedMessage..ctor(IBufferedMessageData messageData, RecycledMessageState recycledMessageState, Boolean[] understoodHeaders, Boolean understoodHeadersModified) bei System.ServiceModel.Channels.TextMessageEncoderFactory.TextMessageEncoder.ReadMessage(ArraySegment`1 buffer, BufferManager bufferManager, String contentType) bei System.ServiceModel.Channels.HttpInput.DecodeBufferedMessage(ArraySegment`1 buffer, Stream inputStream) bei System.ServiceModel.Channels.HttpInput.ReadBufferedMessage(Stream inputStream) bei System.ServiceModel.Channels.HttpInput.ParseIncomingMessage(HttpRequestMessage httpRequestMessage, Exception& requestException) bei System.ServiceModel.Channels.HttpChannelFactory`1.HttpRequestChannel.HttpChannelRequest.WaitForReply(TimeSpan timeout) bei System.ServiceModel.Channels.RequestChannel.Request(Message message, TimeSpan timeout) bei System.ServiceModel.Dispatcher.RequestChannelBinder.Request(Message message, TimeSpan timeout) bei System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[] outs, TimeSpan timeout) bei System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCallMessage methodCall, ProxyOperationRuntime operation) bei System.ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessage message) Exception rethrown at [0]: bei System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg) bei System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type) bei ConsoleApplication1.ServiceReference2.ZTST_MASS_CREATE_USER_gut.ZTST_MASS_USER_CREATE(ZTST_MASS_USER_CREATERequest request) bei ConsoleApplication1.ServiceReference2.ZTST_MASS_CREATE_USER_gutClient.ConsoleApplication1.ServiceReference2.ZTST_MASS_CREATE_USER_gut.ZTST_MASS_USER_CREATE(ZTST_MASS_USER_CREATERequest request) in C:\Users\tstaat\documents\visual studio 2010\Projects\ConsoleApplication1\ConsoleApplication1\Service References\ServiceReference2\Reference.cs:Zeile 138. bei ConsoleApplication1.ServiceReference2.ZTST_MASS_CREATE_USER_gutClient.ZTST_MASS_USER_CREATE(ZTST_USER_PWD[] USER) in C:\Users\tstaat\documents\visual studio 2010\Projects\ConsoleApplication1\ConsoleApplication1\Service References\ServiceReference2\Reference.cs:Zeile 144. bei ConsoleApplication1.Program.Main(String[] args) in C:\Users\tstaat\documents\visual studio 2010\Projects\ConsoleApplication1\ConsoleApplication1\Program.cs:Zeile 61. bei System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args) bei System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args) bei Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly() bei System.Threading.ThreadHelper.ThreadStart_Context(Object state) bei System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx) bei System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx) bei System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state) bei System.Threading.ThreadHelper.ThreadStart() InnerException: 

对我来说似乎很奇怪:

我测试了通过SoapUI创建的请求。 我不得不删除评论,然后它工作正常:

         o kkkk      

所以最后我的代码看起来像这样:

  var binding = new BasicHttpBinding(); binding.MaxReceivedMessageSize = int.MaxValue; binding.Security.Transport.ClientCredentialType = HttpClientCredentialType.Basic; binding.Security.Mode = BasicHttpSecurityMode.TransportCredentialOnly; binding.AllowCookies = true; var address = new EndpointAddress("http://host/relativeurn); //create client ServiceReference2.ZTST_MASS_CREATE_USER_gutClient client = new ServiceReference2.ZTST_MASS_CREATE_USER_gutClient(binding, address); Console.WriteLine("Created Client"); //define credentials client.ClientCredentials.UserName.UserName = "User"; client.ClientCredentials.UserName.Password = "PWD"; ServiceReference2.ZTST_USER_PWD[] parameter = new ServiceReference2.ZTST_USER_PWD[2]; parameter.Initialize(); parameter[] = something client.open(); parameter = client.ZTST_MASS_USER_CREATE(parameter); 

第二个错误是对Web服务的请求被发送两次:一次,一次没有validation。

我通过这个post: http : //social.msdn.microsoft.com/Forums/vstudio/en-US/d9f99777-f702-4c0e-8198-b110f8eacdd9/net-c-console-application-calling-sap-webservice?论坛= WCF

它不适合我,原因

  parameter = client.ZTST_MASS_USER_CREATE(parameter); 

我的程序有两个请求; 第二个被服务器接受(第一个没有validation),但返回错误:

                                        false  # 3EB6184C46517B16E1000000AC10FEEB    false true no false                                                                                

更新:

这是我的appl.config

                

愚蠢的我! 如果您在需要WEB服务参考时选择添加服务引用而不是Web服务引用,则会发生上述错误。 要将webREferenz添加到项目中:

第一步

第二步

第三步