I've got a local WCF service in my solution which I have referenced. However my controller class is not able to pick up the Service namespace? Traditionally I would use svcUtil to write a wrapper class but as this is internal I though I could simply add 'Service Reference', tap into the namespace then simple invoke my service (ie var service = new QServiceReference.MyClass();)
I'm unable to show pictures so here's the structure for my solution,
Solution
-> Services Folder
-> QService Folder
QService Project
-> Web Folder
-> Zipporah.Queuing.Web (project)
-> Services References
-> QServiceReference
-> Controllers Folder
-> KioskProcessController
My class (KioskProcessController) is as follows:
using System.Web.Mvc;
using Zipporah.Queuing.Web.QServiceReference; (ITS THIS NAMESPACE REFERENCE THAT DOES NOT WORK)
namespace Zipporah.Queuing.Web.Controllers
{
public class KioskProcessController : ZipController
{
public ActionResult Index()
{
return View();
}
public ViewResult Queue()
{
return View();
}
public ViewResult PreAppointment()
{
return View();
}
}
}
Sorry if that structure is not clear (as aforementioned i cannot post pictures)
Any clues or thoughts would be most appreciated?
The namespace generated for your WCF Client might be different than the one you are using. In your Solution Explorer window, when you select your Service References folder, you can enable the Show All Files button and then navigate to file Reference.cs as shown in below screenshot:
Then, in Reference.cs file, you can find the actual generated namespace by the Add Service Reference dialog, which you can use in your other file with a using statement.
Related
I have been trying to add Azure application insights to a few projects. The whole experience was seamless with a .net core app. However, when I tried to update the Cloud role name property, that is where I could not find a lot for an OWIN based app. I want the name of the bubble in Insights Application Map to appear what I set in this property (My API for example) but it keeps resorting to the resource name that I have for this resource in Azure (my-azure-api). After scouring through most online resources, I was able to do the following which does not work.
using Microsoft.ApplicationInsights.Channel;
using Microsoft.ApplicationInsights.Extensibility;
namespace MyApp.Insights
{
public class RoleNameInitializer : ITelemetryInitializer
{
public void Initialize(ITelemetry telemetry)
{
// set role name correctly here.
telemetry.Context.Cloud.RoleName = "My API";
}
}
}
Also added the following in the applicationinsights.config
<Add Type="MyApp.Insights.RoleNameInitializer, MyApp"/>
Added the following to the startup class too (Just as a precaution)
using IntegratedTeleHealthPlatformApi.Insights;
using Microsoft.ApplicationInsights.Extensibility;
using Owin;
namespace MyApp
{
public partial class Startup
{
public void Configuration(IAppBuilder app)
{
TelemetryConfiguration
.Active
.TelemetryInitializers
.Add(new RoleNameInitializer());
ConfigureAuth(app);
ApplyDatabaseMigrations();
}
}
}
I just setup a simple owin based asp.net project(asp.net web application, then in nuget install Microsoft.Owin.Host.SystemWeb).
After the setup, in visual studio -> Project -> Add Application Insights Telemetry:
My custom TelemetryInitializer as below:
Then just add the initializer to the applicationinsights.config:
And after execution, the role name is the one which I set in the initializer:
Please have a try if it's ok at your side. And to make sure your RoleNameInitializer is called, you can set breakpoint there to see if it's called or not.
I have created an WEB API in ASP NET 5 and I can reference an external Class Library vNext.
I am working on Visual Studio 2015 Community.
In that Library I have this controller:
[Route("api/[controller]")]
public class NovosController : Controller
{
// GET: api/values
[HttpGet]
public IEnumerable<string> Get()
{
return new string[] { "i am", "an external library" };
}
To add this library in my Web API´s references I had to browse the DLL's (one for dnxcore50 and one for dnx451).
This is the result:
dnx451
dnxcore50
In my web API I can get the data from that controller but I can't acess it from URL.
But if the library is in the same Solution I can acess it from the URL.
For example:
If external library:
localhost:51000/api/novos
returns me nothing
but if the library is in the same solution:
localhost:51000/api/novos
returns me " i am an external library"
I want to acess by URL to the external library but I can't find any solution to my problem, there is anyone that knows how to make this thing work?
You don't need anything special to allow your external class library to be discovered by IControllerTypeProvider as long as you comply with the requisites:
has to be class
can’t be abstract
has to be public
has to be top-level (not nested)
can’t be generic
has to either derive from Controller base class or end in Controller suffix (for POCOs) and be located in an assembly that references MVC assembly
(Source)
In your particular case, I think you just need to remove the Route annotation, since it doesn't looks right.
using Microsoft.AspNet.Mvc;
using System.Collections.Generic;
namespace External.Controllers
{
[Route("api/[controller]")]
public class NovosController: Controller
{
[HttpGet]
public IEnumerable<string> Get()
{
return new string[] { "I am", "an external library" };
}
}
}
Hopefully someone can help me with this, because Sitefinity support appears to be stumped and the community on the G+ page seems stumped also.
I have a dead simple MVC widget:
Controller [~/Mvc/Controllers/TestWidgetController.cs]:
using System.Web.Mvc;
using Telerik.Sitefinity.Mvc;
namespace SitefinityWebApp.Mvc.Controllers
{
[ControllerToolboxItem(Name="TestWidget", Title="Test widget", SectionName="Test section")]
public class TestWidgetController : Controller
{
public ActionResult Index()
{
return View();
}
}
}
Model [~/Mvc/Models/TestWidgetModel.cs]:
namespace SitefinityWebApp.Mvc.Models
{
public class TestWidgetModel
{
}
}
View [~/Mvc/Views/TestWidget/Index.cshtml]:
<p>Test</p>
If I take the controller, the model and the view and drop them into a new Sitefinity project, and then build that project, the widget gets registered automatically without any problems and I can use it right away.
However, I have one specific Sitefinity project that I want to drop this widget into, and that project when built does not register the widget automatically. If I try to register the widget manually I get NullReference exceptions. It's like the project doesn't actually see those files somehow.
Does anyone have any idea what could be going on here? I think the simplicity of the widget and the fact that it works in a new Sitefinity project indicates that it's definitely something wrong with the way this particular project has been configured, but I can't figure out what the problem is.
For what it's worth here's the Solution Explorer for the problematic project:
You need to tell that the controller the page which is returned. Based on the file directory, it is Index.cshtml Therefore:
using System.Web.Mvc;
using Telerik.Sitefinity.Mvc;
namespace SitefinityWebApp.Mvc.Controllers
{
[ControllerToolboxItem(Name="TestWidget", Title="Test widget", SectionName="Test section")]
public class TestWidgetController : Controller
{
public ActionResult Index()
{
return View("Index");
}
}
}
It is now possible to have MVC widget in a separate assembly that automatically registers itself to the toolbox.
Check this doc for more info
Could you try to rename the controller and it toolbox name? Sometime Sitefinity works funny
It seems that you are having an issue regarding the widget registration in the controller store. Since most probably this issue is caused by problems related to this specific project it is highly advisable that you go and open a support ticket to the Sitefinity support system. By doing so your project can be inspected in more details and the most appropriate actions will be recommended.
Apart from that would you please point out the version of your SItefinity project? It will definitely help in the problem investigation.
Also there is an error log file which can be found at ~\App_Data\Sitefinity\Logs. Check and see what is logged there. This can give a clue about what is causing the issue and where to look at for possible solutions.
Regards,
Desislav
I have the following
ProjectA - has a helper method I'm creating to accept a wsdl generated type (.csproj is based on .NET 2.0 becaue it has to be for our legacy code)
ProjectAIntegrationTests (.csproj is based on .NET 4.5)
I've added a service reference to our WCF service to both projects in order to use it since I want to create a helper method in projectA that my Integration tests will test. I intend to send in a
Example:
ProjectA - contains a helper method to allow me to send in a request and get a response
the type I send in is a proxy instance of the type or at least that's my intention in how to do this.
using OurCompany.SomeAppName1.Payment.Integration.Tests.PaymentService
namespace EventInventory.TicketPoint.Payment
{
public static class HttpClientHelper
{
public static PreAuthorizeResponse SendHttpRequest(PreAuthorizeRequest authorizationRequest)
{
PreAuthorizeResponse response;
var service = new PaymentService.PaymentService();
response = service.PreAuthorize(authorizationRequest);
return response;
}
}
}
ProjectAIntegrationTests - Related Integration Test from
using System;
using OurCompany.SomeAppName1.Payment.PaymentService;
using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace OurCompany.SomeAppName1.Payment.Integration.Tests
{
[TestClass]
public class HttpClientHelperTests
{
...
[TestMethod]
public void SendRequest_PreAuthorizatoinWithMinimumValues_ReturnsAuthorizationRespones()
{
// Arrange
PaymentsClient serviceClient = new PaymentsClient(); // proxy client from wsdl
... more code
var preAuthorizeRequest = CreatePreAuthorizeRequest(transactionData, _merchantReference, _securityToken);
// Act
PreAuthorizeResponse preAuthorizeResponse = HttpClientHelper.SendHttpRequest(preAuthorizeRequest);
// Assert
}
The error I get is it's not recognizing the PreAuthorizationRequest instance I'm sending into HttpClientHelper.SendHttpReques() saying the following: "OurCompany.SomeAppName1.Payment.Integration.Tests.PaymentService.PreAuthorizationRequest is not assignable to OurCompany.SomeAppName1.Payment.PaymentService.PreAuthorizationRequest"
so the types are incompatible.
OurCompany.SomeAppName1.Payment.Integration.Tests.PaymentService.PreAuthorizationRequest is not a OurCompany.SomeAppName1.Payment.PaymentService.PreAuthorizationRequest according to .NET
Notice the only thing I can figure different here are the namespaces behind the service. I don't know if that matters but feels like it may be the problem, not sure. If that's true then you can't share client proxy types across projects? Each project is gonna have their own namespace that's specific to that project. My second projet has Integration.Tests in the namespace.
maybe this is a cross boundary thing also that plays into effect?
Try to see your proxy classes as totally different classes. Even if two classes have the same name and are identical (because they were generated from the same wsdl), it doesn't mean you can use an object of type namespace1.ServiceClient where a namespace2.ServiceClient is needed.
Normally, once you add a reference of ProjectA to ProjectAIntegrationTests, you will be able to use the service reference generated code in ProjectAIntegrationTests too. You don't need to add a new service reference on ProjectAIntegrationTests project.
You will also need to add an App.Config on ProjectAIntegrationTests and add there the configuration that you need to access the service (you can copy the necessary configuration from ProjectA).
Im creating a simple web service in a console app. (PersonService)
this is my Program.cs below
im trying to add a service reference to a different console app (PersonClient)
how can i do this?
i tried adding it by right clicking, add service reference, pointing to the refernce etc...
but it wont work.
[DataContract]
public class Person
{
[DataMember]
public string FirstName { get; set; }
[DataMember]
public string LastName { get; set; }
}
[ServiceContract]
public interface IPersonLookup
{
[OperationContract]
Person GetPerson(int identifier);
}
public class PersonService : IPersonLookup
{
public PersonService()
{
}
public Person GetPerson(int identifier)
{
Person p = new Person();
p.FirstName="Jane";
p.LastName="Doe";
return p;
}
}
class Program
{
static void Main(string[] args)
{
using (ServiceHost host = new ServiceHost(typeof(PersonService)))
{
WSHttpBinding binding = new WSHttpBinding();
host.AddServiceEndpoint(typeof(IPersonLookup), binding, "http://localhost:9090/PersonService");
host.Open();
Console.WriteLine("Listening....");
Console.ReadLine();
}
}
}
Solution:
Create a console application using visual studio.
Right click on the project and click on "Add Service Reference...".
On the window, you will find the "Advanced" button at the bottom.
Click on the button and it will open service reference settings window. It has a button at bottom called "Add Web Reference".
You need to read about WCF MEX Endpoints. Here's a blog post that may help.
You have two console exes, one which runs a ServiceHost - is that correct? Run the server console without debugging; then in the IDE add the WCF reference to the url. It should work, but it needs the server (your second console exe) to be running when you query the mex.
When you added the webservice reference, you defined the namespace and 'class name' for the service. You must either add the namespace reference ("using FooNameSpace;") or use the fully qualified class name of the service ("FooNameSpace.BarClass ws = new FooNameSapce.BarClass()");
Create a console application.
Right click on the References and click on Add Service
Reference.
Click on Advanced button at the bottom.
In the New Window click on Add Web Reference.
No one mentioned yet that you need a couple things before you can use "Add Service Reference".
Use the Visual Studio 2019 Installer tool to modify your existing installation.
Check the ".NET Desktop Development Workload". (This will add a second type of console app.)
Now launch VS 2019 and then create a project using: Console App (.NET Framework) IMPORTANT: Do not select the one for .NET Core, or it will not have the "Add Service Reference" option!
Now go to the main menu bar and select Project -> Add Service Reference. Now you can add your reference.
Happy coding!