积极答复者
找不到服务啊,大师。

问题
-
找不到服务啊,大师。
Contracts:
[ServiceContract(Name = "GatherService", Namespace = "http://www.yostec.com/")]
public interface IGather
{
[OperationContract]
int Add(string DANo, DateTime DATime, DateTime LogTime, string MeterNo, string MeterType, double Qty);
}
Services:
public class GatherService:IGather
{
public int Add(string DANo, DateTime DATime, DateTime LogTime, string MeterNo, string MeterType, double Qty)
{
return 1;
}
}
public class Common
{
public static int HostGatherService()
{
int flag=0;
using (ServiceHost host = new ServiceHost(typeof(GatherService)))
{
host.AddServiceEndpoint(typeof(IGather), new WSHttpBinding(), "http://127.0.0.1:9999/GatherService");
if (host.Description.Behaviors.Find<ServiceMetadataBehavior>() == null)
{
ServiceMetadataBehavior behavior = new ServiceMetadataBehavior();
behavior.HttpGetEnabled = true;
behavior.HttpGetUrl = new Uri("http://127.0.0.1:9999/GatherService/metadata");
host.Description.Behaviors.Add(behavior);
}
host.Opened += delegate
{
flag = 1;
};
host.Open();
}
return flag;
}
}
Winform下服务启动:
private void MainForm_Load(object sender, EventArgs e)
{
if (Common.HostGatherService() == 1)
{
this.Text = "服务已启动";
}
}
问题一:
大师,IE浏览器下“http://127.0.0.1:9999/GatherService/metadata”找不到服务元数据,但从断点执行上看服务启动了。 怎么回事呢?问题出在哪里呢? 大师。。。
问题二:
ServiceHost host = new ServiceHost(typeof(GatherService)) 和“.scv”文件的用法有什么不同呢? 在“Winform”和“WPF”中使用“WCF”好像没有“。scv”文件可以用???
一个是“代码控制”服务配置,一个“文件配置”服务是吗???
如果,服务支持“TCP”和“Http”之间的切换,是不是就应该使用“ServiceHost”???问题三:
在宿主程序中加一个“app.config”,服务也不会自己去读取配置信息吧。 必须在宿主程序上写代码读取,是吗???
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior name="metadataBehavior">
<serviceMetadata httpGetEnabled="true" httpGetUrl="http://127.0.0.1:9999/GatherService/metadata" />
</behavior>
</serviceBehaviors>
</behaviors>
<services>
<service behaviorConfiguration="metadataBehavior" name="Services.GatherService">
<endpoint address="http://127.0.0.1:9999/GatherService" binding="wsHttpBinding" contract="Contracts.IGather" name="GatherService"/>
</service>
</services>
</system.serviceModel>
</configuration>
Science and technology is my lover.
- 已编辑 starrycheng 2012年11月6日 2:41
答案
-
把using 去掉,就可以在IE中看到源数据了
参照:http://msdn.microsoft.com/zh-cn/library/aa738489.aspx
http://blog.csdn.net/zx13525079024
- 已标记为答案 Haixia_XieModerator 2012年11月12日 9:16
-
身份认证的方法很多,最简单的就是你给每一个调用者一个用户名和密码,如果不匹配,就不允许进行调用。
也可以使用其他办法,参照
http://www.cnblogs.com/Moosdau/archive/2011/04/20/2022710.html
http://blog.csdn.net/zx13525079024
- 已标记为答案 Haixia_XieModerator 2012年11月12日 9:16
全部回复
-
把using 去掉,就可以在IE中看到源数据了
参照:http://msdn.microsoft.com/zh-cn/library/aa738489.aspx
http://blog.csdn.net/zx13525079024
- 已标记为答案 Haixia_XieModerator 2012年11月12日 9:16
-
大师,问题解决了。
using释放资源了,把“using”去除就可以了。
大师可不可以再问一个问题:
WFC中怎样进行身份认证???
“服务”只能被“校园网”中指定“应用程序”调用,其它“应用程序”是不能调用的。怎样进行认证呢???
在“调用方法”中加一个“参数”叫做密码吗??? 在这个方法中进行判断吗???
Science and technology is my lover.
- 已编辑 starrycheng 2012年11月6日 6:34
-
身份认证的方法很多,最简单的就是你给每一个调用者一个用户名和密码,如果不匹配,就不允许进行调用。
也可以使用其他办法,参照
http://www.cnblogs.com/Moosdau/archive/2011/04/20/2022710.html
http://blog.csdn.net/zx13525079024
- 已标记为答案 Haixia_XieModerator 2012年11月12日 9:16