WFC Service Not Seeing Operation Contract - c#

I am having a weird problem where I have a wcf service that has some Operation Contracts but when I add the service reference to another project they are there.
When I go to add -> add service reference. I put in the wfc url and the service shows up.
When I look at the operations list I see those endpoints but when I hit "ok" and then I try to find those endpoints in my project they are not found.
How can I go about debugging this?

Make sure you are using the correct Data Anotations on your interface, for example:
[ServiceContract]
public interface IService1
{
[OperationContract]
[FaultContract(typeof(ExceptionMessage))]
List<student> GetStudents();
[OperationContract]
[FaultContract(typeof(ExceptionMessage))]
void AddStudents(Student student);
[OperationContract]
[FaultContract(typeof(ExceptionMessage))]
void DeleteStudent(long StudentId);
}

You must have a [Service Contract] interface. And it should contain your methods

When you successfully add the service reference, the proxy class will be automatically generated in the project:
And it will automatically generate web.config, web.config contains endpoint information:

Related

Reference a DLL but only import some of the classes in it

I am consuming a legacy WCF service and need to put a ParameterInspector implementation onto the ServiceContract.
I have written a new contract with the ParameterInspector implementation fine, but the problem with this is that the Legacy service implementation has both the contract interface AND the service implementation in the same DLL.
i.e. LegacyDll.dll contains these namespaces
Legacy.Namespace.IService
Legacy.NameSpace.Service (: IService)
I have written the following namespace
namespace Legacy.Namespace
{
[ServiceContract]
public interface IService
{
[CustomDataOperationBehavior]
[OperationContract]
bool Methods(); ......
Everything works fine until I try to use the NEW contract (with the ParameterInspector) and the OLD service DLL, because the OLD service DLL serviceContract is the same namespace as the new ServiceContract.
So, my question is, can I reference LegacyDll.dll and somehow ignore the ServiceContract in it. i.e. partially reference a DLL ??

WCF Workflow Service REST interface [duplicate]

This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
RESTful Workflow Service Endpoints in WF4 / WCF
I am trying to make Windows Workflow Services 4.0 work with a REST interface. I have a very simple workflow service called "Service1" with a receiveRequest and sendResponse activity.
By default WF Services autogenerate the classes and interfaces implemented, however i would like to force the WF Service to use my own REST enabled interface instead of some internal autogenerated interface.
The interface would be the following:
[ServiceContract]
public interface IService
{
[OperationContract]
[WebInvoke( UriTemplate = "/Data/{item}", Method = "GET" )]
String GetData( Int32 item );
}
However, i have difficulties configuring the XAML to work with this interface.
I would need a XAML configuration like this to specify that the Service contract name is my own contract:
<Receive x:Name="__ReferenceID0" CanCreateInstance="True" DisplayName="ReceiveRequest" sap:VirtualizedContainerService.HintSize="464,90" OperationName="GetData" ServiceContractName="w:IService">
However when i run this workflow service i get the following exception:
The contract name 'wfService.IService' could not be found in the list of contracts implemented by the service 'Service1'.
However, the service that gets created behind the scenes does not implement the IService interface and i would like to know how can i extend the service that gets instantiated by the workflow engine to implement my own interface (which i described above)?
Thanks
In WF4 you cannot declare ServiceContract in code and use it. Contract is declared in XAML and WorkflowServiceHost generates endpoint from declaration.
To enable REST for for your workflowservice you have few options:
Use HttpWorkflowHost from http://wf.codeplex.com/wikipage?title=WebAPIWorkflow. Limitation is that then you will have only REST.
Do something similar to this: http://msdn.microsoft.com/en-us/library/aa967564.aspx
Differences are: replace WorkflowFormatterBehavior instead of DataContractSerializerOperationBehavior, arguments are extracted from message contract instead of operation contract and keep in mind that you will not have client part of this example and you will have to format response according to protocol.

Combine ADO.NET Data Service and custom ServiceContract in the same class?

I have an ADO.NET Data service that I run through WCF:
public class AdminService : DataService<BOPApplicationAccessEntities> {
public static void InitializeService(DataServiceConfiguration config) {
config.UseVerboseErrors = true;
config.DataServiceBehavior.MaxProtocolVersion = DataServiceProtocolVersion.V2;
config.SetEntitySetAccessRule("*", EntitySetRights.All);
}
}
I'd like to add some custom methods to it, such as the following contract
[ServiceContract]
public interface IAdminService {
[OperationContract]
void RequestAccess(int applicationID, string username);
}
If I add the decoration and implement the method on the data service, an error is thrown when a client tries to connect, saying:
AdminService implements multiple servicecontract types, and no endpoints are defined in the configuration file.
Is it not possible to add service contracts onto an ADO.NET data services service?
The error states that the service exposes multiple contracts (interfaces), which is true, because you just added a new one. The host is not able to work based on implicit default values anymore, because it does not know which service interface to host on which endpoint.
Make sure you have an explicit endpoint defined in your service configuration file for each contract your service implements. Thing will start to work for you again after that, though you might need to update the service reference in your client application after making the modifications.
Update: Combine How to disable authentication schemes for WCF Data Services which tells how to explicitly create an endpoint for your WCF Data Service with http://www.west-wind.com/weblog/posts/2008/Apr/10/WCF-REST-Configuration-for-ASPNET-AJAX-and-plain-REST-Services to troubleshoot problems with your specific error message.

Streamed transfer restrictions with WCF

According to the following guide at MSDN, any operations that use streamed transfers can only have one input/output parameter.
Link: http://msdn.microsoft.com/en-us/library/ms731913.aspx (see heading "Restrictions on Streamed Transfers")
I'm using streamed transfers for a WCF service that lets clients/consumers upload files to it. The upload itself works fine, but I need a way of passing two more input parameters along with the Stream object: 'string filename' and 'int userid'.
How would I go about doing this?
ThereĀ“s something called headers that you can use in your datacontract:
Example of the interface:
[ServiceContract]
public interface IFile
{
[OperationContract]
Stream DownloadFile(int fileid);
[OperationContract]
bool UploadFile(FileUploadMessage request);
}
Put this in a separate file:
[MessageContract]
public class FileUploadMessage
{
[MessageHeader(MustUnderstand = true)]
public int MyInt {get;set;
[MessageHeader(MustUnderstand = true)]
public string MyString {get;set;
[MessageBodyMember(Order = 1)]
public System.IO.Stream FileByteStream {get;set;}
}
I have a somewhat similar problem. I created a test project and used a post I found to successfully create a wcf service call it from another project. I have a solution and the two web projects. One project call the service in the other project using a service reference.
I had the ServiceContract and the message contract in the interface file generated by creating a wcf service (the file that start with "I"). All of this worked fine. Then I went to our company's main project. It has a main web project that hosts two silverlight project. However the web project is not really a project but started out life as a website with no project at all. I have assumed that adding the two silverlight projects to the website probably created a solution for all three projects. However I'm not certain how vs2010 sees the main website which I will assume has no pointers to any files as a "real" project would.
What happened was when I created the wcf service in the main website and put the ServiceContract and MessageContract into the interface file I got the "interfaces cannot declare types" messge regarding the MessageContract and its child classes. I'm trying to follow your advice onthis post by taking the MessageContract and putting it into another file but I'm not sure what type of file. I tried putting the Message contract into a class (cs file). However the ServiceContract refers to classes in the MessageContract and the ServiceContract is no longer seeing the classes in the MessageContract even though they are public.
What type of file should I use to separate the Message contract from the ServiceContract?
Thanks,
Fig

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.

Categories

Resources