Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/wcf/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/delphi/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
WCF托管、配置和连接地址/端口问题(包括Delphi 7客户端) 我有一个WCF服务(MyWCFService)和基址_Wcf_Delphi_Wsdl_Wcf Binding_Wcf Client - Fatal编程技术网

WCF托管、配置和连接地址/端口问题(包括Delphi 7客户端) 我有一个WCF服务(MyWCFService)和基址

WCF托管、配置和连接地址/端口问题(包括Delphi 7客户端) 我有一个WCF服务(MyWCFService)和基址,wcf,delphi,wsdl,wcf-binding,wcf-client,Wcf,Delphi,Wsdl,Wcf Binding,Wcf Client,以及app.config中的以下内容 <system.serviceModel> <diagnostics performanceCounters="Default"> <messageLogging logEntireMessage="true" logMalformedMessages="true" logMessagesAtServiceLevel="true" logMessagesAtTransportLevel="

以及app.config中的以下内容

  <system.serviceModel>
    <diagnostics performanceCounters="Default">
      <messageLogging logEntireMessage="true" logMalformedMessages="true"
        logMessagesAtServiceLevel="true" logMessagesAtTransportLevel="true" />
    </diagnostics>
    <extensions>
      <behaviorExtensions>
        <add name="wsdlExtensions" type="WCFExtras.Wsdl.WsdlExtensionsConfig, WCFExtras, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" />
      </behaviorExtensions>
    </extensions>
    <services>
      <service name="MyWCFService.Service1" behaviorConfiguration="MyWCFService.Service1Behavior">
        <host>
          <baseAddresses>
            <add baseAddress="http://localhost:8732/Design_Time_Addresses/MyWCFService/Service1/"   />
          </baseAddresses>
        </host>
        <!-- Service Endpoints -->
        <!-- Unless fully qualified, address is relative to base address supplied above -->
        <!--<endpoint address ="" binding="wsHttpBinding" contract="MyWCFService.IService1">
          --><!-- 
              Upon deployment, the following identity element should be removed or replaced to reflect the 
              identity under which the deployed service runs.  If removed, WCF will infer an appropriate identity 
              automatically.
          --><!--
          <identity>
            <dns value="localhost"/>
          </identity>
        </endpoint>-->
        <!-- Metadata Endpoints -->
        <!-- The Metadata Exchange endpoint is used by the service to describe itself to clients. --> 
        <!-- This endpoint does not use a secure binding and should be secured or removed before deployment -->
        <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
        <endpoint address="" binding="basicHttpBinding" behaviorConfiguration="singleFileEndpointBehavior" contract="MyWCFService.IService1"/>
      </service>
    </services>
    <behaviors>
      <endpointBehaviors>
        <behavior name="singleFileEndpointBehavior">
          <wsdlExtensions singleFile="True" />
        </behavior>
      </endpointBehaviors>
      <serviceBehaviors>
        <behavior name="MyWCFService.Service1Behavior">
          <!-- 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="True" />
        </behavior>
      </serviceBehaviors>
    </behaviors>
  </system.serviceModel>
以及WinForm上的以下代码

namespace MyWCFService
{
    public partial class Form1 : Form
    {
        bool serviceStarted = false;
        ServiceHost myServiceHost = null;
        Uri baseAddress = new Uri("net.tcp://localhost:2202/Service1");
        NetTcpBinding binding = new NetTcpBinding();
        public Form1() { InitializeComponent(); }

        private void StartService(object sender, EventArgs e)
        {
            if (!serviceStarted)
            {
                myServiceHost = new ServiceHost(typeof(Service1), baseAddress);
                myServiceHost.AddServiceEndpoint(typeof(IService1), binding, baseAddress);
                myServiceHost.Open();
                serviceStarted = true;
                RefreshServiceStatus(this, null);
            }
        }
        private void RefreshServiceStatus(object sender, EventArgs e) ...
        private void StopService(object sender, EventArgs e) ...
    }
}
namespace MyWCFService
{
    public partial class Form1 : Form
    {
        IService1 IService1 = null;
        public Form1() { InitializeComponent(); }

        private void Form1_Load(object sender, EventArgs e)
        {
            EndpointAddress address = new EndpointAddress(new Uri("net.tcp://localhost:2202/Service1"));
            NetTcpBinding binding = new NetTcpBinding();
            ChannelFactory<IService1> factory = new ChannelFactory<IService1>(binding, address);
            IService1 = factory.CreateChannel();
        }

        private void btnTest_Click(object sender, EventArgs e)
        {
            lblResponse.Text = IService1.GetData(txtSomeText.Text);
        }
    }
}
我使用WCF测试客户端(WinFormsWCFTester)测试此服务,该客户端使用 并且在WinForm上有以下代码

namespace MyWCFService
{
    public partial class Form1 : Form
    {
        bool serviceStarted = false;
        ServiceHost myServiceHost = null;
        Uri baseAddress = new Uri("net.tcp://localhost:2202/Service1");
        NetTcpBinding binding = new NetTcpBinding();
        public Form1() { InitializeComponent(); }

        private void StartService(object sender, EventArgs e)
        {
            if (!serviceStarted)
            {
                myServiceHost = new ServiceHost(typeof(Service1), baseAddress);
                myServiceHost.AddServiceEndpoint(typeof(IService1), binding, baseAddress);
                myServiceHost.Open();
                serviceStarted = true;
                RefreshServiceStatus(this, null);
            }
        }
        private void RefreshServiceStatus(object sender, EventArgs e) ...
        private void StopService(object sender, EventArgs e) ...
    }
}
namespace MyWCFService
{
    public partial class Form1 : Form
    {
        IService1 IService1 = null;
        public Form1() { InitializeComponent(); }

        private void Form1_Load(object sender, EventArgs e)
        {
            EndpointAddress address = new EndpointAddress(new Uri("net.tcp://localhost:2202/Service1"));
            NetTcpBinding binding = new NetTcpBinding();
            ChannelFactory<IService1> factory = new ChannelFactory<IService1>(binding, address);
            IService1 = factory.CreateChannel();
        }

        private void btnTest_Click(object sender, EventArgs e)
        {
            lblResponse.Text = IService1.GetData(txtSomeText.Text);
        }
    }
}
注意:该地址来自运行WinFormsServiceHost时添加服务引用生成的WSDL。我使用更新的WSDL导入器为Delphi7创建了一个Pascal代理类

在我的电脑上的情况(当我将代码移动到另一台电脑或更糟的电脑上时,甚至会发生更奇怪的事情-例如,虚拟机!) 当服务运行时(由WCF服务主机托管-VS2010调用的WcfSvcHost.exe),Webbrowser可以导航到

http://localhost:8732/Design_Time_Addresses/MyWCFService/Service1/
telnet可以连接到本地主机8732。我的Delphi客户端(Delphi7WCFTester)可以连接并正常工作,但我的WCF客户端(WinFormsWCFTester)无法连接(异常消息“无法连接到网络”。tcp://localhost:2202/Service1 …TCP错误代码10061…目标计算机主动拒绝它127.0.0.1:2202”)

当服务由my WinFormsServiceHost托管并在Visual Studio调试器中运行时,Webbrowser可以导航到端口8732或2202,telnet可以连接到端口8732或2202。两个客户端(WinFormsWCFTester和Delphi7WCFTester)都可以连接并正常工作

当服务由WinFormsServiceHost托管并作为exe独立运行时(我使用VS2010中的Ctrl-F5),两个地址都不能用Webbrowser浏览。Telnet可以连接到2202,但不能连接到8732。我的WinFormsWCFTester客户端连接并正常工作,但我的Delphi7WCFTester无法连接

我的问题
从我对自己处境的详尽描述中,你可能可以看出,我有点迷路了。我需要一些指导来重新控制正在发生的事情。无论服务是如何托管的,两个客户端都应该连接并正常工作。我知道我有很多东西要学。我希望有人能给我一些重要的建议,引导我朝着正确的方向前进。

似乎您希望有一个客户端应用程序(Delphi或WinForm)可以连接到不同的服务实例,而无需更改客户端配置。您已经为netTcpBinding配置了WinForm服务实例,并为basicHttpBinding配置了MyWCFService实例。Delphi客户端只能连接到MyWCFService实例,因为它们都使用basicHttpBinding;WinForm客户端只能连接到WinForm实例,因为它们都使用netTcpBinding


为了实现您认为应该有效的功能,您需要配置这两个服务实例,以公开basicHttpBinding和netTcpBinding的端点。我从未尝试在WinForm应用程序中使用basicHttpBinding,但我认为应该可以使用。

Sam,您好。我有一个像你一样的问题。我有两个端点的wcfservice。一个端点用于delphi(使用wcfextras flateern wsdl)。但我不能在Delphi7 wesdl进口商处选择它。你能帮我吗?@Andrew Kalashnikov,你需要falt wsdl(例如MyService.wsdl),你需要这个。从命令行使用wsdlimp.exe生成.pas文件,然后从D7 IDE(Shift-F11)内部将该.pas文件添加到项目中。然后,您将调用一个类似以下函数的函数:GetIService(usewdl:Boolean=System.False;Addr:string='';HTTPRIO:THTTPRIO=nil):IService;这里有一些有用的链接。希望这对你有帮助,安德鲁。
http://localhost:8732/Design_Time_Addresses/MyWCFService/Service1/
http://localhost:8732/Design_Time_Addresses/MyWCFService/Service1/