XML-DA method to subscribe a set of item values with either an XML-DA or OPC-DA server.
Syntax
C# | |
---|
[SoapDocumentMethodAttribute(Action="http://opcfoundation.org/webservices/XMLDA/1.0/Subscribe",
RequestNamespace="http://opcfoundation.org/webservices/XMLDA/1.0/",
ResponseNamespace="http://opcfoundation.org/webservices/XMLDA/1.0/",
Use=SoapBindingUse.Literal,
ParameterStyle=SoapParameterStyle.Wrapped)]
public ReplyBase Subscribe(
RequestOptions Options,
SubscribeRequestItemList ItemList,
bool ReturnValuesOnReply,
int SubscriptionPingRate,
out SubscribeReplyItemList RItemList,
out OPCError[] Errors,
out string ServerSubHandle
) |
Parameters
- Options
- Container with options used in most server calls.
- ItemList
- The container for the individual Items.
It is expected that there are one or more Items per ItemList.
- ReturnValuesOnReply
- If TRUE the server will return item values which are readily available for inclusion in the SubscribeResponse. Depending on when the SubscriptionPolledRefresh is requested, these items may or may not be updated in the first SubscriptionPolledRefresh.
If FALSE the server must not deliver any item values in the SubscribeResponse. - SubscriptionPingRate
- The SubscriptionPingRate is the requested rate in milliseconds that the server should reevaluate the existence of the client. If the client has not had any communication in the specified period, then the Server is free to clean up all resources associated with that client for this Subscription.
The server should attempt to honor the client’s request, but it may reevaluate the existence of the client at a rate faster than the SubscriptionPingRate based on its own implementation, and resource constraints. If the SubscriptionPingRate is 0, then the server will use its own algorithm to reevaluate the existence of the client. It is highly recommended that clients always specify a non-zero ping rate since specifying zero will allow the server to choose a ping rate that the client will not have knowledge of and may be inappropriate. - RItemList
- The RItemList structure is the container for Item elements which carry error or value information. The readily available item values are sent back via Item elements in RItemList if and only if the client requested them with “ReturnValuesOnReply” (see Subscribe). If the server does not have a value for some of the items at the time of Subscribe, the response will provide no value element for the affected item.
If error conditions (like invalid item name or unsupported rate) are detected by the server, then Item Elements will be returned to communicate the error conditions.
If ReturnValuesOnReply is “false” and no errors are found, RItemList will be empty. - Errors
- An array of OPCError elements with the description of the errors occured in this server call.
Errors are only present if Items contain result codes.
- ServerSubHandle
- Supplied by the Server. It must be used for SubscriptionPolledRefresh and SubscriptionCancel.
ServerSubHandle is specific to the client making the request.
Return Value
Container of information that represents the basic information for most responses.
Example
Visual Basic | Copy Code |
---|
Private Sub startSubscription(ByVal Srv As XmlServer, ByVal eList As ListBuilder)
Dim sil As SubscribeRequestItemList
sil = eList.GetSubscribeItemList("Subscr2")
Dim reply As ReplyBase
Dim options As RequestOptions = New RequestOptions
options.ReturnErrorText = True
Dim rslt As SubscribeReplyItemList
Dim err As OPCError()
Try
reply = Srv.Subscribe(options, sil, True, 120, rslt, err, srvHandle)
If err Is Nothing Or err.Length = 0 Then ' no errors
Dim ival As ItemValue
For Each ival In rslt.Items
' handle initial values
Next
Else
MessageBox.Show(err(0).Text, "Error at Write")
End If
Catch ex As Exception
MessageBox.Show(ex.Message, "Exception in Subscribe")
End Try
End Sub |
C# | Copy Code |
---|
private void startSubscription( XmlServer Srv, ListBuilder elList )
{
try
{
SubscribeRequestItemList sil ;
SubscribeRequestItemList sil = eList.GetSubscribeItemList( "Subscr2" );
ReplyBase reply ;
RequestOptions options = new RequestOptions();
options.ReturnErrorText = true ;
SubscribeReplyItemList rslt ;
OPCError[] err ;
reply = Srv.Subscribe( options, sil, true, 120, out rslt, out err, out srvHandle );
if( (err != null) && (err.Length>0) )
MessageBox.Show( err[0].Text, "Error at Subscribe" );
else
{
foreach( ItemValue ival in rslt.Items )
{
// handle the initial values
}
}
}
catch( Exception ex )
{
MessageBox.Show( ex.Message, "Exception in Subscribe" );
}
} |
Requirements
Target Platforms:Windows XP Professional, Windows Server 2003 family, Windows Vista, Windows 7, Windows Server 2008 family
>
See Also