Everyone! I have have custom WCF SOAP service (chatbot with getAnswer method that takes a string) and my client (website). My IService:
namespace WcfServiceLab1
{
[ServiceContract]
public interface IService1
{
[OperationContract]
string GetChatbotAnswerUsingDataContract(string question);
}
}
Service.svc:
namespace WcfServiceLab1
{
public class Service1 : IService1
{
public string GetChatbotAnswerUsingDataContract(string question)
{
Chatbot chatbot = new Chatbot();
return chatbot.GetAnswer(question);
}
}
}
And my ChatbotController:
[HttpPost]
public ActionResult Create(string question)
{
try
{
ViewBag.ChatbotAnswer = obj.GetChatbotAnswerUsingDataContract(question.ToLower());
ViewBag.YourQuestion = question;
return View("Index");
}
catch
{
return View("Index");
}
}
It's works on localhost, but when I upload my WCF service on free hosting using FTP and try to add Service References Visual Studio didn't find my service. It's here: http://chatbotservice.esy.es/WcfServiceLab1/
How to "install" wcf service on the remote server? What should I do?
Related
My interface look like this:
[ServiceContract]
public interface IMyService
{
[OperationContract]
myConnectedService.SomeComplexResponseType someMethod(myConnectedService.SomeComplexRequestType request);
}
My implementation look like this:
public class MyService : IMyService
{
myConnectedService_client client = new myConnectedService_client();
public myConnectedService.SomeComplexResponseType someMethod(myConnectedService.SomeComplexRequestType request)
{
myConnectedService.SomeComplexResponseType response = client.connectedServiceMethod(request);
return response ;
}
}
The error i get when i am trying to run my service:
Failed to add a service. Service metadata may not be accessible. Make sure your service is running and exposing metadata.
and
error CS0644: 'System.ComponentModel.PropertyChangedEventHandler' cannot derive from special class 'System.MulticastDelegate'
I created WCF service and calling it from the android studio and its working fine, but after implementing WCF perSession functionality it is working for a single user at a time.
Problem:
My problem is when i am hitting WCF url with multiple user my sessionID get overwrite by the latest logged in user, So how to maintain session for multiple user like we do in web application.
I used this to creste session in WCF:
[ServiceBehavior(InstanceContextMode = InstanceContextMode.PerSession)]
and this is my method to create sessionid within services class
public class MyService : IMyService
{
static string currentSessionID = string.Empty;
public string createSession()
{
currentSessionID = DateTime.Now.Ticks.ToString();
return currentSessionID;
}
public string Login()
{
var mysessionId = createSession();
return mysessionId;
}
public string Mymethods(string data)
{
string response = "";
if(data.StartsWith("01"))
response = Login();
return response;
}
}
and am hitting this createSession() method only in login function.
Please help me out of this.....
Thanks in advnance.
I have this simple service in my ASP.NET application:
// IBilling.cs
namespace WebApplication3.V1 {
[ServiceContract]
public interface IBilling {
[OperationContract]
string Get();
}
}
// Billing.svc
namespace WebApplication3.V1 {
public class Billing : IBilling {
public string Get() { return "Amiry"; }
}
}
It's accessible (by default) through /V1/Billing.svc route. However, I changed the route by adding this simple line to my route-table:
RouteTable.Routes.Add(
new ServiceRoute("api/ws/v1/billing",
new WebServiceHostFactory(),
typeof(Billing)));
Now, I can execute the Get() method and get result:
// it works:
http://localhost:7475/api/ws/v1/billing/get
BUT, the discovery address is not accessible:
http://localhost:7475/api/ws/v1/billing
// returns "Endpoint not found."
I'm pretty new to WCF services; so I have no idea where the problem could be and googling didn't help. Can you guide me to achieve the route I mentioned above please? Thanks in advance.
I have a simple web application on Asp.net MVC. I created a WFC Service so I can get data to my Windows 8.1 app, but my new functions are not showing in my client side.
This My WFC code:
[DataContract]
public class Service1 : IService1
{
ApplicationDbContext _db=new ApplicationDbContext();
public string GetData(int value)
{
return string.Format("You entered: {0}", value);
}
public WtFImages.Models.Images GetDataL(int value)
{
var User = _db.Image.Local.FirstOrDefault(c => c.Id == value);
return User;
}
public List<WtFImages.Models.Images> GetDataAll(int value)
{
var GetAllPublic = _db.Image.Local.ToList();
return (GetAllPublic);
}
public IList<WtFImages.Models.Images> ZGetDataAll(int value)
{
var GetAllPublic = _db.Image.Local.ToList();
return (GetAllPublic);
}
public CompositeType GetDataUsingDataContract(CompositeType composite)
{
if (composite == null)
{
throw new ArgumentNullException("composite");
}
if (composite.BoolValue)
{
composite.StringValue += "Suffix";
}
return composite;
}
}
}
My client side only shows the default functions.
Iservice Code
namespace ImageFechingWfc
{
// NOTE: You can use the "Rename" command on the "Refactor" menu to change the interface name "IService1" in both code and config file together.
[ServiceContract]
public interface IService1
{
[OperationContract]
string GetData(int value);
[OperationContract]
CompositeType GetDataUsingDataContract(CompositeType composite);
// TODO: Add your service operations here
}
// Use a data contract as illustrated in the sample below to add composite types to service operations.
[DataContract]
public class CompositeType
{
bool boolValue = true;
string stringValue = "Hello ";
[DataMember]
public bool BoolValue
{
get { return boolValue; }
set { boolValue = value; }
}
[DataMember]
public string StringValue
{
get { return stringValue; }
set { stringValue = value; }
}
}
}
Each method that you want to expose as service method, should exists in you IService1 interface and should be decorated with [OperationContract], then you should implement that method in service class.
Open IService1.cs and put signature of your methods is IService1 interface then decorate your new methods with [OperationContract], then put implementations in Service1 and rebuild the project, then add your service reference and use it.
Also You don't need that [DataContract] above your service implementation.
For example if you want to have an int Add(int x, int y) method in your service, put this in your IService1 interface:
[OperationContract]
int Add(int x, int y);
and then put this in your Service1 class:
public int Add(int x, int y)
{
return x+y;
}
To learn more about WCF services, you can read this Getting Started Tutorials
How to: Define a Windows Communication Foundation Service Contract
How to: Implement a Windows Communication Foundation Service Contract
How to: Host and Run a Basic Windows Communication Foundation Service
How to: Create a Windows Communication Foundation Client
How to: Configure a Basic Windows Communication Foundation Client
How to: Use a Windows Communication Foundation Client
First ensure that your methods are listed in wsdl or not ifnot then open the visual studio as administrator account and open from Visual C# Project File not Visual Studio Project User Options file (.user).
I have added remoting calls to my Windows Service so my GUI application can talk to it. It works great, but my channel implementation has no knowledge of my service.
How should I layer my classes so that my remoting channel implementation can call methods in my service class?
Channel Interface:
public interface IMyService
{
string Ping();
string SomeMethod(string input);
}
Channel Implementation:
public class MyServiceChannel : MarshalByRefObject, IMyService
{
public string Ping()
{
return "Pong";
}
public string SomeMethod(string input)
{
MethodForChannelToCall(input); // in Service class. How to reference?
return "Some Output";
}
}
Service Class
class MyService : ServiceBase
{
public void MethodForChannelToCall(string input)
{
// do service stuff for remoting call
}
public MyService()
{
// Set up remoting channel
try
{
TcpChannel tcpChannel = new TcpChannel(12345);
ChannelServices.RegisterChannel(tcpChannel, false);
RemotingConfiguration.RegisterWellKnownServiceType(
typeof(MyServiceChannel),
"MyServiceChannel",
WellKnownObjectMode.SingleCall);
// Should I pass an instance of my service to my channel somehow here?
}
catch (Exception ex)
{
this.EventLog.WriteEntry("Remoting error: " + ex.ToString());
}
}
}
How should I structure my classes so that my channel can call my service methods?
In this case you should use WCF. WCF replaces .net remoting.
If both your client and service are on the same machine you can use named pipes binding.
If they are on different machines you can use net tcpip binding.