c#编写com使用对webservice调用
2013-09-05 17:52
309 查看
c#编写com使用对webservice调用 , 开发环境为vs2010 问题总结。
1. 生成一个classs lib后 没有service refernece项, 解决 先加入一个from1窗口后,才能add servcie refernece,
2. 然后是接口定义 传出的参数要这样写
ref float dx, ref float dy.
3.
.MobileServiceClient(bind, address); 这个webs对象使用带两个参数的构造函数,
第一个参数为 WSHttpBinding 类型,支持soap1.2的bind,
4. 之后是com组件的编译 这个网上有不少。遇到net f4.0时要加入csharp引用。
namespace MyLib
{
[ComVisible(true)]
[Guid("0BDD4AEC-A0C7-4949-BEE3-0F15ACF3FF5E")]
public interface IMyClass
{
[DispId(1)]
void Initialize();
[DispId(2)]
void Dispose();
[DispId(3)]
int Add(int x, int y);
[DispId(4)]
bool Getxy([In] string strdh, ref float dx, ref float dy);
[DispId(5)]
void ServiceURL([In] string strurl);
}
[ComVisible(true)]
[Guid("EA2F140A-108F-47ae-BBD5-83EEE646CC0D")]
[ProgId("WebCom.MyClass")]
public class MyClass : IMyClass
{
public string m_strUrl = "";
public void Initialize()
{
//nothing todo
}
public void Dispose()
{
//nothing todo
}
public void ServiceURL(string strurl)
{
m_strUrl = strurl;
}
public bool Getxy(string strdh, ref float dx, ref float dy) //
{
bool br = false;
try
{
WSHttpBinding bind = new WSHttpBinding();
bind.Security.Mode = SecurityMode.None;
EndpointAddress address = new EndpointAddress(m_strUrl); //"http:///172.18.70.32/MobileService"
WebCom.MobileService.MobileServiceClient mClient = new WebCom.MobileService.MobileServiceClient(bind, address);
WebCom.MobileService.GPSData data = mClient.GetXY(strdh);
dx = (float)data.x;
dy = (float)data.y;
br = true;
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
br = false;
}
return br;
}
}
}
1. 生成一个classs lib后 没有service refernece项, 解决 先加入一个from1窗口后,才能add servcie refernece,
2. 然后是接口定义 传出的参数要这样写
ref float dx, ref float dy.
3.
.MobileServiceClient(bind, address); 这个webs对象使用带两个参数的构造函数,
第一个参数为 WSHttpBinding 类型,支持soap1.2的bind,
4. 之后是com组件的编译 这个网上有不少。遇到net f4.0时要加入csharp引用。
namespace MyLib
{
[ComVisible(true)]
[Guid("0BDD4AEC-A0C7-4949-BEE3-0F15ACF3FF5E")]
public interface IMyClass
{
[DispId(1)]
void Initialize();
[DispId(2)]
void Dispose();
[DispId(3)]
int Add(int x, int y);
[DispId(4)]
bool Getxy([In] string strdh, ref float dx, ref float dy);
[DispId(5)]
void ServiceURL([In] string strurl);
}
[ComVisible(true)]
[Guid("EA2F140A-108F-47ae-BBD5-83EEE646CC0D")]
[ProgId("WebCom.MyClass")]
public class MyClass : IMyClass
{
public string m_strUrl = "";
public void Initialize()
{
//nothing todo
}
public void Dispose()
{
//nothing todo
}
public void ServiceURL(string strurl)
{
m_strUrl = strurl;
}
public bool Getxy(string strdh, ref float dx, ref float dy) //
{
bool br = false;
try
{
WSHttpBinding bind = new WSHttpBinding();
bind.Security.Mode = SecurityMode.None;
EndpointAddress address = new EndpointAddress(m_strUrl); //"http:///172.18.70.32/MobileService"
WebCom.MobileService.MobileServiceClient mClient = new WebCom.MobileService.MobileServiceClient(bind, address);
WebCom.MobileService.GPSData data = mClient.GetXY(strdh);
dx = (float)data.x;
dy = (float)data.y;
br = true;
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
br = false;
}
return br;
}
}
}
相关文章推荐
- 图文并茂——使用xfire编写webservice,并通过C#调用
- 图文并茂——使用xfire编写webservice,并通过C#调用
- 图文并茂——使用xfire编写webservice,并通过C#调用
- 图文并茂——使用xfire编写webservice,并通过C#调用
- 图文并茂——使用xfire编写webservice,并通过C#调用
- 图文并茂——使用xfire编写webservice,并通过C#调用
- 使用xfire编写webservice,并通过C#调用
- Unity-Android通信:AndroidJava 使用Unity c#编写Android程序调用任何方法
- C#调用C++编写的COM DLL
- 使用Java客户端类调用c# WebService和xml rpc server
- 使用C#调用外部序或是执行DOS命令http://www.yaosansi.com/blog/article.asp?id=810
- (转)Delphi 调用C#编写的WebService 参数为Null解决方法 附中文乱码问题
- 使用C#编写COM组件在网页中调用ActiveXObject
- Silverlight实用窍门系列:22.Silverlight使用WebService调用C++,Delphi编写的DLL文件【实例源码下载】
- 使用C#创建webservice及三种调用方式
- Dephi调用C#编写的WebService的一些问题与解决
- C++调用gSoap编写的WEBSERVICE与C#.NET间接口自定义结构体不能重复使用
- 使用Java客户端类调用c# WebService和xml rpc server
- JavaScript学习笔记之JavaScript调用C#编写的COM组件
- 使用clr 调用C#编写的dll中的方法的全解释