none
i invoke a wcf service via COM+,but i get the warining,please help/VS 2008 RRS feed

  • Question

  • hello  , i tried to invoke the WCF service via COM+ for the legacy VB6 project using,but i have failed,please help.

    i have got the warining when i registing the COM+:

    E:\csharptest\bin\Debug>regsvcs /c bhcom.dll
    Microsoft (R) .NET Framework Services Installation Utility Version 2.0.50727.542
    0
    Copyright (c) Microsoft Corporation.  All rights reserved.

    Type library exporter warning processing 'bhcom.ServiceReference.Service1Client,
     bhcom'. Warning: Type library exporter encountered a type that derives from a g
    eneric class and is not marked as [ClassInterface(ClassInterfaceType.None)]. Cla
    ss interfaces cannot be exposed for such types. Consider marking the type with [
    ClassInterface(ClassInterfaceType.None)] and exposing an explicit interface as t
    he default interface to COM using the ComDefaultInterface attribute.
    Type library exporter warning processing 'bhcom.ServiceReference.Proddepinfo.ext
    ensionDataField, bhcom'. Warning: The public struct contains one or more non-pub
    lic fields that will be exported.

    Installed Assembly:
            Assembly: E:\csharptest\bin\Debug\bhcom.dll
            Application: bhcom
            TypeLib: E:\csharptest\bin\Debug\bhcom.tlb

    Type library exporter warning processing 'bhcom.ServiceReference.Proddepinfo.extensionDataField, bhcom'. Warning: The public struct contains one or more non-public fields that will be exported.

    my COM+ source code:

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Runtime.InteropServices;
    using System.Security.Cryptography.X509Certificates;
    using System.Configuration;
    using System.ServiceModel;
    using System.ServiceModel.Channels;
    using System.Windows;
    using System.EnterpriseServices;




    namespace bhcom
    {

        [Guid("04FF5B4F-BAF3-4eb7-9250-1A77863415E6")]
        [ComVisible(true)]


        public interface InvokeWCFInterface
        {

            string invokgetproddep(ref string[] prodnovar, ref string[] prodnamevar, ref string[] prodsizevar, ref string[] lastaddvar, ref double[] retailpricevar, ref int[] belongtovar, ref int[] ysblvar, string wcfaddr, string theusername, string thepw);



        }



        [Guid("96425A2C-06DE-43c4-81FC-E88CF00BE464")]
        [ClassInterface(ClassInterfaceType.None)]
        [ComVisible(true)]
        public class Bhclass : ServicedComponent, InvokeWCFInterface
        {


            public string invokgetproddep(ref string[] prodnovar, ref string[] prodnamevar, ref string[] prodsizevar, ref string[] lastaddvar, ref double[] retailpricevar, ref int[] belongtovar, ref int[] ysblvar, string wcfaddr, string theusername, string thepw)
            {

               
                ServiceReference.Service1Client m_proxy = new ServiceReference.Service1Client();
              
               

                int rowcount = 0;
                int i = 0;
                ServiceReference.Proddepinfo[] mylistproddepdc = new ServiceReference.Proddepinfo[8000];
                try
                {
                    mylistproddepdc = m_proxy.GetProddepinfo(ref rowcount);



                    for (i = 0; i < rowcount; i++)
                    {
                        prodnovar[i] = mylistproddepdc[i].Myprodno;
                        prodnamevar[i] = mylistproddepdc[i].Myprodname;
                        prodsizevar[i] = mylistproddepdc[i].Myprodsize;
                        lastaddvar[i] = mylistproddepdc[i].Mylastadd;
                        retailpricevar[i] = mylistproddepdc[i].Myretailprice;
                        belongtovar[i] = mylistproddepdc[i].Mybelongto;
                        ysblvar[i] = mylistproddepdc[i].Myysbl;

                    }


                    return "invoke WCF succesful";
                }


                catch (FaultException<ServiceReference.GetProddepinfoFault> ex)
                {
                    System.Windows.Forms.MessageBox.Show("error occur:" + ex.Detail.Operation + "  reason:" + ex.Detail.ProblemType);
                    m_proxy.Abort();
                    return "invoke WCF failed";
                }
                catch (CommunicationException ex)
                {
                    System.Windows.Forms.MessageBox.Show("error occur:" + ex.ToString());
                    m_proxy.Abort();
                    return "invoke WCF failed";
                }
                catch (Exception ex)
                {
                    System.Windows.Forms.MessageBox.Show("error occur:" + ex.ToString());
                    m_proxy.Abort();
                    return "invoke WCF failed";
                }

                finally
                {
                    if (m_proxy != null)
                        m_proxy.Close();
                }


            }


        }
    }

    Ken

    best regards







    • Edited by ken yup Thursday, March 7, 2013 12:14 PM
    Wednesday, March 6, 2013 1:01 PM

Answers

  • i cant comfirm the former post,because i didnt know how to use that code,but i finally found the answer, the answer is the following link,

    http://www.codeproject.com/Articles/87753/Using-T4-to-Generate-a-Wrapper-for-a-WCF-Client

    follow this example,you can inovk the WCF service via COM+,this post is over now,thanks the poeple for watching

    • Marked as answer by ken yup Saturday, March 9, 2013 8:15 AM
    Saturday, March 9, 2013 8:14 AM

All replies

  • service side:

    using System;
    using System.Collections;
    using System.Linq;
    using System.Runtime.Serialization;
    using System.ServiceModel;
    using System.Text;

    namespace bhnew
    {
       
        [ServiceContract]
        public interface IService1
        {

            [OperationContract]
            [FaultContract(typeof(GetProddepinfoFault))]
            Proddepinfo[] GetProddepinfo(ref int returnrowscount);

           
        }                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               


      
        [DataContract]
        public struct Proddepinfo
        {
            

            [DataMember]
            public string Myprodno
            {
                get;
                set;
            }
            [DataMember]
            public string Myprodname
            {
                get;
                set;
            }
            [DataMember]
            public string Myprodsize
            {
                get;
                set;
            }
            [DataMember]
            public string Mylastadd
            {
                get;
                set;
            }
            [DataMember]
            public double Myretailprice
            {
                get;
                set;
            }
            [DataMember]
            public int Mybelongto
            {
                get;
                set;
            }
            [DataMember]
            public int Myysbl
            {
                get;
                set;
            }

        }



        [DataContract]
        public class GetProddepinfoFault
        {

            private string operation;
            private string problemType;

            [DataMember]
            public string Operation
            {
                get { return operation; }
                set { operation = value; }
            }

            [DataMember]
            public string ProblemType
            {
                get { return problemType; }
                set { problemType = value; }
            }

        }

        


    }

    using System;
    using System.Collections;
    using System.Linq;
    using System.Runtime.Serialization;
    using System.ServiceModel;
    using System.Text;
    using System.Data;
    using System.Data.SqlClient;
    using System.ServiceModel.Channels;
    using System.Runtime.Serialization.Formatters.Binary;
    using System.IO;
    using System.IO.Compression;

    namespace bhnew
    {
      
        public class Service1 : IService1
        {
            public Proddepinfo[] GetProddepinfo(ref int returnrowscount)
            {
                 
            

                string connstring1 = @"server =192.168.0.254;database=yyxt01;uid=sa;pwd=''";
                string sqlquery1 = @"SELECT prod_no,prod_name,prod_size,last_add,retail_price,1 as belong_to,ys_bl  FROM product  where prod_no in (select prod_no from prod_dep) and sell_stop<>1 order by prod_no";
                SqlConnection conn1 = null;
                SqlDataReader reader1 = null;
                
               
                int i = 0;
                int rowscount = 0;
                       
                try
                {
                    conn1 = new SqlConnection(connstring1);
                    conn1.Open();
                    SqlCommand cmd1 = new SqlCommand(sqlquery1, conn1);
                    reader1 = cmd1.ExecuteReader();


                    if (reader1.HasRows)
                    {
                        DataTable dt = new DataTable();
                        dt.Load(reader1);
                        rowscount = dt.Rows.Count;
                        

                        returnrowscount = rowscount;

                        Proddepinfo[] Proddeplist = new Proddepinfo[rowscount];

                       for (i=0;i<rowscount;i++)
                        {

                            Proddeplist[i].Myprodno = dt.Rows[i]["prod_no"].ToString();
                            Proddeplist[i].Myprodname = dt.Rows[i]["prod_name"].ToString();
                            Proddeplist[i].Myprodsize = dt.Rows[i]["prod_size"].ToString();
                            Proddeplist[i].Mylastadd = dt.Rows[i]["last_add"].ToString();
                            Proddeplist[i].Myretailprice = Convert.ToDouble(dt.Rows[i]["retail_price"]);
                            Proddeplist[i].Mybelongto = Convert.ToInt16(dt.Rows[i]["belong_to"]);
                            Proddeplist[i].Myysbl = Convert.ToInt16(dt.Rows[i]["ys_bl"]);

                            i++;

                        }

                        return Proddeplist;
                    }
                    else
                    {
                        throw new Exception("database db01 record is null,it occur exeption");
                    }
                }
                catch (Exception ex)
                {
                    GetProddepinfoFault gpdf = new GetProddepinfoFault();
                    gpdf.Operation = "GetProddepinfo method in database db01 occur exception";
                    gpdf.ProblemType = ex.ToString();
                    string expmessag = ex.ToString();
                    if (expmessag.Length > 900)
                    expmessag.Substring(0, 900);
                    throw new FaultException<GetProddepinfoFault>(gpdf, expmessag);

                }
                finally
                {
                    if(reader1!=null)
                    reader1.Close();
                    if(conn1!=null)
                    conn1.Close();
                }
                  
                }      
            
        }   

    }
    • Edited by ken yup Wednesday, March 6, 2013 1:44 PM
    Wednesday, March 6, 2013 1:12 PM
  • http://stackoverflow.com/questions/5480448/issues-with-com-dll-calling-wcf-service

    this article said that he was succesuful invoke the WCF service via COM+ that he using the proxy of generate by add service reference. im used the proxy generated by add service reference as well,why i just failed?

    Friday, March 8, 2013 12:28 AM
  • is it impossible to do it? can some one answer me?if it's impossbile to make it,i will try another method and i will not waste time to search the web to resovle this problem
    Friday, March 8, 2013 1:46 PM
  • i just have searched a web page that a method can invoke the WCF service via COM+,i didn't confirmed it,but i will share the result after i try the following code

    http://www.west-wind.com/weblog/posts/2007/Dec/16/WCF-Clients-and-COM-Interop

    Friday, March 8, 2013 1:57 PM
  • i cant comfirm the former post,because i didnt know how to use that code,but i finally found the answer, the answer is the following link,

    http://www.codeproject.com/Articles/87753/Using-T4-to-Generate-a-Wrapper-for-a-WCF-Client

    follow this example,you can inovk the WCF service via COM+,this post is over now,thanks the poeple for watching

    • Marked as answer by ken yup Saturday, March 9, 2013 8:15 AM
    Saturday, March 9, 2013 8:14 AM