Integrating Apache Synapse with .NET Client/Server

461 views Asked by At

I'm new to apache synapse and the examples didn't help me much. I look in the internet and it doesn't seem to have material about it, can someone help me with some info? I need a sender/receiver in c# and how to configure it in the synapse. Doesn't need code, just the how to is very welcome.

[EDIT] After spending some time i created a simple code to send a message through a WCFService, just like this:

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

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

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

}

My web config:

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

In Synapse i put the wsdl under: repository/conf/wsdl/publisher.wsdl and configured the mains.xml as:

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

The Synapse runs ok, my webservice as well but i don't have any idea how to get the string from the client side i tried the following code but i get a timeout everytime:

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

            }
        }

Can someone give me a hint in what am i doing wrong?

[EDIT 2] I already tried to change the bindings from wsHttpBinding to basic, didn't work.

1

There are 1 answers

0
Lucas Gazire On BEST ANSWER

Well, after a while a i found what's wrong, i changed the binding back to basicHttpBinding and my client code is as follow:

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

Now i'm receiveing the message fine :)