求vb.net写的win frm 作宿主的wcf代码。

ruhong1 2017-06-15 07:49:25
通过iis使用wcf,我试成了,现在想用win frm 作为wcf的宿主,
找了半天,只有c#的代码,虽然转换成vb.net以后,好象没啥问题了,但是就是得不出结果。
我怀疑是不是转换的不对。而且很多属性方法不是很明白他的意思。
谁有vb.net写的win frm 作宿主的wcf代码,给我来一点参考参考。
Private Host As ServiceHost = Nothing
If Host Is Nothing Then
Host = New ServiceHost(GetType(Wcfservice.Service1))
'绑定
Dim httpBinding As System.ServiceModel.Channels.Binding = New BasicHttpBinding()
'终结点
Host.AddServiceEndpoint(GetType(Wcfservice.Service1), httpBinding, "http://localhost:8002/")
Dim behavior As ServiceMetadataBehavior = New ServiceMetadataBehavior()
behavior.HttpGetEnabled = True

'元数据地址
behavior.HttpGetUrl = New Uri("http://localhost:8002/Service1")
Host.Description.Behaviors.Add(behavior)
'启动
Host.Open()
这是关系的代码,我写完了以后,启动他,按那个例子的说明,在浏览器中输入http://localhost:8002/Service1
就应该看到相应的信息了,可是我什么都没有看到。
相应的Wcfservice.Service1已经做了。
...全文
372 12 打赏 收藏 转发到动态 举报
写回复
用AI写文章
12 条回复
切换为时间正序
请发表友善的回复…
发表回复
arhaidai 2018-01-01
  • 打赏
  • 举报
回复
楼主,我最近也在搞一个wcf的项目,但很多不懂,按你的代码这样启动服务怎么会报错,你确定你的能正常运行?
ruhong1 2017-06-17
  • 打赏
  • 举报
回复
引用 10 楼 xdashewan 的回复:
[quote=引用 8 楼 ruhong1 的回复:] 可能还是对System.ServiceModel 这个类不太理解,有没有什么帮助给一个。
ServiceModel只是个namespace而已,不是类啊[/quote]
引用 10 楼 xdashewan 的回复:
[quote=引用 8 楼 ruhong1 的回复:] 可能还是对System.ServiceModel 这个类不太理解,有没有什么帮助给一个。
ServiceModel只是个namespace而已,不是类啊[/quote] ServiceHost 之类的不是从这里面引用的吗。
xdashewan 2017-06-16
  • 打赏
  • 举报
回复
引用 8 楼 ruhong1 的回复:
可能还是对System.ServiceModel 这个类不太理解,有没有什么帮助给一个。
ServiceModel只是个namespace而已,不是类啊
ruhong1 2017-06-16
  • 打赏
  • 举报
回复
引用 6 楼 sp1234 的回复:
在 .net 下不同语言只是一种体验差别问题,真正的技术在于 .net framework 的共同机制的理解而不是纠结于某个编程语言。一个程序员搞不定 c# 只能搞定 vb.net 这不应该。
辛苦了。主要是年龄有点偏大,没有太多时间学习啊。
ruhong1 2017-06-16
  • 打赏
  • 举报
回复
引用 7 楼 xdashewan 的回复:
[quote=引用 4 楼 ruhong1 的回复:] 基本上没改,都是新建的时候系统给的。 就是想了解一下流程,不需要实现太复杂的功能。 所有的逻辑功能的实现全写在一个文件中吗?我现在还不是很清楚这个概念,
不一定要写一个文件中,首先接口就可以定义多个,其次实现服务的类只要继承不同的接口一样可以写成多个[/quote] 可能还是对System.ServiceModel 这个类不太理解,有没有什么帮助给一个。
xdashewan 2017-06-16
  • 打赏
  • 举报
回复
引用 4 楼 ruhong1 的回复:
基本上没改,都是新建的时候系统给的。 就是想了解一下流程,不需要实现太复杂的功能。 所有的逻辑功能的实现全写在一个文件中吗?我现在还不是很清楚这个概念,
不一定要写一个文件中,首先接口就可以定义多个,其次实现服务的类只要继承不同的接口一样可以写成多个
  • 打赏
  • 举报
回复
在 .net 下不同语言只是一种体验差别问题,真正的技术在于 .net framework 的共同机制的理解而不是纠结于某个编程语言。一个程序员搞不定 c# 只能搞定 vb.net 这不应该。
  • 打赏
  • 举报
回复
你可以创建一个 c# 语言的类库(把你的GetType(Wcfservice.Service1) 等等2、3个参数传入),然后把你认为没有问题的 c# 代码实现,再在你的 vb.net 的工程中引用这个 c# 的类库。
xdashewan 2017-06-15
  • 打赏
  • 举报
回复
引用 2 楼 ruhong1 的回复:
他们之间的关系也很模糊。我就想作一个服务端,然后发布很多供引用调用的接口,如何做。
看我给你的url的契约和服务实现部分
ruhong1 2017-06-15
  • 打赏
  • 举报
回复
Private Host As ServiceHost = Nothing Private Sub button1_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button1.Click If Host Is Nothing Then Host = New ServiceHost(GetType(A.Service1)) '绑定 Dim httpBinding As System.ServiceModel.Channels.Binding = New BasicHttpBinding() '终结点 Host.AddServiceEndpoint(GetType(A.IService1), httpBinding, "http://localhost:8002/") Dim behavior As ServiceMetadataBehavior = New ServiceMetadataBehavior() behavior.HttpGetEnabled = True '元数据地址 behavior.HttpGetUrl = New Uri("http://localhost:8002/Service1") Host.Description.Behaviors.Add(behavior) '启动 Host.Open() End If End Sub 已经试成功了,谢谢各位。现在有新的问题了, 就是这个服务如果要同时加载很多接口,应该怎么做, 上面的代码是试成功了,但是我不明白他的具体含义啊。 他们之间的关系也很模糊。我就想作一个服务端,然后发布很多供引用调用的接口,如何做。
xdashewan 2017-06-15
  • 打赏
  • 举报
回复
看下配置文件对不对,你可以参考http://blog.csdn.net/suneqing/article/details/40660227
ruhong1 2017-06-15
  • 打赏
  • 举报
回复
引用 3 楼 xdashewan 的回复:
[quote=引用 2 楼 ruhong1 的回复:] 他们之间的关系也很模糊。我就想作一个服务端,然后发布很多供引用调用的接口,如何做。
看我给你的url的契约和服务实现部分[/quote] Public Class Service1 Implements IService1 Public Function GetData(ByVal value As Integer) As String Implements IService1.GetData Return String.Format("You entered: {0}", value) End Function Public Function GetDataUsingDataContract(ByVal composite As CompositeType) As CompositeType Implements IService1.GetDataUsingDataContract If composite Is Nothing Then Throw New ArgumentNullException("composite") End If If composite.BoolValue Then composite.StringValue &= "Suffix" End If Return composite End Function End Class <ServiceContract()> Public Interface IService1 <OperationContract()> Function GetData(ByVal value As Integer) As String <OperationContract()> Function GetDataUsingDataContract(ByVal composite As CompositeType) As CompositeType ' TODO: 在此添加您的服务操作 End Interface ' 使用下面示例中说明的数据协定将复合类型添加到服务操作 <DataContract()> Public Class CompositeType <DataMember()> Public Property BoolValue() As Boolean <DataMember()> Public Property StringValue() As String End Class 基本上没改,都是新建的时候系统给的。 就是想了解一下流程,不需要实现太复杂的功能。 所有的逻辑功能的实现全写在一个文件中吗?我现在还不是很清楚这个概念,

16,554

社区成员

发帖
与我相关
我的任务
社区描述
VB技术相关讨论,主要为经典vb,即VB6.0
社区管理员
  • VB.NET
  • 水哥阿乐
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧