i invoke a wcf service via COM+,but i get the warining,please help/Visual Studio 2008

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
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:csharptestbinDebug>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:csharptestbinDebugbhcom.dll
Application: bhcom
TypeLib: E:csharptestbinDebugbhcom.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 = mylistproddepdc.Myprodno;
prodnamevar = mylistproddepdc.Myprodname;
prodsizevar = mylistproddepdc.Myprodsize;
lastaddvar = mylistproddepdc.Mylastadd;
retailpricevar = mylistproddepdc.Myretailprice;
belongtovar = mylistproddepdc.Mybelongto;
ysblvar = mylistproddepdc.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();
}


}


}
}
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.Myprodno = dt.Rows["prod_no"].ToString();
Proddeplist.Myprodname = dt.Rows["prod_name"].ToString();
Proddeplist.Myprodsize = dt.Rows["prod_size"].ToString();
Proddeplist.Mylastadd = dt.Rows["last_add"].ToString();
Proddeplist.Myretailprice = Convert.ToDouble(dt.Rows["retail_price"]);
Proddeplist.Mybelongto = Convert.ToInt16(dt.Rows["belong_to"]);
Proddeplist.Myysbl = Convert.ToInt16(dt.Rows["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();
}

}

} }
Ken
best regards

View the full article
 
Back
Top