Recognize WCF solution - c#

I am new in Web Service Developement in .NET. Now I am analyzing a big solution of dozens of projects. There I have project that uses a web service and I want to know if it is a WCF Service or some other kind like Web API...
In the past I used ASMX Web Services in .NET and you were able to recognize a ASMX web service via its file extension. But here I don't see any special extensions in the project. I have read that WCF Services have .svc files if they are hosted in IIS. But this project doesn't have a .svc file. So, what are the main characteristics which distinguish a WCF Service from other web services in .NET.
The structure of the solution is as following:
-Solution
+-CreateDocWebServiceInterface
+-CreateDocWebService
+-...
The CreateDocWebServiceInterface looks like that:
namespace CreateDocWebServiceInterface
{
/// <summary>
/// </summary>
[ServiceContract(Name = "ICreateDocWebService", Namespace = "http://www.standardlife.de/CreateDocWebService")]
[RequiredParametersBehavior]
[ServiceKnownType(typeof(Bookmark))]
[ServiceKnownType(typeof(List<Bookmark>))]
public interface ICreateDocWebService
{
[OperationContract]
byte[] CreateDoc(OutputFormat OutputFormat, bool DuplexPrinting, List<Document> Documents);
}
}
And the CreateDocWebService looks like that:
namespace CreateDocWebService
{
// single threaded, but each request is handled concurrent !
[ServiceBehavior(InstanceContextMode = InstanceContextMode.PerCall, ConcurrencyMode = ConcurrencyMode.Single, Namespace = "http://www.blablabla.de/CreateDocWebService")]
public class CreateDocWebService : ICreateDocWebService
{
public byte[] CreateDoc(OutputFormat outputFormat, bool duplexPrinting, List<Document> documents)
{
bla bla bla
}
}
}
It could be a Web Service with Web API, but as I know Web API web services consist of controllers which derive from the ApiController?!(Is this correct and the unique characteristic of Web Api Web Services?)
So is this a WCF Service? And what is the unique characteristic of a WCF service and of an Web API Web Service

It is a WCF Project because your Interface is surrounded by [ServiceContract].
Another way if you want to know if it's a WCF Project or ASP.NET Web Service simply open your project's folders in File Explorer. You can hover over the icon with your mouse and a tooltip will display the project type as shown in the picture. Also, you can look under the Type column in File Explorer and it shows it there as well.
WCF Web Service Project:
ASP.NET Web Service Project:
Also to note, if your project has a Resources.Designer.cs or Settings.Designer.cs in its Properties folder it's likely a WinForms application.

Related

Can't add service reference

I have started learning WCF. I wrote a simple service to query a SQL relation through LINQ.
[ServiceContract]
[AspNetCompatibilityRequirements(RequirementsMode = aspNetCompatibilityRequirementsMode.Allowed)]
public class Order_WCFService
{
[OperationContract]
public List<Order> getOrders()
{
List<Order> orderList= null;
try
{
orderList= DAL.GetList<Order>();
return orderList;
}
catch (Exception)
{
throw;
}
}
}
This is located in ASP.NET-MVC project.
I have a simple silverlight application. It's in the same solution, but in a different project.
I would like to consume my service by a silverlight application.
I attempt to "Add Service Reference..." and in the left hand column I have a list of all available ASMX and WCF services. When I click on any of the services, it attempts to download service information, but fails after 10-20 seconds: "An error occured (details) while attempting to find services at..."
What am I doing wrong here?
Thank you
I'm 100% certain that services are functional because I can invoke them through AJAX.
Maybe a stupid question but was the service running when you attempted to add the service reference (if you are using the Visual Studio's built-in web server, was it started and the ASP.NET MVC project containing the service running)? Also you may try giving the full address of the WSDL in the Add Service Reference dialog instead of selecting it from a list after verifying that this WSDL is accessible in your browser.

DataContract create in WCF

At client side, I have this class without [DataContract]:
public class UserEntity
{
public string login;
public string password;
}
when I put [DataContract] and refresh the reference of this class at WCF side, then I can't initiate the web service. It says an error:
cannot create metadata...
What's wrong?
Are you sure that you actually know, why you can't refresh the reference? I mean you add [DataMember] - and it fails, you remove it - it works? Or it works several days ago and now you add [DataMember] (and many other stuff) and it not works now?
But anyway, the easiest way to solve "refresh reference" issues - to refresh reference manually with SvcUtil.exe. In this case error message would be much more descriptive the simple "oops! error!".
What is client and server side in your case? What is refreshing reference on the WCF side? Your description is very uncommon. Here is description how to create service with complex data type and WCF Class library:
Create WCF class library
Add data contract to the class library
Add service to class library
Implement service contract and service in the class library
Add host project
Reference WCF class library from host project
Host service from class library in host project
Add Metadata endpoint to your hosted service
Create client project
Run the host project outside the visual studio
Use Add service reference to create proxy on WCF service hosted in your host project
Implment code to call your service through created proxy
As you see there is no modification of data contract on the client side and no refreshing WCF service.

ASMX Web Reference not Updating After Service Return Type Updated

I have a webservice - called MyCompany.WebService1
I reference this using a web reference in my ASP.net web application.
Theres a method called "GetDeal" in this web service, that returns a "Deal" Object.
The deal object currently looks (for example) like this:
public class Deal
{
Public string Name {get;set;}
Public string Description {get;set;}
}
This class is in a different assembly: MyCompany.Model
The web service references this assembly.
In my web app, I can call the GetDeal method.
This returns Service1.Deal (service1 is just the name of the web reference)
I can access both properties above.
I have now changed the Deal class, and added a couple more properties.
However, I can't see these new properties in my web application.
I've updated the web service in the web application.
I rebuilt the web service several times, tried removing the MyCompany.Model reference and re-addding it etc...
I can't figure out what has changed... This was working - I have changed the model before, and it's updated the reference correctly...
Anything I've missed?
As long as the following points are fulfilled, this should work:
the new property is marked as Public and must be read/write (must have a getter and a setter)
you have compiled the host web application (the web app which exposes the web service).
(You can try calling the web service in a web browser to check whether the new property is visible).
you have updated the web reference the client application (and rebuilt the app)
In addition to what Martin suggests, you have to actually run the updated service.
I recommend you look at the WSDL to see if the changes took effect. Add "?wsdl" to the web service URL in the browser, and look to see if your new properties appear in the XML Schema at the top.

WCF and FluentNHibernate

I've hit a wall on this one. I have a WCF library with a respective WCF web service. A sandbox web application attempts to fire one method from this service.
The service, however, will log requests as they are made. The persistence layer here is built with FluentNHibernate. Session management in a web application has been pretty straight forward in the past(ie HttpModules), but in WCF it got a bit tricky for me.
I followed the notes and examples with the IglooCommons library and added the following line to my global.asax(residing in the web service directory).
protected void Application_Start(object sender, EventArgs e)
{
NHibernateFactory.Initialize(new SessionFactory().BuildSessionFactory());
}
BuildSessionFactory returns the following:
public class SessionFactory
{
public SessionFactory() { }
public ISessionFactory BuildSessionFactory()
{
return Fluently.Configure()
.Database(MsSqlConfiguration
.MsSql2005
.ConnectionString(x =>
x.FromConnectionStringWithKey("myConnection"))
.ShowSql()
.CurrentSessionContext<WebSessionContext>())
.Mappings(m =>
m.FluentMappings
.AddFromAssemblyOf<OneClass>()
.AddFromAssemblyOf<AnotherClass>()
.Conventions.Add(
PrimaryKey.Name.Is(x => x.EntityType.Name + "ID"),
ForeignKey.EndsWith("ID"),
Table.Is(x => Inflector.Net.Inflector.Pluralize(x.EntityType.Name))))
.BuildSessionFactory();
}
}
The service page(*.svc) loads up with its soothing stock blue "to generate classes use this wsdl" page, with no issue.
When the web application that references this attempts to call a service method,
NHibernateContext.Current().Session
is unable to find any live session. After stepping through the application, the app start method in global.asax is being fired, however seems to be dying(this is a guess) prior to any action requiring it.
I realize IglooCommons may be a bit specific as NHibernateContext is a proprietary library, however, WCF with a persistence layer isn't uncommon. Any thoughts on what I've missed or another direction to take are greatly appreciated.
Additional Note:
For the web application using this service, I've created an "interop" library which was based on the wsdl, auto-generated using svcutil. There isn't a web reference between the web app and the web service, just the web app using the auto-gen classes.
Have you enabled the ASP.NET service hosting environment for your WCF service? This requires that you:
Apply the AspNetCompatibilityRequirementsAttribute to your service with an AspNetCompatibilityRequirementsMode of Required.
That you configure the hosting environment in WCF web.config like so:
<system.serviceModel>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" />
<!-- rest of config here -->
</system.serviceModel>
More information about WCF Service hosting with ASP.NET is available here in the MSDN documentation.
This resolution in particular was a misunderstanding of the IglooCommons lib. The "NHibernateContext" attribute in the example was used to decorate the interface, when in reality it needed to decorate the implementation. By moving this alone, the sample on the Igloo site was able to function normally.
As a side note, the other solutions provided here were excellent in expanding the little knowledge I have of inner workings with WCF and its interaction with NHibernate.
Your WCF service svc.cs file should look like this:
[NHibernateContext(Rollback.Automatically)]
public class YourWcfService : IYourWcfService

ADO.NET Data Services in an ASP.NET-MVC project

I'm trying to add an ADO.NET data service to a vanilla ASP.NET-MVC project. Does anyone know if these technologies are compatible?
When I Ctrl+f5 the solution and visit the service URL all I get when is the very unhelpful "Request Error ... See server logs" page. Does the Development Web server even write any logs and if so where?
I guessed that routing may be the problem so I added:-
routes.IgnoreRoute("{service}.svc/{*pathInfo}");
in an attempt to fix this but that doesn't help.
I would rather not create a separate ASP.NET Web project just to host the data service. Are there other steps to addiing a Data service in an ASP.NET-MVC project that are not common to standard ASP.NET project?
Did you place debugging atribute into service class ?
**[System.ServiceModel.ServiceBehavior(IncludeExceptionDetailInFaults = true)]**
public class MyDataService : DataService<...>
{
// This method is called only once to initialize service-wide policies.
public static void InitializeService(IDataServiceConfiguration config)
{
// TODO: set rules to indicate which entity sets and service operations are visible, updatable, etc.
// Examples:
config.SetEntitySetAccessRule("*", EntitySetRights.AllRead);
config.SetServiceOperationAccessRule("*", ServiceOperationRights.All);
**config.UseVerboseErrors = true;**
}

Categories

Resources