Good morning all,
i have a somewhat complicated question; which i am trying to learn to answer myself.
I have a couple of questions about what it is that i am trying to accomplish, ie is that a RESTful or WCF action that im trying to accomplish.
So for the most part, i bought the O'Reilly book "Programming WCF Services" and i didnt seem to really answer what i am trying to do, however learned some good knowledge of things.
So for my question:
Q 1) So What is the difference between RESTful and WCF?
I have learned how to set up a WCF Application via VS and load it in the URL: ex localhost:1111/myservice.svc/dothis, but whenever i google or look at tutorials, they have localhost/dothis and again i cant really find out how to pass parameters from computer A to computer B and computer B spits it out.
When i launch a program to run the below code, i get an error saying that

[Connector] There was no endpoint listening at http://localhost/Submit that could accept the message. This is often caused by an incorrect address or SOAP action. See InnerException, if present, for more details.

Computer A has a program that is running this code and gathering the respected info and posting it. Keep in mind that i got this from someone, but still have some knowledge of whats going on.
Service Contract for ItemService.cs

using System.ServiceModel;
using System.ServiceModel.Web;

namespace Service
{
    [ServiceContract]
    public interface IItemService
    {
        [OperationContract]
        [WebInvoke(Method="POST", ResponseFormat = WebMessageFormat.Json, RequestFormat = WebMessageFormat.Json)]
        string Submit(ItemData data);    
    }
}

Connector.cs

using System;
using System.ServiceModel;
//using System.ServiceModel.Description;
using System.ServiceModel.Web;

namespace Collection.Network
{
    public class Connector
    {
        const string ItemServiceUrl = "http://localhost/ItemService";

        private static Connector _instance;
        private bool _initialized;
        private Uri _serverUri;
        private ChannelFactory<IItemService> _httpFactory;
        private IItemService _httpProxy;

        public static Connector Instance { get { return _instance ?? (_instance = new Connector()); } }

        public void SendItem(ItemData itemData)
        {
            try
            {
                ClientInitialize();

                var result = _httpProxy.Submit(itemData);
                LoggerIt.Debug("Item Service Response: {0}", result);
            }
            catch (Exception ex)
            {
                LoggerIt.Error("Error sending Item: " + itemData.Name + ", " + ex.Message);
            }
        }

        private void ClientInitialize()
        {
            try
            {
                if (!_initialized)
                {
                    _serverUri = new Uri(ItemServiceUrl);

                    LoggerIt.Log("Initializing Client Service connection to {0}", _serverUri.AbsoluteUri);

                    WebHttpBinding webHttpBinding = new WebHttpBinding
                    {
                        OpenTimeout = TimeSpan.FromMilliseconds(5000),
                        SendTimeout = TimeSpan.FromMilliseconds(5000),
                        CloseTimeout = TimeSpan.FromMilliseconds(5000),
                    };

                    _httpFactory = new WebChannelFactory<IItemService>(webHttpBinding, _serverUri);
                    _httpProxy = _httpFactory.CreateChannel();

                    _initialized = true;
                }
            }
            catch (Exception ex)
            {
                LoggerIt.Log("Exception in ClientInitialize() {0}", ex);
            }
        }
    }
}

So.. on in connector.cs, what is this exactly doing on Computer A. Is it opening up an instance for the program to pass the parameters to computer B?

Q 2) What is it that i need to research for Computer B to accept the POST parameters from the url? WCF, RESTful API, REST..?? and do i need to set up a WCF service on Computer B? I know how to store information via php and mysql, so thats not an issue, just need to know what to research or point me in some sort of direction.

I do appreciate any responses that you provide.

A web service is a piece of software, running on the server (computer B) and listening on a particular port (optional).
Computer A would post data to the URL and port the web service is listening on and it will be processed on computer B.

You can post information to a URL with particularly ever programming language (.Net, cURL, PHP, javascript, the list goes on) and all server side languages should be able to create a web service to listen on a port. So you can definitely do what you want with WCF or a variety of RESTful architectures.

The error you are getting is almost certainly because you haven't set up an endpoint or the endpoint is wrong and isn't aimed at the connector's location.

So what you are saying is that i need to create a website -> WCF Service in VS? or actually create a website via xampp or apache and have it listen on that port?
The code that i posted will be running on computer A (client) posting the info to computer B (server)

Im using a console application to run a service host on computer B, so do i just need to add the endpoint there? or am i way off the mark?

Here is my host service app.config

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <system.serviceModel>
    <behaviors>
      <serviceBehaviors>
        <behavior name="mexBehaviour">
          <serviceMetadata httpGetEnabled="true" />
        </behavior>
      </serviceBehaviors>
      <endpointBehaviors>
        <behavior name="mexBehaviour">
          <webHttp />
        </behavior>
      </endpointBehaviors>
    </behaviors>
    <services>
      <!-- name is from HelloService.cs namespace.class. behaviorConfiguration is from the endpoint address.-->
      <service name="ItemService.ItemService" behaviorConfiguration="mexBehaviour">
        <endpoint name="web" address="web" binding="webHttpBinding" behaviorConfiguration ="mexBehaviour" contract="ItemService.IItemService"></endpoint>
        <host>
          <baseAddresses>
            <!--// For basicHttpBinding endpoint (where the web address will enter)-->
            <add baseAddress="http://localhost/ItemService" />
          </baseAddresses>
        </host>
      </service>
    </services>
  </system.serviceModel>
</configuration>

Program.cs for the host service

namespace ItemServiceHost
{
    class Program
    {
        static void Main()
        {
            using (ServiceHost host = new ServiceHost(typeof(ItemService.ItemService)))
            {
                host.Open();
                Console.WriteLine("Host Started @ " + DateTime.Now.ToString());
                Console.ReadLine();
            }
        }
    }
}

when i had the endpoint address as "http://localhost/ItemService" instead of "web", i was able to view the servcie. However, when i did /Submit, i got an error saying "endpoint not found". If i change the endpoint to web, i put in the address with /Submit and i get a big white blank screen.

The IItemService.cs to recieve the url parameters.

using System.ServiceModel;
using System.ServiceModel.Web;

namespace ItemService
{
    // NOTE: You can use the "Rename" command on the "Refactor" menu to change the interface name "IItemService" in both code and config file together.
    [ServiceContract]
    public interface IItemService
    {
        [OperationContract]
        string Submit(string itemData);
    }
}

The ItemService.cs

namespace ItemService
{
    // NOTE: You can use the "Rename" command on the "Refactor" menu to change the class name "ItemService" in both code and config file together.
    public class ItemService : IItemService
    {
        public string Submit(string itemData)
        {
            return "hello " + itemData;
        }
    }
}

So i found out what it was, the endpoint address was address="web", so i changed it to address="Sumit". Works now with the client.
Now im getting another error from the client (computer a) posting the data: The remote server returned an unexpected response: (405) Method Not Allowed.

Ill have to submit a thread for this one, because i definetly cannot figure it out.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.