Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>"I am supposed to make my own WCF service that will communicate with the existing one and share some request and response objects which are already defined in the existing service." - This sounds like you need to create a <strong>client</strong> to connect to the service (see below how to create client). You can create WCF service to communicate with another service but you would need bit more background than this format allows.</p> <p>You can get up to speed with WCF through <a href="http://www.microsoft.com/en-us/download/details.aspx?id=21459" rel="nofollow">WCF examples</a>. Under WF_WCF_Samples\WCF\Basic in the examples you can find many Service/Client setups that you should go through first. <a href="http://msdn.microsoft.com/en-us/magazine/ee532094.aspx?sdmr=wcf&amp;sdmi=topics" rel="nofollow">MSDN Magazine</a> has tons of articles on this topic.</p> <p>In a 10,000 foot view of things:</p> <p>Client - To consume service create a test console application. Add Service Reference in your project (when you right click references you will see that option). Point the address of the Service Reference dialog to the service you would like to consume and lot of stuff will happen. Final result is that you can call service methods on your service with something like below (where Service1 will be replaced with what ever service you are calling)</p> <pre><code> static void Main(string[] args) { var proxy = new ServiceReference1.Service1Client(); var test = proxy.GetData(1); } </code></pre> <p>Service - you would create an interface with methods and types then decorate this interface with attributes for example:</p> <pre><code>[ServiceContract] public interface IService1 { [OperationContract] string GetData(int value); [OperationContract] CompositeType GetDataUsingDataContract(CompositeType composite); // TODO: Add your service operations here } </code></pre> <p>These are operations (OperationContract) that your serive can perform. Service methods can return primitive or complex type (string vs. CompositeType) as well as take parameters that are complex or primitive. </p> <p>You would implement this contract:</p> <pre><code>public class Service1 : IService1 { public string GetData(int value) { throw new ApplicationException("Boom"); return string.Format("You entered: {0}", value); } public CompositeType GetDataUsingDataContract(CompositeType composite) { if (composite == null) { throw new ArgumentNullException("composite"); } if (composite.BoolValue) { composite.StringValue += "Suffix"; } return composite; } } </code></pre> <p>Next you need to host your service. You have many options to accomplish this depending on your hosting requirements. The simplest hosting you can do is using Console application:</p> <pre><code>class Program { static void Main(string[] args) { var host = new ServiceHost(typeof(Service1), new Uri("http://localhost:8999/")); host.AddServiceEndpoint(typeof(IService1), new BasicHttpBinding(), ""); var metadataBehavior = host.Description.Behaviors.Find&lt;ServiceMetadataBehavior&gt;(); if (metadataBehavior == null) { metadataBehavior = new ServiceMetadataBehavior(); metadataBehavior.HttpGetEnabled = true; host.Description.Behaviors.Add(metadataBehavior); } host.Open(); Console.WriteLine("Running.."); Console.ReadLine(); } } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload