LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How do I configure .NET SOAPSender AsyncCallback in LabVIEW

I have XML messages that I need to send from a LabVIEW application via SOAP protocol using .NET.  I can successfully create the SOAP envelope and send the message via the SOAPSender Send method, but I need to asyncronously process the results as well.  To use the BeginSend method of the SOAPSender class, I need to wire in an AsyncCallback.  How do I create this object in LabVIEW and what are the contents of the callback routine to retrieve the results.  Any code examples would be a great help.
0 Kudos
Message 1 of 6
(5,685 Views)
LabVIEW 8 introduced support for .NET events but we don't have support for raw delegates (the AsyncCallback parameter). However, here are a couple things to consider...
 
1. If the remote application is a full web service (and if it takes SOAP messages, it probably is), you might want to try the following VI, which creates all of the necessary wrapper code to talk to the web service from LabVIEW. It saves you from messing with the low level XML. Note that the remote web service doesn't necessarily need to be written in .NET, but there are some compatibility issues in the earlier web service implementations between the different companies.
 
 
2. What level of async support do you need? LabVIEW approaches multi-threaded applications differentlly than text languages, so you may be able to do what you need via the LV language itself.
 
3. If you want to use the async model from the .NET code, we'll need to create a simple wrapper that fires a .NET event when the method returns. This is pretty easy and I can whip up some C# code for you if you want to go that direction...
0 Kudos
Message 2 of 6
(5,680 Views)
We have looked into option 1.  We already have XML in our LV application and their web service interface would require unparsing the XML to wire each attribute individually so this is a possibility, but seems like unneccesary work if we can just wrap and send the existing XML.  Basically we are sending a message and need to asyncronously wait for a "accepted" response XML message or a standard soap:Fault response.  If you could provide me some C# code that would be a great help.  I'm new to .NET so trying to understand .NET and get it into LV has been quite a challenge.
0 Kudos
Message 3 of 6
(5,677 Views)
I believe this should do it. It compiles but I haven't tested it - let me know if it works for you. Don't forget, when building the assembly, to include Microsoft.Web.Services2.
 

using

System;

using

Microsoft.Web.Services2;

using

Microsoft.Web.Services2.Addressing;

using

Microsoft.Web.Services2.Messaging;

namespace

Example

{

public class SOAPSenderWithEvents : SoapSender

{

   public event AsyncCallback SendCompleteEvent;

   public SOAPSenderWithEvents() : base()

   {

   }

   public SOAPSenderWithEvents(EndpointReference destination) : base(destination)

   {

   }

   public SOAPSenderWithEvents(Uri arg) : base(arg)

   {

   }

   public IAsyncResult BeginSendWithEvent(SoapEnvelope envelope, object state)

   {

      AsyncCallback delegateInstance =

new AsyncCallback(MyAsyncCallback);

      return BeginSend(envelope, delegateInstance, state);

   }

   private void MyAsyncCallback(IAsyncResult ar)

   {

      if (SendCompleteEvent != null)

         SendCompleteEvent(ar);

   }

}

}

0 Kudos
Message 4 of 6
(5,669 Views)
Is there anything special I need to do when compiling these into a DLL for inclusion into LabView.  I did the following:

 

csc /t:library /r:C:\...\Microsoft.Web.Services2.dll asyncResult.cs

When I execute it in LabView I get the following error at the call to the constructor  for SOAPSenderWithEvents passing it a Uri as an arg:

Error 1172 occurred at File or assembly name asyncResult, or one of its dependencies, was not found

I’ve seen this with other sample C# web service examples I’ve tried to create and run through LabView.  They seem to compile and link in fine, but fail to run.

0 Kudos
Message 5 of 6
(5,659 Views)
This sounds like an issue with trying to find the assemblies. I believe you are using LV 7.x, right? If so, then there are some issues about the directory for the assembly. I recommend moving the assembly you created into the same directory as the top level VI that you are trying to run. This requirement has been removed in LV 8, so if that is the version you are using, let me know.

Let me know if that does the trick. I have some other things to try, but I'm guessing this is the problem.
0 Kudos
Message 6 of 6
(5,647 Views)