【问题标题】:WCF service & TCP binding issueWCF 服务和 TCP 绑定问题
【发布时间】:2014-02-14 13:36:24
【问题描述】:

我正在学习 wcf。所以我只写了一个简单的地方,我使用 TCP 绑定和 basicHttpBinding。 当我只使用 basicHttpBinding 运行服务时,不会出现问题,但是当我进行 tcp 绑定时,就会出现问题。所以在这里我也粘贴了我的代码和屏幕截图。 我的解决方案屏幕截图

这是我的完整代码以及配置条目详细信息

namespace WcfServiceLibrary4
{
    // 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]
        string GetData(int value);

        [OperationContract]
        CompositeType GetDataUsingDataContract(CompositeType composite);

        // TODO: Add your service operations here
    }


    // Use a data contract as illustrated in the sample below to add composite types to service operations.
    [DataContract]
    public class CompositeType
    {
        bool boolValue = true;
        string stringValue = "Hello ";

        [DataMember]
        public bool BoolValue
        {
            get { return boolValue; }
            set { boolValue = value; }
        }

        [DataMember]
        public string StringValue
        {
            get { return stringValue; }
            set { stringValue = value; }
        }
    }
}

namespace WcfServiceLibrary4
{
    // 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 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;
        }
    }
}

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

  <system.web>
    <compilation debug="true" targetFramework="4.0" />
  </system.web>
  <system.serviceModel>
    <services>
      <service name="WcfServiceLibrary4.Service1">
        <host>
          <baseAddresses>
            <!--<add baseAddress = "http://localhost:8733/Service1/" />-->
            <add baseAddress="net.tcp://localhost:8734/Service1/"/>
          </baseAddresses>
        </host>
        <!--<endpoint address="" binding="basicHttpBinding" contract="WcfServiceLibrary4.IService1"/>
        <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>-->
        <endpoint address=""    binding="netTcpBinding" contract="WcfServiceLibrary4.IService1"/>
        <endpoint address="mex" binding="mexTcpBinding" contract="IMetadataExchange"/>
      </service>
    </services>
    <behaviors>
      <serviceBehaviors>
        <behavior>
          <serviceMetadata httpGetEnabled="False" httpsGetEnabled="False"/>
          <serviceDebug includeExceptionDetailInFaults="False" />
        </behavior>
      </serviceBehaviors>
    </behaviors>
  </system.serviceModel>

 <system.webServer>
    <modules runAllManagedModulesForAllRequests="true"/>
  </system.webServer>

</configuration>

当我从 VS2010 IDE 运行应用程序时,出现名为 无法添加服务的错误。服务元数据可能无法访问。确保您的服务正在运行并公开元数据。

所以搜索谷歌,从这个网址我知道我必须启动一些服务 http://rohitguptablog.wordpress.com/2011/06/16/configuring-wcf-service-with-nettcpbinding/

但是当我尝试启动这些服务时,我得到了错误

所以请详细指导我如何启动这些服务,并指导我在我的电脑中还需要设置什么,因此我可以使用来自 vs2010 ide 的我的电脑的 tcp 绑定来测试我的 wcf 应用程序。谢谢

【问题讨论】:

    标签: wcf nettcpbinding


    【解决方案1】:

    【讨论】:

    • 基本上当我从 wcf 测试客户端测试我的服务时,我得到了错误。这就是为什么我不考虑 iis。我想如果有问题然后 wcf 测试客户端喊,我想有一些问题可能在我的代码或配置代码中,或者我可能必须启动一些服务。我尝试启动服务但出现错误。所以请告诉我如何启动这些服务?如果有什么我需要安装然后告诉我。谢谢
    • 你启动net tcp端口共享服务了吗:msdn.microsoft.com/en-us/library/ms733925(v=vs.110).aspx
    • 那么您是自托管还是 IIS 托管?
    • 我计划在 iis 和自托管中托管,但首先尝试从 VS2010 IDE 运行服务。所以 wcf 测试客户端给出了问题。告诉我我需要修复什么,结果 wcf 测试客户端不会抛出任何错误。谢谢
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-07-08
    • 2018-02-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多