首页新闻找找看学习计划

今天用VS2012建立的WCF碰到的问题

0
[待解决问题]

求高手指导,本人小白。

报错

服务“Services.HelloService”有零个应用程序(非基础结构)终结点。这可能是因为未找到应用程序的配置文件,或者在配置文件中未找到与服务名称匹配的服务元素,或者服务元素中未定义终结点。

运行代码

    class Program
    {
        static void Main(string[] args)
        {
            //ServiceHost host = new ServiceHost(typeof(HelloWorld), new Uri("http://localhost:8080/HelloService"));
            //host.AddServiceEndpoint(typeof(IHello),new BasicHttpBinding(),"SVC");
            //if (host.Description.Behaviors.Find<ServiceMetadataBehavior>() == null)
            //{
            //    ServiceMetadataBehavior behavior = new ServiceMetadataBehavior();
            //    behavior.HttpGetEnabled = true;

            //    behavior.HttpGetUrl = new Uri("http://localhost:8080/HelloService");

            //    host.Description.Behaviors.Add(behavior);


            //}

            //host.Open();
            //Console.WriteLine("Start Your Service.");
            //Console.ReadKey();
            //host.Close();

            ServiceHost host1 = new ServiceHost(typeof(HelloService));
            host1.Open();
            Console.WriteLine("Hello service start");
            Console.ReadLine();
            host1.Close();
        }
    }

 

这是Contract类

using System;
using System.Collections.Generic;
using System.Linq;
using System.ServiceModel;
using System.Text;
using System.Threading.Tasks;

namespace Contracts
{
    [ServiceContract]
    public interface IHello
    {
        [OperationContract]
        void Hello();
    }
}

这是Service代码

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

namespace Services
{
    public class HelloService : IHello
    {
        public void Hello()
        {
             Console.WriteLine("Hello service hello");
        }
    }
}

这是config文件

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
    <system.serviceModel>
        <behaviors>
            <serviceBehaviors>
                <behavior name="">
                    <serviceMetadata httpGetEnabled="true" httpsGetEnabled="true" />
                    <serviceDebug includeExceptionDetailInFaults="false" />
                </behavior>
            </serviceBehaviors>
        </behaviors>
        <services>
            <service name="Services.HelloService">
                <endpoint address="http://localhost:8080/HelloService" binding="basicHttpBinding" contract="Contracts.IHello">
                    <identity>
                        <dns value="localhost" />
                    </identity>
                </endpoint>
                <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
                <host>
                    <baseAddresses>
                        <add baseAddress="http://localhost:8080/HelloService" />
                    </baseAddresses>
                </host>
            </service>
        </services>
    </system.serviceModel>
</configuration>
WCF
瓜&瓜的主页 瓜&瓜 | 菜鸟二级 | 园豆:204
提问于:2012-12-11 22:55
< >
分享
所有回答(1)
0

    <endpoint address="" binding="basicHttpBinding" contract="Artech.WCFService.Contract.IGeneralCalculator">
                
</endpoint>

明显你没有配置contract 属性

chenping2008 | 园豆:9836 (大侠五级) | 2012-12-12 09:16

配置了啊,

contract="Contracts.IHello"
支持(0) 反对(0) 瓜&瓜 | 园豆:204 (菜鸟二级) | 2012-12-12 21:51

@瓜&瓜: 

  <service name="Services.HelloService">
                <endpoint address="HelloService" binding="basicHttpBinding" contract="Contracts.IHello">
                    <identity>
                        <dns value="localhost" />
                    </identity>
                </endpoint>
                <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
                <host>
                    <baseAddresses>
                        <add baseAddress="http://localhost:8080/" />
                    </baseAddresses>
                </host>
            </service>
支持(0) 反对(0) chenping2008 | 园豆:9836 (大侠五级) | 2012-12-12 21:58

ServiceHost host1 = new ServiceHost(typeof(HelloService), new Uri("http://localhost:8080/HelloService"));

这样就可以了,不是可以用相对的uri吗?

支持(0) 反对(0) 瓜&瓜 | 园豆:204 (菜鸟二级) | 2012-12-12 22:01

@瓜&瓜: 

<baseAddresses>
<add baseAddress="http://192.168.17.169:8080/MailSys"/>
</baseAddresses>
<endpoint address="" binding ="basicHttpBinding" contract="MailSys.IMailSys"></endpoint>
这个是配置在
endpoint 前面的,你也试试
支持(0) 反对(0) chenping2008 | 园豆:9836 (大侠五级) | 2012-12-13 09:52
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册