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 May 5th, 2005, 09:59 AM
Registered User
 
Join Date: May 2005
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Default Using MAPI with a Web Service

Hello,

I'm trying to use MAPI with a web service in C#, I'm trying to use this MAPI33.dll found at http://www.mapi33.adexsolutions.com but i can't figure out how to set it up for use with a webservice.

NOTE: this works as a console application.

here's the code, it just tries to send an email.

-------------------------------------------------------------
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Web;
using System.Web.Services;

using MAPI33;

namespace WebService1
{
    public class Service1 : System.Web.Services.WebService
    {
        public Service1()
        {
            //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;

        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 MAPITest()
        {
            try
            {
                Error hr;
                IMAPISession session;

                // Initialise MAPI interface driver
                MAPIINIT map = new MAPIINIT();

                map.Flag = MAPIINIT.FLAGS.NTService;

                hr = MAPI.Initialize(map);

                string[] problems;

                hr = MAPI.LogonEx(IntPtr.Zero, "username", "pass",

                    MAPI.FLAGS.NTService
                    | MAPI.FLAGS.NoMail
                    | MAPI.FLAGS.NewSession
                    | MAPI.FLAGS.ExplicitProfile,

                    out session);

                MAPI33.Helpers.Message.Send(
                    MAPI33.Helpers.Message.SendFlags.CopyToSentItems,
                    session,
                    new string[] {"[email protected]"},
                    null,
                    null,
                    "WEBService Test",
                    "test",
                    null,
                    out problems
                    );

                MAPI.Uninitialize();
            }
            catch (System.Exception e)
            {
                return e.ToString();
            }
            return "success";
        }
    }
}

 
Old May 5th, 2005, 10:14 AM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

Why don't you use the classes that are built in to .NET for sending mail?

-Peter
 
Old May 5th, 2005, 10:21 AM
Registered User
 
Join Date: May 2005
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Quote:
quote:Originally posted by planoie
 Why don't you use the classes that are built in to .NET for sending mail?

-Peter
I have to use MAPI, I need it for more than just sending email, i have to communicate with three different mail stores, Domino, GroupWise and Exchange, and get information on Messages, Calendar, Tasks etc.

This is for an automated testing project

 
Old May 5th, 2005, 10:46 AM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

Ok then... so what is the problem? I don't see a question in your first post. It looks like you are already on your way to using it.

-Peter
 
Old May 5th, 2005, 10:53 AM
Registered User
 
Join Date: May 2005
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Quote:
quote:Originally posted by planoie
 Ok then... so what is the problem? I don't see a question in your first post. It looks like you are already on your way to using it.

-Peter
It doesn't work as a web service, only as a console application. The code above doesn't work

 
Old May 5th, 2005, 12:51 PM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

Can you describe more about how it doesn't work? Are you getting error messages?
(You don't need to quote every post unless there's a specific part you want to refer to.)

-Peter
 
Old May 5th, 2005, 01:32 PM
Registered User
 
Join Date: May 2005
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Default

well, for some reason i cannot logon using MAPI with a web service, i get "Logon Failed NotInitialized" returned when i Invoke this from the web service.

This code works perfectly fine, if i replace the username, pass with valid ones, and I run it as a console app, and not a web service

I know that some other steps are required to have this work as a webservice, but i do not know what they are. I read some stuff on how to do this using C++ but i'm not able to duplicate that in C#

here's the code that just tries to logon
----------------------------------------


using System;
...

using MAPI33;

namespace WebService1
{
...
        [WebMethod]
        public string MAPITest()
        {
            try
            {
                Error hr;
                IMAPISession session;

                // Initialise MAPI interface driver
                MAPIINIT map = new MAPIINIT();

                map.Flag = MAPIINIT.FLAGS.NTService | MAPIINIT.FLAGS.NTService;

                hr = MAPI.Initialize(map);

                string[] problems;

                hr = MAPI.LogonEx(
                    IntPtr.Zero, "username",
                    "pass",
                    MAPI.FLAGS.NTService
                    | MAPI.FLAGS.NoMail
                    | MAPI.FLAGS.NewSession
                    | MAPI.FLAGS.ExplicitProfile,
                    out session);

                if (hr == 0)
                {
                    return ("Logon Successful");
                }
                else
                {
                    return ( "Logon Failed " + hr.ToString());
                }
                MAPI.Uninitialize();
            }
            catch (System.Exception e)
            {
                return e.ToString();
            }
            return "success";
        }
    }
}


 
Old May 5th, 2005, 02:37 PM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

I don't want to sound like I'm passing the buck... but this sounds like it's a problem with the component you are using which is outside the scope of .NET. However, that doesn't really explain why you'd experience different problems between a console app and web service.

Just to clarify something: you keep saying "run it as a web service". Am I right in assuming that you mean "run it FROM a web service"? Cause from your code samples, you are building a web service that is consuming this control. The control itself is not a web service.

Quote:
quote:This code works perfectly fine, if i replace the username, pass with valid ones, and I run it as a console app, and not a web service
Have you tried keeping all things constant except for the change in application type? I mean, the statement "if i replace the username, pass with valid ones" makes me think, "What good is it to try to run the component with an invalid username and password?" Point being, it sounds like you are trying to change too much all at once. Try it one step at a time.

-Peter
 
Old May 5th, 2005, 02:48 PM
Registered User
 
Join Date: May 2005
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I guess what i need is someone to explain the steps involved in using MAPI from a web service or NT Service, and how that is different than running it as a normal application



 
Old May 5th, 2005, 02:52 PM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

That's my point. It shouldn't be. Consuming a component in .NET shouldn't be any different based on what kind of application you are consuming it in. Granted, certain application types have limitations (you can't use a messagebox in a webforms app) but for what you are doing, it shouldn't matter.

-Peter





Similar Threads
Thread Thread Starter Forum Replies Last Post
Web Service Consuming another web service CraigWhitfield EJB 0 January 10th, 2008 08:38 AM
web service windows_mss ASP.NET 2.0 Professional 0 January 29th, 2007 12:54 AM
Error to Add Web Reference from a Web service jdjbarrios ASP.NET 2.0 Professional 0 July 18th, 2006 02:58 PM
Service Oriented Web Service aldwinenriquez .NET Web Services 2 September 15th, 2005 03:25 AM





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