webservice in C#, wse 2.0 - c#

I have a problem.
I import this in to my program:
using Microsoft.Web.Services2;
using Microsoft.Web.Services2.Addressing;
using Microsoft.Web.Services2.Messaging;
I've also added Microsoft.Web.Services2.dll to my project, but I still get an error when I try to compile program ... What is wrong?
I get these errors:
Error 4 The type or namespace name 'Web' does not exist in the namespace 'Microsoft' (are you missing an assembly reference?)
Error 6 The type or namespace name 'SoapServiceAttribute' could not be found (are you missing a using directive or an assembly reference?)
more code:
[SoapService("http://www.example.org/test/")]
public class Payment : SoapClient
{
public Payment() : base( new Uri("http://localhost:8080/TestServer/services/testSOAP") )
{
}
[SoapMethod("http://www.example.org/test/paymant")]
public paymantResponse paymant( paymant request )
{
return (paymantResponse)base.SendRequestResponse("paymant", request).GetBodyObject( typeof(paymantResponse), SoapServiceAttribute.TargetNamespace);
}
public IAsyncResult Beginpaymant( paymant request, System.AsyncCallback callback, object asyncState)
{
return base.BeginSendRequestResponse("paymant", request, callback, asyncState);
}
public paymantResponse Endpaymant( System.IAsyncResult asyncResult )
{
return (paymantResponse)base.EndSendRequestResponse(asyncResult).GetBodyObject( typeof(paymantResponse), SoapServiceAttribute.TargetNamespace);
}
Everything connected with SoapService, SoapClient, SoapService attribute ... can*t get namespace or should I say reference ...
}

Related

I am unable to run tests on my code using NUnit framework, how do I properly reference it?

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using NUnit.Framework;
namespace Iteration1
{
[TestFixture]
public class IdentifiableObjectUnitTests //Rename this appropriately.
{
[Test]
public void TestAreYou()
{
IdentifiableObject id = new IdentifiableObject(new string[] { "fred", "bob" });
Assert.IsTrue(id.AreYou("fred"));
Assert.IsTrue(id.AreYou("bob"));
}
[Test]
public void TestNotAreYou()
{
IdentifiableObject id = new IdentifiableObject(new string[] { "fred", "bob" });
Assert.IsFalse(id.AreYou("wilma"));
Assert.IsFalse(id.AreYou("boby"));
}
[Test]
public void TestCaseSensitive()
{
IdentifiableObject id = new IdentifiableObject(new string[] { "fred", "bob" });
Assert.IsTrue(id.AreYou("FRED"));
Assert.IsTrue(id.AreYou("bOB"));
}
[Test]
public void TestFirstID()
{
IdentifiableObject id = new IdentifiableObject(new string[] { "fred", "bob" });
Assert.IsTrue(id.FirstId == "fred");
}
[Test]
public void TestAddID()
{
IdentifiableObject id = new IdentifiableObject(new string[] { "fred", "bob" });
id.AddIdentifier("wilma");
Assert.IsTrue(id.AreYou("fred"));
Assert.IsTrue(id.AreYou("bob"));
Assert.IsTrue(id.AreYou("wilma"));
}
}}
These are the errors I'm getting:
"The name 'Assert' does not exist in the current context"
"The type or namespace name 'NUnit' could not be found (are you missing a using directive or an assembly reference?)"
"The type or namespace name 'Test' could not be found (are you missing a using directive or an assembly reference?)"
"The type or namespace name 'TestAttribute' could not be found (are you missing a using directive or an assembly reference?)"
"The type or namespace name 'TestFixture' could not be found (are you missing a using directive or an assembly reference?)"
"The type or namespace name 'TestFixtureAttribute' could not be found (are you missing a using directive or an assembly reference?)"
Note: these errors occurred multiple times, so I'll attach a screenshot so as to not cause clutter.
Error Messages

The type or namespace name 'UserRoleLevelDetails' could not be found (are you missing a using directive or an assembly reference?)

I'm trying to use one method for storing and get list of object in session and use it in .cshtml file. For that I have given below code.
#inject IHttpContextAccessor HttpContextAccessor;
#using Microsoft.Extensions.Configuration
#inject IConfiguration Configuration
#model IEnumerable<TCS.ConfigDomainModel.UserManagement.UserRoleLevelDetails>
#using ConfigWeb.Helpers
#HttpContextAccessor.HttpContext.Session.GetObjectFromJson<UserRoleLevelDetails>("GetAllUsersList")
But when i use this I'm getting this error:
Cannot convert method group 'GetObjectFromJson' to non-delegate type 'object'. Did you intend to invoke the method?
So I changed this from:
#HttpContextAccessor.HttpContext.Session.GetObjectFromJson<UserRoleLevelDetails>("GetAllUsersList")
To
#(HttpContextAccessor.HttpContext.Session.GetObjectFromJson<UserRoleLevelDetails>("GetAllUsersList"))
Now I'm getting below error:
Error CS0246 The type or namespace name 'UserRoleLevelDetails' could not be found (are you missing a using directive or an assembly reference?)
Can anyone help on this?
I'm using below SessionHelper class
using Microsoft.AspNetCore.Http;
using Newtonsoft.Json;
using System.Collections.Generic;
namespace MMWeb.Helpers
{
public static class SessionHelper
{
public static void SetObjectAsJson(this ISession session, string key, object value)
{
session.SetString(key, JsonConvert.SerializeObject(value));
}
public static IList<T> GetObjectFromJson<T>(this ISession session, string key)
{
var value = session.GetString(key);
return value == null ? default(IList<T>) : JsonConvert.DeserializeObject<IList<T>>(value);
}
}
}
You could try typing the full path to the object.
change
#(HttpContextAccessor.HttpContext.Session.GetObjectFromJson<UserRoleLevelDetails>("GetAllUsersList"))
to
#(HttpContextAccessor.HttpContext.Session.GetObjectFromJson<TCS.ConfigDomainModel.UserManagement.UserRoleLevelDetails>("GetAllUsersList"))

How to resolve Errors of below code?

How to resolve Errors of below code?
Code
namespace Phonebook
{
using System;
using System.Data.Entity;
14- using System.Data.Entity.Infrastructure;
17- public partial class ContactsEntities : DbContext
{
public ContactsEntities()
20- : base("name=ContactsEntities")
{
}
24- protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
throw new UnintentionalCodeFirstException();
}
public virtual DbSet<Tbl_Contacts> Tbl_Contacts { get; set; }
public class DbSet<T>
{
internal object Tolist;
}
}
}
Errors
Error CS0115 'ContactsEntities.OnModelCreating(DbModelBuilder)': no
suitable method found to override Phonebook
C:\Users\PC\Desktop\Phonebook\ Phonebook \ModelContacts.Context.cs 24
Error CS0234 The type or namespace name 'Infrastructure' does not
exist in the namespace 'System.Data.Entity' (are you missing an
assembly reference?) Phonebook C:\Users\PC\Desktop\ Phonebook \
Phonebook \ModelContacts.Context.cs 14
Error CS0246 The type or namespace name 'DbModelBuilder' could not be
found (are you missing a using directive or an assembly reference?)
Phonebook C:\Users\PC\Desktop\
Phonebook\Phonebook\ModelContacts.Context.cs 24
Error CS0246 The type or namespace name 'DbContext' could not be
found (are you missing a using directive or an assembly reference?)
Phonebook C:\Users\PC\Desktop\ Phonebook\ Phonebook
\ModelContacts.Context.cs 17
Error CS1729 'DbContext' does not contain a constructor that takes 1
arguments Phonebook C:\Users\PC\Desktop\ Phonebook \Phonebook
\ModelContacts.Context.cs 20
My problem has been resolved :
I added EntityFramework to project from Nuget packages in visualStudio and I Performed ' Powershell ' settings in control panel .

How to compile C# application through Command Prompt

I have one folder. In that I have three cs files.
Demo.cs
using System;
namespace Demo
{
public class Test
{
public static Entity entity = new Entity();
public static void Main(string[] args)
{
var objectHandler = Activator.CreateInstance(null,
args);
var obj = objectHandler.Unwrap();
entity.GetAnnotation(obj.GetType());
}
}
}
Entity.cs
using System;
namespace Demo
{
public class Entity
{
public void GetAnnotation(Type classname)
{
Attribute[] dataAnnotationlist = Attribute.GetCustomAttributes(propInfo);
foreach (var dataannotationAttribute in dataAnnotationlist)
{
//some operation to get annotation property from Employee.cs class
}
}
}
}
Employee.cs
using System.ComponentModel.DataAnnotations;
namespace Demo
{
public class Employee
{
[Display(Name = "name")]
public string name { get; set; }
}
}
I have created XML file format from class file (Employee.cs) using reflection.
But error occurred when try to run through Command Prompt. It runs in visual studio.
I want to run Test.cs, Entity.cs using command prompt with passing "Employee.cs" as a string parameter to Main method.
Now, I have passed hard coded as,
System.Runtime.Remoting.ObjectHandle objectHandler = Activator.CreateInstance(null, "Demo.Employee");
Its working fine but how to pass it through command.
Error Occurred is:
Entity.cs(8,29): error CS0234: The type or namespace name
'DataAnnotations' does not exist in the namespace
'System.ComponentModel' (are you missing an assembly reference?) Entity.cs(9,19): error CS0234: The type or namespace name
'Objects'
does not exist in the namespace 'System.Data' (are you missing an
assembly reference?) Employee.cs(6,33): error CS0234: The type or namespace name 'DataAnnotations' does
not exist in the namespace 'System.ComponentModel' (are you missing an
assembly reference?)
and it also shows error for "DataAnnotations" and "Objects".
how can i solve this problem?
One option to simply build .csproj with MSBUILD.
More entertaining is to configure all dependencies yourself via command line arguments of csc. For your immediate error you need to add references with /r: command similar to following
csc /out:Test.exe /r:System.ComponentModel.DataAnnotations.dll *.cs
For more details on command line arguments of csc check help csc /? or on MSDN CSC command line options and Building with CSC.

ASP.NET MVC2 and MEF - Why can't my MefControllerFactory get exports or MetaData?

I am following this blog post: http://blog.maartenballiauw.be/post/2009/04/21/ASPNET-MVC-and-the-Managed-Extensibility-Framework-%28MEF%29.aspx and I'm having dificulty implementing the MefControllerFactory.
MefControllerFactory Code
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.ComponentModel.Composition;
using System.ComponentModel.Composition.Hosting;
using System.Web.Mvc;
namespace plugme.Utilities
{
public class MefControllerFactory : IControllerFactory
{
private string pluginPath;
private DirectoryCatalog catalog;
private CompositionContainer container;
private DefaultControllerFactory defaultControllerFactory;
public MefControllerFactory(string pluginPath)
{
this.pluginPath = pluginPath;
this.catalog = new DirectoryCatalog(pluginPath);
this.container = new CompositionContainer(catalog);
this.defaultControllerFactory = new DefaultControllerFactory();
}
#region IControllerFactory Members
public IController CreateController(System.Web.Routing.RequestContext requestContext, string controllerName)
{
IController controller = null;
if (controllerName != null)
{
string controllerClassName = controllerName + "Controller";
// "Export" isn't recognized
// and "Metadata" (as in c => c.Metadata ) isn't recognized.
Export<IController> export = this.container.GetExports<IController>()
.Where(c => c.Metadata.ContainsKey("controllerName")
&& c.Metadata["controllerName"].ToString() == controllerName)
.FirstOrDefault();
if (export != null)
{
controller = export.GetExportedObject();
}
}
if (controller == null)
{
return this.defaultControllerFactory.CreateController(requestContext, controllerName);
}
return controller;
}
public void ReleaseController(IController controller)
{
IDisposable disposable = controller as IDisposable;
if (disposable != null)
{
disposable.Dispose();
}
}
#endregion
}
}
The errors I'm getting are:
Error 1 The type or namespace name 'Export' could not be found
(are you missing a using directive or an assembly reference?)
Error 2 'System.Lazy<System.Web.Mvc.IController>' does not contain a
definition for 'Metadata' and no extension method 'Metadata'
accepting a first argument of type
'System.Lazy<System.Web.Mvc.IController>' could be found
(are you missing a using directive or an assembly reference?)
Error 3 'System.Lazy<System.Web.Mvc.IController>' does not contain a
definition for 'Metadata' and no extension method 'Metadata'
accepting a first argument of type
'System.Lazy<System.Web.Mvc.IController>' could be found
(are you missing a using directive or an assembly reference?)
I'm rather confused as to why this wouldn't recognize Export or Metadata. Do you guys have any thoughts?
Edit
I changed the line:
Export<IController> export = this.container.GetExports<IController>()
.Where(c => c.Metadata.ContainsKey("controllerName")
&& c.Metadata["controllerName"].ToString() == controllerName)
.FirstOrDefault();
To:
var export = this.container.GetExports<IController>()
.Where(c => c.Metadata.ContainsKey("controllerName")
&& c.Metadata["controllerName"].ToString() == controllerName)
.FirstOrDefault();
That took care of my issues with Metadata. But now i hev a new error with the next if statement:
if (export != null)
{
controller = export.GetExportedObject();
}
error:
'System.Lazy<System.Web.Mvc.IController,System.Collections.Generic.IDictionary<string,object>>' does not contain a definition for 'GetExportedObject' and no extension method 'GetExportedObject' accepting a first argument of type 'System.Lazy<System.Web.Mvc.IController,System.Collections.Generic.IDictionary<string,object>>' could be found (are you missing a using directive or an assembly reference?)
That blog post was based on a preview version of MEF. The API changed before the final release, you should use export.Value instead of export.GetExportedObject().
also you can use :
Lazy<IController> export = this.container.GetExports<IController, IDictionary<string, object>>()
.Where(c => c.Metadata.ContainsKey("ControllerName")
&& c.Metadata["ControllerName"].ToString().ToLowerInvariant().Equals(controllerName.ToLowerInvariant())).
FirstOrDefault();
also , you need to implements the IControllerFactory function = >
public System.Web.SessionState.SessionStateBehavior GetControllerSessionBehavior(System.Web.Routing.RequestContext requestContext, string controllerName)
{
return SessionStateBehavior.Default;
}
new export
icontrollerfactory-implementation

Categories

Resources