[英]Full duplex communication between wcf applications
For a proof of concept, I am trying to write two applications WcfApp1 and WcfApp2. 为了进行概念验证,我尝试编写两个应用程序WcfApp1和WcfApp2。
Problem: I am able to add service reference of WcfApp1 in WcfApp2 solution, but unable to add WcfApp2 in WcfApp1. 问题:我能够在WcfApp2解决方案中添加WcfApp1的服务引用,但是无法在WcfApp1中添加WcfApp2。 Although the code is same (of course changing basic_httpbinding_url).
尽管代码是相同的(当然更改了basic_httpbinding_url)。 Can anyone tell me what could be wrong with this?
谁能告诉我这有什么问题吗?
Detail: 详情:
WcfApp1 has: WcfApp1具有:
IWcfApp1_Class -> interface; IWcfApp1_Class->接口;
WcfApp1_Class -> class derived from interface above; WcfApp1_Class->从上面的接口派生的类;
WcfApp1_DClass -> class (as data structure); WcfApp1_DClass->类(作为数据结构);
WcfApp2 has: WcfApp2具有:
IWcfApp2_Class -> interface; IWcfApp2_Class->接口;
WcfApp2_Class -> class derived from interface above; WcfApp2_Class->从上面的接口派生的类;
WcfApp2_DClass -> class (as data structure); WcfApp2_DClass->类(作为数据结构);
Code of WcfApp1: WcfApp1的代码:
Uri baseAddress_BasicHttpBinding = new Uri("http://localhost:9001/WcfApp1");
Uri baseAddress_NetTcpBinding = new Uri("net.tcp://localhost:9001/WcfApp1");
Uri baseAddress_NetNamedPipeBinding = new Uri("http://localhost:9001/WcfApp1");// new Uri("net.pipe://localhost:9001/WcfApp1");
Uri baseAddress_WSHttpBinding = new Uri("http://localhost:9001/WcfApp1");
Uri baseAddress_WSDualHttpBinding = new Uri("http://localhost:9001/WcfApp1");
ServiceHost host;
public void f_BasicHttpBinding()
{
host = new ServiceHost(typeof(WcfApp1_Class), baseAddress_BasicHttpBinding);
ServiceMetadataBehavior smb = new ServiceMetadataBehavior();
smb.HttpGetEnabled = true;
smb.MetadataExporter.PolicyVersion = PolicyVersion.Policy15;
var behavior = host.Description.Behaviors.Find<ServiceBehaviorAttribute>();
behavior.InstanceContextMode = InstanceContextMode.Single;
host.Description.Behaviors.Add(smb);
try
{
host.Open();
}
catch (Exception exxx)
{
Console.WriteLine(exxx.ToString());
}
}
IWcfApp1_Class: IWcfApp1_Class:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.ServiceModel;
using System.ServiceModel.Description;
using System.Runtime.Serialization;
namespace WcfApp1
{
[ServiceContract]
interface IWcfApp1_Class
{
[OperationContract]
void Function1();
[OperationContract]
int Function2();
[OperationContract]
string Function3();
[OperationContract]
WcfApp1_DClass Function4();
[OperationContract]
void Function5(WcfApp1_DClass data);
[OperationContract]
WcfApp1_DClass Function6(WcfApp1_DClass data);
}
}
WcfApp1_Class: WcfApp1_Class:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace WcfApp1
{
class WcfApp1_Class :
IWcfApp1_Class
{
public void Function1()
{
Console.WriteLine("Function1 executed...");
}
public int Function2()
{
Console.WriteLine("Function2 executed...");
return 1;
}
public string Function3()
{
Console.WriteLine("Function3 executed...");
return "WcfApp1_Class->Function3";
}
public WcfApp1_DClass Function4()
{
WcfApp1_DClass data = new WcfApp1_DClass
{
student_Id = 1,
student_Name = "WcfApp1_DClass"
};
Console.WriteLine("Function4 executed...");
return data;
}
public void Function5(WcfApp1_DClass data)
{
if(data.student_Id == 2 && data.student_Name == "WcfApp2_DClass")
{
Console.WriteLine("Function5 executed... OK...");
return;
}
Console.WriteLine("Function5 executed... NOT OK...");
return;
}
public WcfApp1_DClass Function6(WcfApp1_DClass data)
{
if (data.student_Id == 2 && data.student_Name == "WcfApp2_DClass")
{
Console.WriteLine("Function6 executed... OK...");
data.student_Name = "WcfApp1_DClass";
return data;
}
Console.WriteLine("Function6 executed... NOT OK...");
return data;
}
}
}
WcfApp1_DClass: WcfApp1_DClass:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.ServiceModel;
using System.ServiceModel.Description;
using System.Runtime.Serialization;
namespace WcfApp1
{
[DataContract]
class WcfApp1_DClass
{
private int _student_Id;
private string _student_Name;
[DataMember]
public int student_Id
{
get
{
return _student_Id;
}
set
{
if(_student_Id != value)
{
_student_Id = value;
}
}
}
[DataMember]
public string student_Name
{
get
{
return _student_Name;
}
set
{
if (_student_Name != value)
{
_student_Name = value;
}
}
}
}
}
Code of WcfApp2: WcfApp2的代码:
Uri baseAddress_BasicHttpBinding = new Uri("http://localhost:9002/WcfApp2");
Uri baseAddress_NetTcpBinding = new Uri("net.tcp://localhost:9002/WcfApp2");
Uri baseAddress_NetNamedPipeBinding = new Uri("http://localhost:9002/WcfApp2");// new Uri("net.pipe://localhost:9002/WcfApp2");
Uri baseAddress_WSHttpBinding = new Uri("http://localhost:9002/WcfApp2");
Uri baseAddress_WSDualHttpBinding = new Uri("http://localhost:9002/WcfApp2");
ServiceHost host;
public void f_BasicHttpBinding()
{
host = new ServiceHost(typeof(WcfApp2_Class), baseAddress_BasicHttpBinding);
ServiceMetadataBehavior smb = new ServiceMetadataBehavior();
smb.HttpGetEnabled = true;
smb.MetadataExporter.PolicyVersion = PolicyVersion.Policy15;
var behavior = host.Description.Behaviors.Find<ServiceBehaviorAttribute>();
behavior.InstanceContextMode = InstanceContextMode.Single;
host.Description.Behaviors.Add(smb);
try
{
host.Open();
}
catch (Exception exxx)
{
Console.WriteLine(exxx.ToString());
}
}
IWcfApp2_Class: IWcfApp2_Class:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.ServiceModel;
using System.ServiceModel.Description;
namespace WcfApp2
{
interface IWcfApp2_Class
{
[OperationContract]
void Function1();
[OperationContract]
int Function2();
[OperationContract]
string Function3();
[OperationContract]
WcfApp2_DClass Function4();
[OperationContract]
void Function5(WcfApp2_DClass data);
[OperationContract]
WcfApp2_DClass Function6(WcfApp2_DClass data);
}
}
WcfApp2_Class: WcfApp2_Class:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace WcfApp2
{
class WcfApp2_Class :
IWcfApp2_Class
{
public void Function1()
{
Console.WriteLine("Function1 executed...");
}
public int Function2()
{
Console.WriteLine("Function2 executed...");
return 1;
}
public string Function3()
{
Console.WriteLine("Function3 executed...");
return "WcfApp1_Class->Function3";
}
public WcfApp2_DClass Function4()
{
WcfApp2_DClass data = new WcfApp2_DClass
{
student_Id = 1,
student_Name = "WcfApp1_DClass"
};
Console.WriteLine("Function4 executed...");
return data;
}
public void Function5(WcfApp2_DClass data)
{
if (data.student_Id == 2 && data.student_Name == "WcfApp2_DClass")
{
Console.WriteLine("Function5 executed... OK...");
return;
}
Console.WriteLine("Function5 executed... NOT OK...");
return;
}
public WcfApp2_DClass Function6(WcfApp2_DClass data)
{
if (data.student_Id == 2 && data.student_Name == "WcfApp1_DClass")
{
Console.WriteLine("Function6 executed... OK...");
data.student_Name = "WcfApp2_DClass";
return data;
}
Console.WriteLine("Function6 executed... NOT OK...");
return data;
}
}
}
WcfApp2_DClass: WcfApp2_DClass:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.ServiceModel;
using System.ServiceModel.Description;
using System.Runtime.Serialization;
namespace WcfApp2
{
[DataContract]
class WcfApp2_DClass
{
private int _student_Id;
private string _student_Name;
[DataMember]
public int student_Id
{
get
{
return _student_Id;
}
set
{
if (_student_Id != value)
{
_student_Id = value;
}
}
}
[DataMember]
public string student_Name
{
get
{
return _student_Name;
}
set
{
if (_student_Name != value)
{
_student_Name = value;
}
}
}
}
}
Error Message: 错误信息:
There was an error downloading ' http://localhost:9002/WcfApp2/ $metadata'.
下载' http:// localhost:9002 / WcfApp2 / $ metadata'时出错 。 The request failed with HTTP status 405: Method Not Allowed.
请求失败,HTTP状态为405:不允许使用方法。 Metadata contains a reference that cannot be resolved: ' http://localhost:9002/WcfApp2 '.
元数据包含无法解析的引用:' http:// localhost:9002 / WcfApp2 '。 There was no endpoint listening at http://localhost:9002/WcfApp2 that could accept the message.
在http:// localhost:9002 / WcfApp2上没有侦听终结点的端点可以接受该消息。 This is often caused by an incorrect address or SOAP action.
这通常是由不正确的地址或SOAP操作引起的。 See InnerException, if present, for more details.
有关更多详细信息,请参见InnerException(如果存在)。 The remote server returned an error: (404) Not Found.
远程服务器返回错误:(404)找不到。 If the service is defined in the current solution, try building the solution and adding the service reference again.
如果服务是在当前解决方案中定义的,请尝试构建解决方案并再次添加服务引用。
Found the trouble spot. 找到了麻烦点。
I was missing [ServiceContract]
in IWcfApp2_Class
interface. 我在
IWcfApp2_Class
界面中缺少[ServiceContract]
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.