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.