WCF错误。无法创建和理解端点。什么是主机端点 [英] WCF Error.Could not create and understand endpoint.What is host endpoints

查看:59
本文介绍了WCF错误。无法创建和理解端点。什么是主机端点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,



我最近开始学习WCF,我对端点感到很困惑。

究竟什么是主机端点。



我创建了一个简单的主机和客户端服务,然后在Windows Form中托管。但是我无法调用服务。 :(

---------------------------------------- --------------------------------------------

hostService代码 -

Hi All,

I have recently started to study WCF and I am really confused in Endpoints.
What are Host endpoints exactly.

I have created a simple host and client service and hosted then in Windows Form.But i am unable to invoke services. :(
------------------------------------------------------------------------------------
Code of hostService-

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

namespace WcfService2
{
    // NOTE: You can use the "Rename" command on the "Refactor" menu to change the interface name "IService1" in both code and config file together.
    [ServiceContract]
    public interface IService1
    {

        [OperationContract(IsOneWay=true)]
        void SendCreditLimitRequest(string id);


    }

}






and

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

namespace WcfService2
{
    // NOTE: You can use the "Rename" command on the "Refactor" menu to change the class name "Service1" in code, svc and config file together.
    public class Service1 : IService1
    {

        public void  SendCreditLimitRequest(string id)
        {
            double value;

            if (id == "1")
                value = 10;
            else if (id == "2")
                value = 20;
            else
                value = 0;


        }
    }
}



------------ --------

它的Web配置是 -


--------------------
Its Web Config is--

<?xml version="1.0"?>
<configuration>

  <system.web>
    <compilation debug="true" targetFramework="4.0" />
  </system.web>
  <system.serviceModel>
    <services>
      <service name="Service1">
        <clear />
        <host>
          <baseAddresses>
            <add  baseAddress ="http://localhhost/host"/>
          </baseAddresses>
        </host>
        <endpoint address="net.msmq://localhost/private/requestqueue"

          binding="netMsmqBinding" bindingConfiguration="" name="ServiceEndpoint"

          contract="WcfService2.IService1" />
      </service>
    </services>
    <behaviors>
      <serviceBehaviors>
        <behavior>
          <!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment -->
          <serviceMetadata httpGetEnabled="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>
    <serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
  </system.serviceModel>
 <system.webServer>
    <modules runAllManagedModulesForAllRequests="true"/>
  </system.webServer>
  
</configuration>



- -------------------------------------------------- ------------------------------

我的窗口主机代码如下:


----------------------------------------------------------------------------------
Code of my Window host is as :

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.ServiceModel;
using System.ServiceProcess;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace host
{
    public partial class Form1 : Form
    {
        ServiceHost host;
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            host = new ServiceHost(typeof(WcfService2.Service1Client));
            host.Open();
            MessageBox.Show("Service Started!");

        }

        private void button2_Click(object sender, EventArgs e)
        {
            host.Close();
        }
    }
}



-------------------- -------------------------------------------------- ----------

我面临的例外是---


--------------------------------------------------------------------------------
and exception i am facing is---

System.InvalidOperationException was unhandled
  Message=Service 'host.WcfService2.Service1Client' has zero application (non-infrastructure) endpoints. This might be because no configuration file was found for your application, or because no service element matching the service name could be found in the configuration file, or because no endpoints were defined in the service element.
  Source=System.ServiceModel
  StackTrace:
       at System.ServiceModel.Description.DispatcherBuilder.EnsureThereAreApplicationEndpoints(ServiceDescription description)
       at System.ServiceModel.Description.DispatcherBuilder.InitializeServiceHost(ServiceDescription description, ServiceHostBase serviceHost)
       at System.ServiceModel.ServiceHostBase.InitializeRuntime()
       at System.ServiceModel.ServiceHostBase.OnBeginOpen()
       at System.ServiceModel.ServiceHostBase.OnOpen(TimeSpan timeout)
       at System.ServiceModel.Channels.CommunicationObject.Open(TimeSpan timeout)
       at System.ServiceModel.Channels.CommunicationObject.Open()
       at host.Form1.button1_Click(Object sender, EventArgs e) in C:\WcfPrograms\host\host\Form1.cs:line 25
       at System.Windows.Forms.Control.OnClick(EventArgs e)
       at System.Windows.Forms.Button.OnClick(EventArgs e)
       at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
       at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
       at System.Windows.Forms.Control.WndProc(Message& m)
       at System.Windows.Forms.ButtonBase.WndProc(Message& m)
       at System.Windows.Forms.Button.WndProc(Message& m)
       at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
       at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
       at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
       at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
       at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(IntPtr dwComponentID, Int32 reason, Int32 pvLoopData)
       at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
       at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
       at System.Windows.Forms.Application.Run(Form mainForm)
       at host.Program.Main() in C:\WcfPrograms\host\host\Program.cs:line 18
       at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
       at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
       at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
       at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean ignoreSyncCtx)
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
       at System.Threading.ThreadHelper.ThreadStart()
  InnerException: 



------------------- ---

请帮助!!

推荐答案

我能给你的最佳答案是一个链接有关该主题的MSDN文档:

http://msdn.microsoft.com /en-us/library/ms733107.aspx [ ^ ]

它详细解释了您在这篇文章中的所有查询。
The best answer I can give you is a link to the MSDN documentation on the topic:
http://msdn.microsoft.com/en-us/library/ms733107.aspx[^]
It explains in detail all of the queries you have in this post.


检查双重检查您的服务名称并确保您正在使用您的命名空间以及界面以外的其他内容

Check double check your service name and make sure you are using your namespace along with interface nothing other than that
<services>
     <service behaviorConfiguration="maxBehavior"
              name="SimplesServices.SimplesServices">

       <endpoint address="SimplesServices"
          binding="basicHttpBinding"
                 contract="SimplesServices.ISimplesServices"/>
       <host>
         <baseAddresses>
           <add baseAddress="http://localhost:8080"/>
         </baseAddresses>
       </host>
     </service>



专注于上述部分


Concentrate on the above section


这篇关于WCF错误。无法创建和理解端点。什么是主机端点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆