我是apache突触的新手,这些例子对我没什么帮助。我在互联网上看,似乎没有关于它的材料,有人可以帮我提供一些信息吗?我需要c#中的发送者/接收者以及如何在突触中配置它。 不需要代码,只是如何受到欢迎。
[编辑]花了一些时间我创建了一个简单的代码来通过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,但是没有用。
答案 0 :(得分:0)
好吧,过了一会儿我发现了什么错了,我把绑定更改回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();
现在我收到的消息很好:)