I'm not really a VB.NET guy, haven't touched VB since version 6, but I'm to understand that people experienced with it wouldn't have much trouble reading/translating between it and C#, which to do only what is asked here would look something like this (all the code has just been dumped into the button's action/event handler routine):
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;[color=#554dc9]
using IdeaSubmissionDemo.IdeaService; // IdeaService is the name I gave to the Service Reference added to the project pointing to http://myserver/niku/wsdl/Object/Ideas
using System.Xml;
using System.ServiceModel;
using System.ServiceModel.Description;[color]
namespace IdeaSubmissionDemo
{
public partial class IdeaForm : Form
{
public IdeaForm()
{
InitializeComponent();
}
[color=#554dc9]
private void SubmitIdea_Click(object sender, EventArgs e)
{
IdeasPortClient ipc = new IdeasPortClient();
IdeasPort ip = ipc.ChannelFactory.CreateChannel(new EndpointAddress(Properties.Settings.Default.endpoint));
// Logging in
Login creds = new Login();
creds.Username = Properties.Settings.Default.username;
creds.Password = Properties.Settings.Default.password;
Auth auth = new Auth();
LoginRequest loginRequest = new LoginRequest(creds);
auth.SessionID = ip.Login(loginRequest).SessionID;
// Populating idea submission details
XmlDocument request = new XmlDocument();
request.LoadXml(@"<NikuDataBus xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance""
xsi:noNamespaceSchemaLocation=""../xsd/nikuxog_idea.xsd"">
<Header action=""write"" externalSource=""NIKU"" objectType=""idea"" version=""8.0""/>
<Ideas>
<Idea objectID=""temp"" lastUpdatedBy=""admin""
lastUpdatedDate=""2006-02-17T12:06:10"" managerUserName=""admin""
status=""0"" name=""temp"" description=""temp"">
<CustomInformation>
<ColumnValue name=""partition_code"">NIKU.ROOT</ColumnValue>
</CustomInformation>
</Idea>
</Ideas>
</NikuDataBus>");
XmlNode node = request.SelectSingleNode("//@objectID");
node.Value = IdeaName.Text; // Note: Reused name as the ID, handle/populate this better in a 'for real' case
node = request.SelectSingleNode("//@name");
node.Value = IdeaName.Text;
node = request.SelectSingleNode("//@description");
node.Value = IdeaDescription.Text;
node = request.SelectSingleNode("//@lastUpdatedDate");
node.Value = DateTime.Now.ToString("yyyy-MM-ddTHH:mm:ss");
Console.WriteLine("-------------------------------------------------------------");
Console.WriteLine("Request: ");
Console.WriteLine(request.OuterXml);
// Submitting idea
WriteIdeaRequest ideaRequest = new WriteIdeaRequest(auth, request.DocumentElement);
WriteIdeaResponse ideaResponse = ip.WriteIdea(ideaRequest);
Console.WriteLine("Response: ");
Console.WriteLine(ideaResponse.WriteIdeaResponse1.OuterXml);
// Logging out -- exception handling needed at minimum since a non/null response is sort of unexpected here
try
{
ip.Logout(auth.SessionID);
}
catch (ProtocolException)
{
// ignore throw;
}
catch (Exception)
{
throw;
}
// Report success or fail or otherwise here
// ...
}[color]
}
}
To make it flexible enough to handle different endpoints (otherwise running it would fail for you without regenerating the service proxy code again, since you can't connect to my endpoint), the code isn't quite as trivial as it could otherwise have looked, but it's still relatively small and simple.
Attached are the project files (sources, properties, and debug binary).
To change the username, password, and endpoint to your own needed values, change the Settings.settings file contents in the Solution Explorer window of Visual Studio.
I hope that will do!
Edit: Emboldened the code that was added to the initial boiler template Form code given to you by default.