2015-06-23 52 views
0

我是新來的apache突觸,這些例子並沒有多大幫助。我期待在互聯網上,它似乎沒有關於它的材料,有人可以幫我一些信息?我需要c#中的發件人/接收者以及如何在突觸中進行配置。 不需要代碼,只是如何非​​常歡迎。將Apache Synapse與.NET客戶端/服務器集成

[編輯]花一些時間,我創建了一個簡單的代碼通過WCFService發送消息,就像在此之後:

 public class Publisher : IPublisher 
    { 
     public string SendData() 
     { 
      return "Teste"; 
     } 
    } 

[ServiceContract (Name = "SynapsePublisher")] 
public interface IPublisher 
{ 

    [OperationContract (Name = "SendData")] 
    string SendData(); 

} 

我的web配置:

<?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> 

突觸我把下的wsdl:儲存庫/ 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> 

突觸運行正常,我的web服務,以及,但我沒有任何想法如何從客戶端我嘗試下面的代碼串,但我得到一個超時每次:

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更改爲基本,沒有工作。

回答

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(); 

現在我receiveing消息精細:)