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文件
宿主挂起后,运行是一片空白!
但是用程序开启服务可以,是不是配置文件哪里还需要设置,请大神们指教!在线等!
WCFASP.NETC#WCF配置
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文件
宿主挂起后,运行是一片空白!
但是用程序开启服务可以,是不是配置文件哪里还需要设置,请大神们指教!在线等!
WCFASP.NETC#WCF配置
解决方案 »
- 求dhtmlxtree 上移下移(moveItem)代码思路
- VS2005中treeview控件和数据库连接的问题
- 一个超奇怪的datalist问题
- 菜鸟刚学用c#做asp.net网页,我想算出数据库中符合条件的记录的id值的最大值,然后判断如果这个值小与10000则加1,怎么做呢?我写的怎么
- 紧急求助一个超麻烦问题,两个asp.net网站部署到一个虚拟目录下
- 在使用Datagrid 绑定数据时,得写法问题!请大家帮助!
- csdn这论坛登陆怎么做?点击登陆后在一个新页面打开
- Session.Abandon问题?
- 请问发布带有水晶报表的应用程序时是怎么发布的是?
- IndexOf返回结果时是从0开始还是从1开始?
- 时间问题,进来看下!
- 正则达人请进,高分求一个正则!!!!
<service.serverModel>
。。
</service.serverModel>帖出来看,才看出原因在哪?一般要设置绑定、服务、行为
这是一个用控制台应用程序寄宿的宿主,用的是app.config文件,就是上面WCF服务配置器自动生成的!
所以你打开就是一片空白.
但是引用是可以的, 在添加引用时可以看到其描述.
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>