Wcf 西铁服务及;TCP绑定问题
我正在学习wcf。所以我只写了一个简单的例子,使用TCP绑定&basicHttpBinding。 当我只使用basicHttpBinding运行服务时,就不会出现问题,但当我使用tcp绑定时,就会出现问题。所以在这里我粘贴我的代码和屏幕截图了。 我的解决方案屏幕截图 这是我的完整代码和配置条目的详细信息Wcf 西铁服务及;TCP绑定问题,wcf,nettcpbinding,Wcf,Nettcpbinding,我正在学习wcf。所以我只写了一个简单的例子,使用TCP绑定&basicHttpBinding。 当我只使用basicHttpBinding运行服务时,就不会出现问题,但当我使用tcp绑定时,就会出现问题。所以在这里我粘贴我的代码和屏幕截图了。 我的解决方案屏幕截图 这是我的完整代码和配置条目的详细信息 namespace WcfServiceLibrary4 { // NOTE: You can use the "Rename" command on the "Refactor" m
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>
命名空间WcfServiceLibrary4
{
//注意:您可以使用“重构”菜单上的“重命名”命令同时更改代码和配置文件中的接口名称“IService1”。
[服务合同]
公共接口IService1
{
[经营合同]
字符串GetData(int值);
[经营合同]
CompositeType GetDataUsingDataContract(CompositeType composite);
//TODO:在此处添加服务操作
}
//如下面的示例所示,使用数据协定将复合类型添加到服务操作中。
[数据合同]
公共类复合类型
{
布尔布尔值=真;
string stringValue=“Hello”;
[数据成员]
公共布尔布尔值
{
获取{返回布尔值;}
设置{boolValue=value;}
}
[数据成员]
公共字符串字符串值
{
获取{return stringValue;}
设置{stringValue=value;}
}
}
}
命名空间WcfServiceLibrary4
{
//注意:您可以使用“重构”菜单上的“重命名”命令来同时更改代码、svc和配置文件中的类名“Service1”。
公共类服务1:IService1
{
公共字符串GetData(int值)
{
返回string.Format(“您输入:{0}”,value);
}
公共复合类型GetDataUsingDataContract(复合类型复合)
{
if(composite==null)
{
抛出新的ArgumentNullException(“复合”);
}
if(复合布尔值)
{
composite.StringValue+=“后缀”;
}
收益组合;
}
}
}
您是否在IIS中启用了NET.TCP
见下文:
基本上,当我从wcf测试客户端测试我的服务时,我会遇到错误。这就是为什么我不考虑iis。我猜如果会有问题,然后wcf测试客户端会发出呼喊,我猜可能是我的代码或配置代码中有问题,或者可能是我必须启动一些服务。我试图启动服务,但出现错误。那就告诉我如何启动这些服务吧?如果我需要安装任何东西,请告诉我。感谢您启动网络tcp端口共享服务:那么您是自托管还是IIS托管?我计划在IIS和自托管中托管,但首先尝试从VS2010 IDE运行该服务。所以wcf测试客户端出现了问题。请告诉我需要修复什么,这样wcf测试客户端就不会抛出任何错误。谢谢