将 Apache Synapse 与 .NET 集成 Client/Server
Integrating Apache Synapse with .NET Client/Server
我是 apache 突触的新手,这些示例对我帮助不大。我在网上查了一下,似乎没有 material 相关信息,有人可以帮我提供一些信息吗?我需要 c# 中的 sender/receiver 以及如何在突触中配置它。
不需要代码,欢迎使用方法。
[编辑] 花了一些时间后,我创建了一个简单的代码来通过 WCFService 发送消息,就像这样:
public class Publisher : IPublisher
{
public string SendData()
{
return "Teste";
}
}
[ServiceContract (Name = "SynapsePublisher")]
public interface IPublisher
{
[OperationContract (Name = "SendData")]
string SendData();
}
我的网络配置:
<?xml version="1.0"?>
<configuration>
<appSettings>
<add key="aspnet:UseTaskFriendlySynchronizationContext" value="true" />
</appSettings>
<system.web>
<compilation debug="true" targetFramework="4.5" />
<httpRuntime targetFramework="4.5"/>
</system.web>
<system.serviceModel>
<services>
<service name="SynapsePublisherWCF.Publisher">
<endpoint contract="SynapsePublisherWCF.IPublisher" binding="wsHttpBinding" bindingName="Binding" >
</endpoint>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior>
<!-- To avoid disclosing metadata information, set the values below to false before deployment -->
<serviceMetadata httpGetEnabled="true" httpsGetEnabled="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="false"/>
</behavior>
</serviceBehaviors>
</behaviors>
<bindings>
<wsHttpBinding>
<binding name="Binding">
<security mode="None" />
<reliableSession enabled="true" />
</binding>
</wsHttpBinding>
</bindings>
<protocolMapping>
<add binding="wsHttpBinding" scheme="https" />
</protocolMapping>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
</system.serviceModel>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true"/>
<!--
To browse web app root directory during debugging, set the value below to true.
Set to false before deployment to avoid disclosing web app folder information.
-->
<directoryBrowse enabled="true"/>
</system.webServer>
</configuration>
在 Synapse 中,我将 wsdl 置于:repository/conf/wsdl/publisher.wsdl
并将 mains.xml 配置为:
<sequence xmlns="http://ws.apache.org/ns/synapse" name="main">
<in>
<log level="full"/>
<send>
<!-- get epr from the given wsdl -->
<endpoint>
<wsdl uri="file:repository/conf/wsdl/publisher.wsdl"
service="Publisher"
port="Binding_SynapsePublisher"/>
</endpoint>
</send>
</in>
<out>
<send/>
</out>
Synapse 运行正常,我的网络服务也是如此,但我不知道如何从客户端获取字符串我尝试了以下代码,但每次都超时:
var webRequest = (HttpWebRequest)WebRequest.Create(url); //CreateWebRequest(url, action);
webRequest.Method = "POST";
webRequest.Headers.Add("SOAPAction: http://synapseServerAddress:8280/services/Publisher.Binding_SynapsePublisher/SendData");
webRequest.ContentType = "text/xml; charset=utf-8";
using (HttpWebResponse response = webRequest.GetResponse() as HttpWebResponse)
{
using (Stream stream = response.GetResponseStream())
{
XmlTextReader reader = new XmlTextReader(stream);
Console.WriteLine(reader.ToString());
}
}
谁能告诉我我做错了什么?
[编辑 2] 我已经尝试将绑定从 wsHttpBinding 更改为 basic,但没用。
好吧,过了一会儿我发现了问题,我将绑定改回 basicHttpBinding,我的客户端代码如下:
var url = @"http://synapseServerUrl:8280/services/Publisher.Binding_SynapsePublisher/";
var doc = new XmlDocument();
doc.LoadXml(@"<?xml version=""1.0"" encoding=""utf-8""?>
<soap:Envelope xmlns:soap=""http://schemas.xmlsoap.org/soap/envelope/""
xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance""
xmlns:xsd=""http://www.w3.org/2001/XMLSchema"">
<soap:Body>
<SendData xmlns=""http://tempuri.org/""></SendData>
</soap:Body>
</soap:Envelope>");
var webRequest = (HttpWebRequest)WebRequest.Create(url);
webRequest.Method = "POST";
webRequest.Headers.Add("SOAPAction", "http://tempuri.org/SynapsePublisher/SendData");
webRequest.ContentType = "text/xml; charset=\"utf-8\"";
webRequest.Accept = "text/xml";
Stream stream = webRequest.GetRequestStream();
doc.Save(stream);
stream.Close();
var response = (HttpWebResponse)webRequest.GetResponse();
StreamReader reader = new StreamReader(response.GetResponseStream());
var teste = reader.ReadToEnd().Trim();
Console.ReadLine();
现在我可以正常收到消息了:)
我是 apache 突触的新手,这些示例对我帮助不大。我在网上查了一下,似乎没有 material 相关信息,有人可以帮我提供一些信息吗?我需要 c# 中的 sender/receiver 以及如何在突触中配置它。 不需要代码,欢迎使用方法。
[编辑] 花了一些时间后,我创建了一个简单的代码来通过 WCFService 发送消息,就像这样:
public class Publisher : IPublisher
{
public string SendData()
{
return "Teste";
}
}
[ServiceContract (Name = "SynapsePublisher")]
public interface IPublisher
{
[OperationContract (Name = "SendData")]
string SendData();
}
我的网络配置:
<?xml version="1.0"?>
<configuration>
<appSettings>
<add key="aspnet:UseTaskFriendlySynchronizationContext" value="true" />
</appSettings>
<system.web>
<compilation debug="true" targetFramework="4.5" />
<httpRuntime targetFramework="4.5"/>
</system.web>
<system.serviceModel>
<services>
<service name="SynapsePublisherWCF.Publisher">
<endpoint contract="SynapsePublisherWCF.IPublisher" binding="wsHttpBinding" bindingName="Binding" >
</endpoint>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior>
<!-- To avoid disclosing metadata information, set the values below to false before deployment -->
<serviceMetadata httpGetEnabled="true" httpsGetEnabled="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="false"/>
</behavior>
</serviceBehaviors>
</behaviors>
<bindings>
<wsHttpBinding>
<binding name="Binding">
<security mode="None" />
<reliableSession enabled="true" />
</binding>
</wsHttpBinding>
</bindings>
<protocolMapping>
<add binding="wsHttpBinding" scheme="https" />
</protocolMapping>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
</system.serviceModel>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true"/>
<!--
To browse web app root directory during debugging, set the value below to true.
Set to false before deployment to avoid disclosing web app folder information.
-->
<directoryBrowse enabled="true"/>
</system.webServer>
</configuration>
在 Synapse 中,我将 wsdl 置于:repository/conf/wsdl/publisher.wsdl 并将 mains.xml 配置为:
<sequence xmlns="http://ws.apache.org/ns/synapse" name="main">
<in>
<log level="full"/>
<send>
<!-- get epr from the given wsdl -->
<endpoint>
<wsdl uri="file:repository/conf/wsdl/publisher.wsdl"
service="Publisher"
port="Binding_SynapsePublisher"/>
</endpoint>
</send>
</in>
<out>
<send/>
</out>
Synapse 运行正常,我的网络服务也是如此,但我不知道如何从客户端获取字符串我尝试了以下代码,但每次都超时:
var webRequest = (HttpWebRequest)WebRequest.Create(url); //CreateWebRequest(url, action);
webRequest.Method = "POST";
webRequest.Headers.Add("SOAPAction: http://synapseServerAddress:8280/services/Publisher.Binding_SynapsePublisher/SendData");
webRequest.ContentType = "text/xml; charset=utf-8";
using (HttpWebResponse response = webRequest.GetResponse() as HttpWebResponse)
{
using (Stream stream = response.GetResponseStream())
{
XmlTextReader reader = new XmlTextReader(stream);
Console.WriteLine(reader.ToString());
}
}
谁能告诉我我做错了什么?
[编辑 2] 我已经尝试将绑定从 wsHttpBinding 更改为 basic,但没用。
好吧,过了一会儿我发现了问题,我将绑定改回 basicHttpBinding,我的客户端代码如下:
var url = @"http://synapseServerUrl:8280/services/Publisher.Binding_SynapsePublisher/";
var doc = new XmlDocument();
doc.LoadXml(@"<?xml version=""1.0"" encoding=""utf-8""?>
<soap:Envelope xmlns:soap=""http://schemas.xmlsoap.org/soap/envelope/""
xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance""
xmlns:xsd=""http://www.w3.org/2001/XMLSchema"">
<soap:Body>
<SendData xmlns=""http://tempuri.org/""></SendData>
</soap:Body>
</soap:Envelope>");
var webRequest = (HttpWebRequest)WebRequest.Create(url);
webRequest.Method = "POST";
webRequest.Headers.Add("SOAPAction", "http://tempuri.org/SynapsePublisher/SendData");
webRequest.ContentType = "text/xml; charset=\"utf-8\"";
webRequest.Accept = "text/xml";
Stream stream = webRequest.GetRequestStream();
doc.Save(stream);
stream.Close();
var response = (HttpWebResponse)webRequest.GetResponse();
StreamReader reader = new StreamReader(response.GetResponseStream());
var teste = reader.ReadToEnd().Trim();
Console.ReadLine();
现在我可以正常收到消息了:)