This discussion has been locked. The information referenced herein may be inaccurate due to age, software updates, or external references.
You can no longer post new replies to this discussion. If you have a similar question you can start a new discussion in this forum.

Create nodes with C#

Hello all,

I've been through the documentation, but I don't see any examples for using the WSDL for creating a node in vb.net or C#.  I've looked through the JAVA example and re-created in C# as far as I can see, but when I try to call client.create("Orion.Nodes", PropertBag") I get the following exception:

System.ServiceModel.CommunicationException was unhandled

  HResult=-2146233087

  Message=There was an error while trying to serialize parameter http://schemas.solarwinds.com/2007/08/informationservice:properties. The InnerException message was 'Member type in type SolarwindsAPI.SWClient.item cannot be serialized. This exception is usually caused by trying to use a null value where a null value is not allowed. The 'type' member is set to its default value (usually null or zero). The member's EmitDefault setting is 'false', indicating that the member should not be serialized. However, the member's IsRequired setting is 'true', indicating that it must be serialized. This conflict cannot be resolved.  Consider setting 'type' to a non-default value. Alternatively, you can change the EmitDefaultValue property on the DataMemberAttribute attribute to true, or changing the IsRequired property to false.'.  Please see InnerException for more details.

  Source=mscorlib

  StackTrace:

    Server stack trace:

       at System.ServiceModel.Dispatcher.DataContractSerializerOperationFormatter.SerializeParameterPart(XmlDictionaryWriter writer, PartInfo part, Object graph)

       at System.ServiceModel.Dispatcher.DataContractSerializerOperationFormatter.SerializeParameter(XmlDictionaryWriter writer, PartInfo part, Object graph)

       at System.ServiceModel.Dispatcher.DataContractSerializerOperationFormatter.SerializeParameters(XmlDictionaryWriter writer, PartInfo[] parts, Object[] parameters)

       at System.ServiceModel.Dispatcher.DataContractSerializerOperationFormatter.SerializeBody(XmlDictionaryWriter writer, MessageVersion version, String action, MessageDescription messageDescription, Object returnValue, Object[] parameters, Boolean isRequest)

       at System.ServiceModel.Dispatcher.OperationFormatter.SerializeBodyContents(XmlDictionaryWriter writer, MessageVersion version, Object[] parameters, Object returnValue, Boolean isRequest)

       at System.ServiceModel.Dispatcher.OperationFormatter.OperationFormatterMessage.OperationFormatterBodyWriter.OnWriteBodyContents(XmlDictionaryWriter writer)

       at System.ServiceModel.Channels.BodyWriterMessage.OnWriteBodyContents(XmlDictionaryWriter writer)

       at System.ServiceModel.Channels.Message.OnWriteMessage(XmlDictionaryWriter writer)

       at System.ServiceModel.Channels.BufferedMessageWriter.WriteMessage(Message message, BufferManager bufferManager, Int32 initialOffset, Int32 maxSizeQuota)

       at System.ServiceModel.Channels.TextMessageEncoderFactory.TextMessageEncoder.WriteMessage(Message message, Int32 maxMessageSize, BufferManager bufferManager, Int32 messageOffset)

       at System.ServiceModel.Channels.HttpOutput.SerializeBufferedMessage(Message message)

       at System.ServiceModel.Channels.HttpOutput.Send(TimeSpan timeout)

       at System.ServiceModel.Channels.HttpChannelFactory`1.HttpRequestChannel.HttpChannelRequest.SendRequest(Message message, 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 SolarwindsAPI.SWClient.InformationService.Create(String entityType, dictionary properties)

       at SolarwindsAPI.SWClient.InformationServiceClient.Create(String entityType, dictionary properties) in S:\Projects\CS Apps\SolarWindsAPI\SolarwindsAPI\Service References\SWClient\Reference.cs:line 381

       at SolarwindsAPI.Orion.Nodes.Node.CreateNode(Node objNode) in S:\Projects\CS Apps\SolarWindsAPI\SolarwindsAPI\Orion.Nodes.cs:line 203

       at SWAPITester.Program.Main(String[] args) in S:\Projects\CS Apps\SolarWindsAPI\SWAPITester\Program.cs:line 31

       at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)

       at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)

       at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()

       at System.Threading.ThreadHelper.ThreadStart_Context(Object state)

       at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)

       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)

       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)

       at System.Threading.ThreadHelper.ThreadStart()

  InnerException: System.Runtime.Serialization.SerializationException

       HResult=-2146233076

       Message=Member type in type SolarwindsAPI.SWClient.item cannot be serialized. This exception is usually caused by trying to use a null value where a null value is not allowed. The 'type' member is set to its default value (usually null or zero). The member's EmitDefault setting is 'false', indicating that the member should not be serialized. However, the member's IsRequired setting is 'true', indicating that it must be serialized. This conflict cannot be resolved.  Consider setting 'type' to a non-default value. Alternatively, you can change the EmitDefaultValue property on the DataMemberAttribute attribute to true, or changing the IsRequired property to false.

       Source=System.Runtime.Serialization

       StackTrace:

            at System.Runtime.Serialization.XmlObjectSerializerWriteContext.ThrowRequiredMemberMustBeEmitted(String memberName, Type type)

            at WriteitemToXml(XmlWriterDelegator , Object , XmlObjectSerializerWriteContext , ClassDataContract )

            at System.Runtime.Serialization.ClassDataContract.WriteXmlValue(XmlWriterDelegator xmlWriter, Object obj, XmlObjectSerializerWriteContext context)

            at System.Runtime.Serialization.XmlObjectSerializerWriteContext.WriteDataContractValue(DataContract dataContract, XmlWriterDelegator xmlWriter, Object obj, RuntimeTypeHandle declaredTypeHandle)

            at System.Runtime.Serialization.XmlObjectSerializerWriteContext.SerializeWithoutXsiType(DataContract dataContract, XmlWriterDelegator xmlWriter, Object obj, RuntimeTypeHandle declaredTypeHandle)

            at System.Runtime.Serialization.XmlObjectSerializerWriteContext.InternalSerialize(XmlWriterDelegator xmlWriter, Object obj, Boolean isDeclaredType, Boolean writeXsiType, Int32 declaredTypeID, RuntimeTypeHandle declaredTypeHandle)

            at WritedictionaryToXml(XmlWriterDelegator , Object , XmlObjectSerializerWriteContext , CollectionDataContract )

            at System.Runtime.Serialization.CollectionDataContract.WriteXmlValue(XmlWriterDelegator xmlWriter, Object obj, XmlObjectSerializerWriteContext context)

            at System.Runtime.Serialization.XmlObjectSerializerWriteContext.WriteDataContractValue(DataContract dataContract, XmlWriterDelegator xmlWriter, Object obj, RuntimeTypeHandle declaredTypeHandle)

            at System.Runtime.Serialization.XmlObjectSerializerWriteContext.SerializeWithoutXsiType(DataContract dataContract, XmlWriterDelegator xmlWriter, Object obj, RuntimeTypeHandle declaredTypeHandle)

            at System.Runtime.Serialization.DataContractSerializer.InternalWriteObjectContent(XmlWriterDelegator writer, Object graph, DataContractResolver dataContractResolver)

            at System.Runtime.Serialization.DataContractSerializer.InternalWriteObject(XmlWriterDelegator writer, Object graph, DataContractResolver dataContractResolver)

            at System.Runtime.Serialization.XmlObjectSerializer.WriteObjectHandleExceptions(XmlWriterDelegator writer, Object graph, DataContractResolver dataContractResolver)

            at System.Runtime.Serialization.XmlObjectSerializer.WriteObject(XmlDictionaryWriter writer, Object graph)

            at System.ServiceModel.Dispatcher.DataContractSerializerOperationFormatter.SerializeParameterPart(XmlDictionaryWriter writer, PartInfo part, Object graph)

       InnerException:

I notice that in java, there is a nodeProps.getAsSoapPropertyBag, however, this does not exist in the WSDL client?  Is this still an issue?

NPM version is 10.4

  • My C# code....

    SWClient.dictionary objParamBag = new SWClient.dictionary();
                SWClient.item objItem = new SWClient.item();

                objItem.key = "IPAddress";
                objItem.value = _IPAddr;
                objParamBag.Add(objItem);

    ...................

              

                SWClient.InformationServiceClient objClient = new InformationServiceClient("OrionProductionV3");
                objClient.ClientCredentials.UserName.UserName = "nsnvpnapi";
                objClient.ClientCredentials.UserName.Password = "nsnvpnapi";
                string ClientResponse = objClient.Create("Orion.Nodes", objParamBag);
                return ClientResponse;

  • You need to set objItem.type each time. This should the name of the .NET type stored in value. Like "System.String" or "System.Int32". Refer to the schema to know the correct type for each property.

  • Thanks, I'll give that a shot.  Also, where is the list of required fileds I keep reading about?  I don't see it on the schema pages?

  • It's in "Orion SDK.pdf", which is linked from the start menu as "Technical Reference".