您的位置:首页 > 编程语言 > C#

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;

}

}

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: