WCF配置问题,很小的一个案例!
1、创建契约
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ServiceModel;
namespace ICalcService
{
[ServiceContract]
public interface ICalc
{
[OperationContract]
double Add(double x, double y);
}
}
2、创建服务
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ICalcService;
namespace CalcService
{
public class CalcServiceWCF : ICalc
{
public double Add(double x, double y)
{
return x + y;
}
}
}
3、寄宿宿主
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ServiceModel;
using CalcService;
namespace Hosting
{
class Program
{
static void Main(string[] args)
{
ServiceHost host = new ServiceHost(typeof(CalcServiceWCF),new Uri("http://127.0.0.1:12345/WCF"));
host.Open();
Console.WriteLine("服务开启");
Console.ReadLine();
}
}
}
4、使用VS2010的WCF服务编辑器生成的配置的app.net文件
宿主挂起后,运行是一片空白!
但是用程序开启服务可以,是不是配置文件哪里还需要设置,请大神们指教!在线等!
WCF ASP.NET C# WCF配置 --------------------编程问答-------------------- ---->但是用程序开启服务可以,是不是配置文件哪里还需要设置,请大神们指教!在线等
从你给出的图看,你的服务还不行,不是正常服务显示出来的界面.先在WCF服务端找原因吧,服务端都不正常,客户端什么可以访问呢 --------------------编程问答-------------------- 你的服务端不正常。应该把服务端里Web.config的
<service.serverModel>
。。。。。。。。。
。。。。。
</service.serverModel>
帖出来看,才看出原因在哪?一般要设置绑定、服务、行为
--------------------编程问答--------------------
这是一个用控制台应用程序寄宿的宿主,用的是app.config文件,就是上面WCF服务配置器自动生成的! --------------------编程问答-------------------- 基本上console 是不能作为宿主的,不如直接把wcf 挂到IIS上 --------------------编程问答-------------------- 其实你的WCF是一个HTTP服务,不需要这么麻烦,做这么多事情;
目前的IIS7以上 支持 NON-HTTP 协议(net.tcp)照着以前的思路去做,有点本末倒置了。 --------------------编程问答-------------------- 用WCF自承载的方式, 是不能用WCF网址查看其内容的.
所以你打开就是一片空白.
但是引用是可以的, 在添加引用时可以看到其描述. --------------------编程问答-------------------- to楼上一群水货:请不要误人子弟……
console完全可以作为宿主。
而且楼主的错误跟寄宿什么的完全无关,
to楼主:你打开的窗口已经告诉你太清楚了——你的wcf的配置没有开发http的元数据发布
声明http元数据的节点在app.config里面加上
就是你的错误报告给你看的那个节点 --------------------编程问答-------------------- 用程序(而不用配置文件)可以这样写(例如)
--------------------编程问答--------------------
Uri host = .....;
Type serviceType = ......;
var station = new ServiceHost(serviceType, host);
var behaviour = new ServiceMetadataBehavior();
behaviour.HttpGetEnabled = true;
behaviour.MetadataExporter.PolicyVersion = PolicyVersion.Policy15;
station.Description.Behaviors.Add(behaviour);
station.AddServiceEndpoint(serviceType, new BasicHttpBinding(), host);
station.Open();
ServiceHost host = new ServiceHost(typeof(CalcServiceWCF),new Uri("http://127.0.0.1:12345/WCF"));
不需要后面的Url参数
<?xml version="1.0"?>
<configuration>
<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior name="metadataBehavior">
<serviceMetadata httpGetEnabled="true" httpGetUrl="http://127.0.0.1:12345/calcWCF/metadata"/>
<serviceDebug includeExceptionDetailInFaults="true"/>
</behavior>
</serviceBehaviors>
</behaviors>
<services>
<service name="CalcService.CalcServiceWCF" behaviorConfiguration="metadataBehavior">
<endpoint address="http://127.0.0.1:12345/calcWCF" binding="basicHttpBinding" contract="ICalcService.ICalc" />
</service>
</services>
</system.serviceModel>
补充:.NET技术 , ASP.NET