IIS8 部署 WCF service

首先创建wcf service服务
在这里插入图片描述
新建一个服务,命名为IService4

using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.Text;

namespace WcfService1
{
    // NOTE: You can use the "Rename" command on the "Refactor" menu to change the interface name "IService4" in both code and config file together.
    [ServiceContract(Name = "te", Namespace = "te")]
    interface IService4
    {
        [OperationContract]
        string DoWork();
        [OperationContract]
        string GetData(int value);

        [OperationContract]
        CompositeType GetDataUsingDataContract(CompositeType composite);
    }
}

service4.svc代码并设置为启动项

using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.Text;

namespace WcfService1
{
    // NOTE: You can use the "Rename" command on the "Refactor" menu to change the class name "Service4" in code, svc and config file together.
    // NOTE: In order to launch WCF Test Client for testing this service, please select Service4.svc or Service4.svc.cs at the Solution Explorer and start debugging.
    public class Service4 : IService4
    {
        public string DoWork()
        {
            return "test";
        }
        public string GetData(int value)
        {
            return string.Format("You entered: {0}", value);
        }

        public CompositeType GetDataUsingDataContract(CompositeType composite)
        {
            if (composite == null)
            {
                throw new ArgumentNullException("composite");
            }
            if (composite.BoolValue)
            {
                composite.StringValue += "Suffix";
            }
            return composite;
        }
    }
}

右键发布即可,发布生成的config文件在system.serviceModule 里添加

<behaviors>
      <serviceBehaviors>
        <behavior name="CalculatorBehavior">
          <!-- To avoid disclosing metadata information, set the values below to false before deployment -->
          <serviceMetadata httpGetEnabled="true" httpsGetEnabled="true"/>
          <!-- To receive exception details in faults for debugging purposes, set the value below to true.  Set to false before deployment to avoid disclosing exception information -->
          <serviceDebug includeExceptionDetailInFaults="false"/>
        </behavior>
      </serviceBehaviors>
    </behaviors>
	<services>
		<service behaviorConfiguration="CalculatorBehavior" name="WcfService1.Service4">
		<endpoint address="" binding="basicHttpBinding"
           bindingConfiguration="" contract="WcfService1.IService4" />
		</service>
		<service behaviorConfiguration="CalculatorBehavior" name="WcfService1.Service2">
		<endpoint address="" binding="basicHttpBinding"
           bindingConfiguration="" contract="WcfService1.IService2" />
		</service>
	</services>

在这里插入图片描述
需要注意的是要修改svc里面的内容
比如Service2.svc内容是

<%@ ServiceHost Language="C#" Debug="true" Service="WcfService1.Service2" CodeBehind="Service2.svc.cs" %>

接着就可以发布服务了
在这里插入图片描述
依次填写就行
当时当我们访问http://127.0.0.1:8080/Service4.svc 假如报错如下
由于扩展配置问题而无法提供您请求的页面。如果该页面是脚本,请添加处理程序。如果应下载文件,请添加 MIME 映射
解决方案:CD到如下目录

C:\Windows\Microsoft.NET\Framework\v3.0\Windows Communication Foundation

运行ServiceModelReg.exe -i

假如报错:未能从程序集“System.ServiceModel, Version=3.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089”中加载类型“System.ServiceModel.Activation.HttpHandler”。

解决方案:把这些装上
在这里插入图片描述

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值