Jump to content


  • 0
anyweb

Adding parameters to your web service

Question

Adding paramters to a webservice.

 

 

Ok now that the webservice is working, lets add two parameters (name and age) that we can pass to our webservice, go back and edit the code in Visual Studio.

 

Change this

 

using System;
using System.Collections.Generic;
using System.Web;
using System.Web.Services;

namespace windows_noob_webservice
{
   /// <summary>
   /// Summary description for Service1
   /// </summary>
   [WebService(Namespace = "http://windows-noob.com/")]
   [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
   [system.ComponentModel.ToolboxItem(false)]
   public class Service1 : System.Web.Services.WebService
   {

       [WebMethod]
       public string HelloWorld()
       {
           return "Hello World";
       }
   }
}

 

 

To this

 

 

using System;
using System.Collections.Generic;
using System.Web;
using System.Web.Services;

namespace windows_noob_webservice
{
   /// <summary>
   /// Summary description for Service1
   /// </summary>
   [WebService(Namespace = "http://windows-noob.com/")]
   [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
   [system.ComponentModel.ToolboxItem(false)]
   public class Service1 : System.Web.Services.WebService
   {

       [WebMethod]
       public string HelloWorld()
       {
           return "Hello World";
       }

       [WebMethod]
       public string HelloWorld2(string name)
       {
           return "Hi " + name;
       }

       [WebMethod]
       public string HelloWorld3(string name, string age)
       {
           return "Hi " + name + " your age is " + age;
       }

   }
}

 

Build the code (compile it) and you can simply copy the DLL found in bin to your webserver to test the new functions.

 

copy dll.jpg

 

Copy the dll to the BIN folder of your current webservice on your server…

 

bin folder.jpg

 

Copy the new web service operation to your CustomSettings.ini file and update your MDT Files package once done.

 

hellowworld3.jpg

 

Once done, test the web service,

 

test ws.jpg

 

Click on HelloWorld3

Input some values into the fields:-

 

enter values.jpg

 

And click on Invoke, the result is ouput

 

hi niall your age is 44.jpg

 

 

 

 

 

Testing webservices from WinPE

 

 

We will now Create a WSF script file called helloworld.wsf, containing the following lines

 

<job id="MDTMenu_helloworld">
<script language="VBScript" src="..\ZTIUtility.vbs"/>
<script language="VBScript" src="..\ZTIDataAccess.vbs"/>
<script language="VBScript">

Dim oService
Dim oXML
oEnvironment.Item("testing") = Wscript.Arguments.Named.Item("helloworld")

Set oService = New WebService
oService.IniFile = "CustomSettings.ini"
oService.SectionName = "helloworld"
Set oXML = oService.Query
If oXML Is Nothing Then
oLogging.CreateEntry "Unable to call HelloWorld web service.", LogTypeWarning
WScript.Echo "Not Found" & vbcrlf
Else
oXML.setProperty "SelectionNamespaces", "xmlns:wn='http://windows-noob.com/'"
WScript.Echo oXML.SelectSingleNode("wn:string").Text	
End If
</script>
</job>

 

 

Save it in the wnb subfolder of your MDT Files scripts directory. (eg: scripts\wnb)

 

Next create a new file called name_age.wsf, Paste in the following:-

 

<job id="MDTMenu_name">
<script language="VBScript" src="..\ZTIUtility.vbs"/>
<script language="VBScript" src="..\ZTIDataAccess.vbs"/>
<script language="VBScript">

Dim oService
Dim oXML
oEnvironment.Item("name") = Wscript.Arguments.Named.Item("name")
oEnvironment.Item("age") = Wscript.Arguments.Named.Item("age")

Set oService = New WebService
oService.IniFile = "CustomSettings.ini"
oService.SectionName = "helloworld3"

Set oXML = oService.Query

If oXML Is Nothing Then
oLogging.CreateEntry "Unable to call UserGetName web service.", LogTypeWarning
WScript.Echo "Not Found" & vbcrlf
Else	oXML.setProperty "SelectionNamespaces", "xmlns:wn='http://windows-noob.com/'"
WScript.Echo oXML.SelectSingleNode("wn:string").Text	
End If
</script>
</job>

 

Save the file and update your MDT files package on the distribution points.

 

update dps.jpg

 

Edit your CustomSettings.ini file, Add the following lines:-

 

[helloworld]

WebService=http://sccm/newwebservice/service1.asmx/HelloWorld

[helloworld3]

WebService=http://sccm/newwebservice/service1.asmx/HelloWorld3

Parameters=name,age

 

PXE boot into WinPE, at your FrontEndHTA screen, press F8 to bring up a command prompt, cd to the following address

 

C:\_SMSTaskSequence\WDPackage\Scripts\wnb

 

And execute this:-

 

Cscript.exe /nologo helloworld.wsf

 

The following is output

 

hello world output.jpg

 

In the screenshot above, UserDomain and UserID are actually the Network Access Account retrieved from SCCM.

(SCCMnaa) as defined in Computer Client Agent Properties.

 

sccmnaa.jpg

 

Now lets test passing values to our Hello World3 operation in our webservice, Open a command prompt in WinPE and type this:-

 

C:

Cd _SMSTaskSequence\WDPackage\Scripts\wnb

 

Then to execute the webservice try

 

Cscript.exe /nologo name_age.wsf /name:niall /age:44

 

hi niall.jpg

 

We pass two properties to the web service, name and age, and the output is seen above.

Share this post


Link to post
Share on other sites

0 answers to this question

Recommended Posts

There have been no answers to this question yet

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...


×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.