下面的wcf服务,一个协定是没有问题的,增加一个协定就出问题了。都是双工的:
[ServiceContract(CallbackContract = typeof(ISomeCallbackContract))]
public interface IService
{
[OperationContract(IsOneWay = true)]
void DoSomething();
}
//用于回调的契约
public interface ISomeCallbackContract
{
[OperationContract(IsOneWay = true)]
void SomeCallbackMethod();
}
[ServiceContract(CallbackContract = typeof(ISomeCallbackContract2))]
public interface IService2
{
[OperationContract(IsOneWay = true)]
string DoSomething2();
}
public interface ISomeCallbackContract2
{
[OperationContract(IsOneWay = true)]
void SomeCallbackMethod2();
}
实现类:
[ServiceBehavior(InstanceContextMode = InstanceContextMode.PerSession, ConcurrencyMode = ConcurrencyMode.Reentrant)]
public class MyService : IService, IService2
{
static List<ISomeCallbackContract> m_Callbacks = new List<ISomeCallbackContract>();
public void DoSomething()
{
ISomeCallbackContract callback = OperationContext.Current.GetCallbackChannel<ISomeCallbackContract>();
if (m_Callbacks.Contains(callback) == false)
{
m_Callbacks.Add(callback);
}
Console.WriteLine("这句话是在服务端执行的");
callback.SomeCallbackMethod();
}
public string DoSomething2()
{
ISomeCallbackContract2 callback = OperationContext.Current.GetCallbackChannel<ISomeCallbackContract2>();
callback.SomeCallbackMethod2();
return "dfdf";
}
}
配置文件:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.web>
<customErrors mode="Off" />
</system.web>
<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior name="metadataBehavior">
<serviceMetadata httpGetEnabled="false"/>
<serviceDebug includeExceptionDetailInFaults="true"/>
</behavior>
</serviceBehaviors>
</behaviors>
<bindings>
<netTcpBinding>
<binding name="netTcpBindingConfiguration">
<readerQuotas maxDepth="64" maxStringContentLength="2147483647 " maxArrayLength="2147483647 " maxBytesPerRead="4096" maxNameTableCharCount="16384" />
<reliableSession ordered="true" inactivityTimeout="00:10:00" enabled="false" />
<security mode="Transport">
<transport clientCredentialType="Windows" protectionLevel="EncryptAndSign" />
</security>
</binding>
</netTcpBinding>
</bindings>
<services>
<service name="Services.MyService" behaviorConfiguration="metadataBehavior">
<endpoint address="MyService" binding="netTcpBinding" contract="Contracts.IService" bindingConfiguration="netTcpBindingConfiguration" />
<endpoint address="MyService" binding="netTcpBinding" contract="Contracts.IService2" bindingConfiguration="netTcpBindingConfiguration" />
<endpoint address="mex" binding="mexTcpBinding" contract="IMetadataExchange" />
<host>
<baseAddresses>
<add baseAddress="net.tcp://localhost:9999/"/>
</baseAddresses>
</host>
</service>
</services>
</system.serviceModel>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true"/>
</system.webServer>
</configuration>
发布到Windows服务之后,客户端不能添加服务引用:

这是唱的哪一出啊,一个协定,一个回调,就没有问题,增加一个协定和一个回调,就出问题了,,,,
什么原因这是,请问
------解决思路----------------------
public interface IService2
{
[OperationContract(IsOneWay = true)]
string DoSomething2();
}
先改正错误,把IsOneWay去掉。
有返回值不可以是单向调用。