WCF的问题。。。有没有人遇到过?

海会圣贤 2011-01-07 09:17:24
我新建一个WCF服务库WcfServiceLibrary1,

我把接口改成我要用的ILogContract,这个类在Prj.Model项目里面。

当使用该项目里面默认的Service1的类时,可以正确运行。

就是:
部分主要配置文件如下:

<service name="WcfServiceLibrary1.Service1" behaviorConfiguration="LogHanderBehavior">
<host>
<baseAddresses>
<add baseAddress = "http://localhost:8731/Design_Time_Addresses/WcfServiceLibrary1/Service1/" />
</baseAddresses>
</host>
<!-- Service Endpoints -->
<!-- 除非完全限定,否则地址将与上面提供的基址相关 -->
<endpoint address ="" binding="wsHttpBinding" contract="Prj.WCF.ILogContract">


但当我把使用的Service类指向Prj.BLL里面的LogHelper类时(这个类在Prj.BLL项目里面),就报:
客户端无法检索服务元数据。请确保该服务正在运行并且正在公开元数据。
的错误。


部分主要配置文件如下:

<service name="Prj.BLL.LogHelper" behaviorConfiguration="LogHanderBehavior">
<host>
<baseAddresses>
<add baseAddress = "http://localhost:8731/Design_Time_Addresses/WcfServiceLibrary1/Service1/" />
</baseAddresses>
</host>
<!-- Service Endpoints -->
<!-- 除非完全限定,否则地址将与上面提供的基址相关 -->
<endpoint address ="" binding="wsHttpBinding" contract="Prj.WCF.ILogContract">


但我如果用Service1继承LogHelper类,配置文件使用最上面的那个,就可以正确运行。

大家知不知道这是神马问题?
...全文
201 22 打赏 收藏 转发到动态 举报
写回复
用AI写文章
22 条回复
切换为时间正序
请发表友善的回复…
发表回复
saisky 2011-01-12
  • 打赏
  • 举报
回复
你的bll没有实现接口吧?或是你的契约没有完全实现。
而且你的宿主我没看懂要做什么?
贴的问题也没看太明白,你最好能把各部分的代码贴详细点。
我看着像是你的bll没有实现接口。
海会圣贤 2011-01-12
  • 打赏
  • 举报
回复
那位GG能不能看清我的问题啊。
机器人 2011-01-11
  • 打赏
  • 举报
回复
linyaocai 2011-01-11
  • 打赏
  • 举报
回复

不懂。。
机器人 2011-01-11
  • 打赏
  • 举报
回复
你工程什么结构,先弄清楚哪个工程发布的WCF服务。才能查出问题。。。
机器人 2011-01-11
  • 打赏
  • 举报
回复
就是ServiceLib才需要宿主啊。。。要么console,要么winform,要么windows service,要么IIS。
你一个干的Library怎么打开服务端端口?
海会圣贤 2011-01-11
  • 打赏
  • 举报
回复
[Quote=引用 15 楼 fangxinggood 的回复:]
Host里的代码改了吗?

ServiceHost host = new ServiceHost(typeof(Prj.BLL.LogHelper));
[/Quote]

是建的服务库哦,哥哥。
机器人 2011-01-11
  • 打赏
  • 举报
回复
Host里的代码改了吗?

ServiceHost host = new ServiceHost(typeof(Prj.BLL.LogHelper));
海会圣贤 2011-01-11
  • 打赏
  • 举报
回复
[Quote=引用 12 楼 jiangshun 的回复:]
在IE里面打开看看
http://localhost:8731/Design_Time_Addresses/WcfServiceLibrary1/Service1

确定下宿主程序运行没
[/Quote]

运行了。
机器人 2011-01-10
  • 打赏
  • 举报
回复
[Quote=引用 10 楼 zhang116868 的回复:]
引用 9 楼 zhudachuncomeon 的回复:
客户端调用的时候你要注意,你的代理类要生成 元数据,可以手动使用微软提供的工具生成元数据


如何用微软提供的工具生成元数据,兄台能不能详细说下?
[/Quote]

客户端重新生成下Proxy,客户端的Services Reference删掉以前的,重新添加一下。
url里输入http://localhost:8731/Design_Time_Addresses/WcfServiceLibrary1/Service1
jiangshun 2011-01-10
  • 打赏
  • 举报
回复
在IE里面打开看看
http://localhost:8731/Design_Time_Addresses/WcfServiceLibrary1/Service1

确定下宿主程序运行没
海会圣贤 2011-01-10
  • 打赏
  • 举报
回复
海会圣贤 2011-01-07
  • 打赏
  • 举报
回复
[Quote=引用 9 楼 zhudachuncomeon 的回复:]
客户端调用的时候你要注意,你的代理类要生成 元数据,可以手动使用微软提供的工具生成元数据
[/Quote]

如何用微软提供的工具生成元数据,兄台能不能详细说下?
zhudachuncomeon 2011-01-07
  • 打赏
  • 举报
回复
客户端调用的时候你要注意,你的代理类要生成 元数据,可以手动使用微软提供的工具生成元数据
海会圣贤 2011-01-07
  • 打赏
  • 举报
回复
[Quote=引用 5 楼 bossma 的回复:]
是不是没有声明:
[OperationContract]
[/Quote]

有申明的。
zhudachuncomeon 2011-01-07
  • 打赏
  • 举报
回复
这个是宿主:
public static void StartService()
{
ServiceHost aServiceHost = null;
Configuration conf = ConfigurationManager.OpenExeConfiguration(Assembly.GetEntryAssembly().Location);
ServiceModelSectionGroup svcmod = (ServiceModelSectionGroup)conf.GetSectionGroup("system.serviceModel");

foreach (ServiceElement el in svcmod.Services.Services)
{

//Type svcType = Type.GetType(el.Name + "," + "ChinaQueue.Restaurant.WCFService");

Type svcType = Type.GetType(el.Name + "," + el.Name.Split('.')[0] + "." + el.Name.Split('.')[1]+"."+el.Name.Split('.')[2]);

if (svcType == null)

throw new Exception("Invalid Service Type " + el.Name + " in configuration file.");

aServiceHost = new ServiceHost(svcType);

aServiceHost.Opened += delegate
{

Console.WriteLine(el.Name + "服务已经启动了");

};

aServiceHost.Open();

}

Console.Read();
}
这个是配置文件:
<system.serviceModel>
<services>
<service name="Rinpak.Portal.WCFService.AgentSvc" behaviorConfiguration="HostBehavior">
<endpoint address="" binding="basicHttpBinding" contract="Rinpak.Portal.IContract.IContractAgentSvc">
</endpoint>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
<host>
<baseAddresses>
<add baseAddress="http://192.168.0.47:2000/Rinpak/Agent/" />
</baseAddresses>
</host>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="HostBehavior">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="false" />
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>

我都是分成不同的工厂,哥哥
zhudachuncomeon 2011-01-07
  • 打赏
  • 举报
回复
可以的呀
萤火架构 2011-01-07
  • 打赏
  • 举报
回复
是不是没有声明:
[OperationContract]
海会圣贤 2011-01-07
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 zhudachuncomeon 的回复:]
这个是契约
public interface IContractAgentSvc
{
//-------------------用户

[OperationContract]
[FaultContract(typeof(ExDetail))]
List<UserEntity> GetUserList();

[OperationContract]
……
[/Quote]

首先谢谢你,不过这些东东我都知道写了。

主要是为什么不能使用其它项目里bll的类作为service类呢?
zhudachuncomeon 2011-01-07
  • 打赏
  • 举报
回复
这个是契约
public interface IContractAgentSvc
{
//-------------------用户

[OperationContract]
[FaultContract(typeof(ExDetail))]
List<UserEntity> GetUserList();

[OperationContract]
[FaultContract(typeof(ExDetail))]
List<UserEntity> GetUserListByRoleId(string roleId);


}
加载更多回复(2)

62,041

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

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