Wrox Programmer Forums
Go Back   Wrox Programmer Forums > .NET > Other .NET > .NET Web Services
|
.NET Web Services Discussions about .NET XML Web Service technologies including ASMX files, WSDL and SOAP.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the .NET Web Services section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old July 2nd, 2003, 09:39 AM
Registered User
 
Join Date: Jul 2003
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default How to call WMI from web service?

Hi,

I have trouble to call WMI from the web service.

The code is like the following:
==================


using System;

using System.Collections;

using System.ComponentModel;

using System.Data;

using System.Diagnostics;

using System.Web;

using System.Web.Services;

using System.Text;

using System.Management;

using System.Configuration;



namespace MyWMI

{

    /// <summary>

    /// Summary description for ADSSrv.

    /// </summary>

    ///

    public class MyWMI : System.Web.Services.WebService

    {

        public MyWMI()

        {

            //CODEGEN: This call is required by the ASP.NET Web Services Designer

            InitializeComponent();



        }



        #region Component Designer generated code



        //Required by the Web Services Designer

        private IContainer components = null;



        /// <summary>

        /// Required method for Designer support - do not modify

        /// the contents of this method with the code editor.

        /// </summary>

        private void InitializeComponent()

        {

        }



        /// <summary>

        /// Clean up any resources being used.

        /// </summary>

        protected override void Dispose( bool disposing )

        {

            if(disposing && components != null)

            {

                components.Dispose();

            }

            base.Dispose(disposing);

        }



        #endregion





        [WebMethod]

        public string MyTest()

        {

            try

            {

                ManagementClass someClass = new ManagementClass("\\\\.\\root\\someclassname");

                ManagementObject objDevice = someClass.CreateInstance();



                // set device properties

                objDevice["Name"] = "sample1.example.com";

                objDevice["Description"] = "Sample device";



                // create device instance

                objDevice.Put();

                return "success";

            }

            catch(Exception ex)

            {

                return ex.ToString();

            }

        }

             }

}




=============================


I run this web service with WMI on the same server with Administrator privilage and I also add user ASPNET to the Administrator group.

But the web service return the following error message:
=======================================
System.Management.ManagemetException:
Access denied at System.Management.ManagementException.ThrowWithExt endedInfo(ManagementStat atus errorCode) System.Management.ManagementObject.Put(PutOptions options) at System.Management.ManagementObject.Put() at MyTest()
========================================


Does anyone know what's wrong with the code?

Thanks,
 
Old July 22nd, 2003, 11:58 PM
Authorized User
 
Join Date: Jun 2003
Posts: 97
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to planeswalk
Default

Hi,

You can follow the steps below although I am not sure if this is the only thing that needs to get done. If you are logged into the machine where you are trying to use WMI:

1. Go to Programs -> Admin Tools -> Computer Management, then expand the Services and Applications tree node.

2. Right-click WMI Control and click Properties.

3. Go to the Advanced tab and add the ASPNET username with at least Read permissions.

Hope this helps....


Cheers!
Marlon





Similar Threads
Thread Thread Starter Forum Replies Last Post
Web service call error Tomi J2EE 0 February 1st, 2008 06:22 AM
Web Service call fails gurujeet .NET Web Services 10 December 18th, 2006 06:28 PM
call web service from pocket pc rsa3des .NET Web Services 1 June 7th, 2006 07:41 AM
Call a Web Service deer_reema ASP.NET 1.0 and 1.1 Basics 1 April 28th, 2006 10:12 AM
How to call WMI from web service? yezh99 VS.NET 2002/2003 1 July 14th, 2003 10:45 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.