Custom Class Inside a WCF Service Object - c#

A bit rusty here with regards to WCF Services.
I have a custom class named cSecurity.cs which does some custom functions.
I want to use this custom class inside my Service:
This is the App.svc.cs:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.ServiceModel.Web;
using System.Text;
namespace AppServices
{
public class App : IApp
{
public cSecurity _csec;
public string GetItems(int agentID, string agentName)
{
// Need to use some functions from the cSecurity class here???
return _csec.getItems();
}
}
}
This is the cSecurity.cs class:
using System.Collections;
using System.Configuration;
using System.Net;
namespace AppServices
{
public class cSecurity
{
// Some functions defined here....
public string getItems(){
return string.Empty;
}
}
}
But I am getting an error on the line:
public cSecurity _csec;
"The type or namespace name 'cSecurity' could not be found."
This seems pretty trivial but I seem to be lost here.
Appreciate any insight. Thanks.

For some reason, the solution for this was for me to close and restart VS. Not sure what caused the class for it to be not referenced by VS.

Related

SolrNet in C# example

I am trying to write a simple c# program to just connect to my Solr instance. I have downloaded the SolrNet library and made reference to SolrNet.dll in my project. I am following some of the examples online but have been getting the error "ServiceLocationProvider must be set" when the last line of my code is executed. Following is my code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.CompilerServices;
using CommonServiceLocator;
using SolrNet;
using SolrNet.Attributes;
using SolrNet.Impl;
using SolrNet.Impl.DocumentPropertyVisitors;
using SolrNet.Impl.FacetQuerySerializers;
using SolrNet.Impl.FieldParsers;
using SolrNet.Impl.FieldSerializers;
using SolrNet.Impl.QuerySerializers;
using SolrNet.Impl.ResponseParsers;
using SolrNet.Mapping;
using SolrNet.Mapping.Validation;
using SolrNet.Mapping.Validation.Rules;
using SolrNet.Schema;
using SolrNet.Utils;
namespace WebApplication1
{
public class Post
{
[SolrField("id")]
public string id { get; set; }
}
public class Program
{
public static void Main(string[] args)
{
var connection = new SolrConnection("http://localhost:8983/solr/test");
Startup.Init<Post>(connection.ServerURL);
var solr = ServiceLocator.Current.GetInstance<ISolrOperations<Post>>();
}
}
}
Can someone tell me what am I missing?
Thank You

C# dll System.Reflection.TargetInvocationException error

I'm new on vs C#. I want to create dll file too use meta trader 5. my dll correct working in visual studio. But not working in meta trader.
Problem is Newtonsoft.Json packages.
Code
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading.Tasks;
namespace Analiz
{
public class anlz
{
public static void metot()
{
var myDetails = JsonConvert.DeserializeObject<List<MyDetail>>(File.ReadAllText(#"C:\Users\Durak\AppData\Roaming\MetaQuotes\Terminal\D0E8209F77C8CF37AD8BF550E51FF075\MQL5\Files\json\deneme.json"));
}
}
public class MyDetail
{
public string emirtipi{get;set;}
public string miktar{get;set;}
public string takip{ get; set;}
}
}
Error :
enter image description here
When creating a DLL for an external program which does not support Newtonsoft.Json, you cannot build it this way.
Remove the reference to Newtonsoft.Json from your program.
Add a reference to System.Runtime.Serialization
After that you can refactor your code to:
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading.Tasks;
namespace Analiz
{
public class anlz
{
public static void metot()
{
System.Runtime.Serialization.Json.DataContractJsonSerializer serializer = new System.Runtime.Serialization.Json.DataContractJsonSerializer(typeof(List<Test>));
List<MyDetail> myDetails = (List<Test>)serializer.ReadObject(new FileStream(#"C:\Users\Durak\AppData\Roaming\MetaQuotes\Terminal\D0E8209F77C8CF37AD8BF550E51FF075\MQL5\Files\json\deneme.json", FileMode.Open, FileAccess.Read));
}
}
public class MyDetail
{
public string emirtipi{get;set;}
public string miktar{get;set;}
public string takip{ get; set;}
}
}

Entity Framework Windows App

I have EF application with following code.
using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace WinFormswithEFSample
{
public class ObservableListSource<T> : ObservableCollection<T>, IListSource
where T : class
{
private IBindingList _bindingList;
bool IListSource.ContainsListCollection { get { return false; } }
IList IListSource.GetList()
{
return _bindingList ?? (_bindingList = this.ToBindingList());
}
}
}
But when build the project attached error comming. What is the error in this code?
Try add namespace System.Data.Entity which resides in EntityFramework.dll library (this assembly is necessery).

In structuremap, how do I scan assemblies and add all registrations as singletons?

I wish for structuremap to scan my assemblies and register classes as singletons.
I'd further restrict this to factories, services etc.
For now, however, the challenge is to mark the found registrations as singletons.
I've found out that one way is through conventions.
I've found an example that marks a single, specific registration as singleton, but I want to do it for all registrations.
The example code does not compile; first of all because the IsConcrete etc is not available.
Does anyone have a way forward?
using StructureMap;
using StructureMap.Configuration.DSL;
using StructureMap.Graph;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
namespace planner_gui
{
public class SingletonConvention : IRegistrationConvention
{
public void Process(Type t, Registry registry)
{
if (!(t.IsConcrete()) || !(t.CanBeCreated()) ) return;
registry.For( ... ).Singleton().Use(t);
}
}
public class GuiRegistry : Registry
{
public GuiRegistry()
{
Scan(x =>
{
x.AssemblyContainingType<IExecutionContext>();
x.With(new SingletonConvention());
});
}
}
}
IsConcrete() method is an extension method in StructureMap.TypeRules namespace so adding
using StructureMap.TypeRules
would do the trick.

Can anyone assist with "The name 'posttype' does not exist in the current context" error

.......So, I have the below class which I have created as part of my automated test pack, but I am getting an error against the 'ListPostsPage.GoTo(PostType.Page)' line of code, advising that: 'the name PostType does not exist in the current context'. The code for this class is below:
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace WordpressTests
{
[TestClass]
public class PageTests
{
[TestInitialize]
public void Init()
{
Driver.Initialise();
}
[TestMethod]
public void CanEditAPage()
{
LoginPage.GoTo();
LoginPage.LoginAs("XXXXXX").WithPassword("XXXXXX").Login();
**ListPostsPage.GoTo(PostType.Page);**
ListPostsPage.SelectPost("Sample Page");
Assert.IsTrue(NewPostPage.IsInEditMode(), "Wasn't in edit mode");
Assert.AreEqual("Sample Page", NewPostPage.Title, "Title did not match");
}
[TestCleanup]
public void Cleanup()
{
Driver.Close();
}
}
}
Just for reference, the code for the ListPostsPage class is as follows:
using OpenQA.Selenium;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace WordpressTests
{
public class ListPostsPage
{
public static void GoTo(PostType postType)
{
switch (postType)
{
case PostType.Page:
Driver.Instance.FindElement(By.Id("menu-pages")).Click();
Driver.Instance.FindElement(By.LinkText("All Pages")).Click();
break;
}
}
public static void SelectPost(string title)
{
var postLink = Driver.Instance.FindElement(By.LinkText("Sample Page"));
postLink.Click();
}
public enum PostType
{
Page
}
}
}
Does anyone have any ideas as to what the issue may be? Please bear in mind I am fairly new to this, so please be nice! :-)
Any help would be much appreciated.
Cheers
Andy
PostType is an enum member of ListPostsPage but you're trying to access it as if it were a static class.
You should do this:
ListPostsPage.GoTo(ListPostsPage.PostType.Page);

Categories