Add web service with 2 interfaces - c#

I am updating a web service from VB to C#. This is a WCF service.
The web service implements 2 interfaces.
When I add the web service to a test application, only one of the interfaces is accessible.
When I try to invoke a method from the second interface, the method signature is not recognized.
This works in VB and I am hoping I can do the same in C#.
This is the implementation of the web service class:
PayService Interface:
namespace PayService
{
[ServiceContract (Namespace...)]
public interface IPayService
{
//Initiate a credit card authorization.
[OperationContract(IsOneWay = true)]
void Authorize(...12 arguments here...);
}
PayService2 Interface:
namespace PayService2
{
[ServiceContract (Namespace...)]
public interface IPayService
{
//Initiate a credit card authorization.
[OperationContract(IsOneWay = true)]
void Authorize(...13 arguments here...);
}
public partial class PayService : IPayService, IPayService2
{
Authorize(...there are 12 arguments here)
Authorize(...there are 13 arguments here)
...more methods but they are not a problem.
}
The calling application is just a web application to test the web service.
//Create instance of PayService
PayService.PayServiceClient payService = new PayService.PayServiceClient();
payService.Authorize(...12 arguments) //this one works fine
payService.Authorize(...13 arguments) //this one is not recognized
Does anyone have an idea why not all of the methods would be visible in the web application that uses the PayService?
Thanks.

Check this out: https://stackoverflow.com/a/720389/487940
You basically want to combine the 2 interfaces into a single interface, like this:
public interface IMyInterface : IInterface1, IInterface2

Related

how can i consume a method from a connected service in .NET WCF and expose it 'AS IS' in a new method in my WCF

My interface look like this:
[ServiceContract]
public interface IMyService
{
[OperationContract]
myConnectedService.SomeComplexResponseType someMethod(myConnectedService.SomeComplexRequestType request);
}
My implementation look like this:
public class MyService : IMyService
{
myConnectedService_client client = new myConnectedService_client();
public myConnectedService.SomeComplexResponseType someMethod(myConnectedService.SomeComplexRequestType request)
{
myConnectedService.SomeComplexResponseType response = client.connectedServiceMethod(request);
return response ;
}
}
The error i get when i am trying to run my service:
Failed to add a service. Service metadata may not be accessible. Make sure your service is running and exposing metadata.
and
error CS0644: 'System.ComponentModel.PropertyChangedEventHandler' cannot derive from special class 'System.MulticastDelegate'

Using the same dll in a web service and a client application

I'm updating a few web services that have some components in common, so I thought that by creating a library that has that code in it, it could ease maintenance. When using a class from said library, the web service forces me to call the method with its proxy class.
Since the system is somewhat old, I can't change the architecture. The compilation is made in x64. I've already attempted to change the "Reuse types in referenced assemblies".
Referencing a class "x" from the "y" library on a web service "w" forces me to use the class "w.x" instead of "y.x" on a service method call.
Best regards,
Fábio Jesus
The code that I can provide is the following:
Library
namespace Library1
{
public class Class1
{
}
}
Service
namespace Services
{
[ServiceContract]
public interface Service
{
[OperationContract]
void Method(Library1.Class1 cc);
}
}
Client
namespace Client
{
public class ClientControl : PageControl
{
public void Execute(){
using(var _service = new Services.Service){
var cc = new Library1.Class1();
_service.Method(cc);
}
}
}
}

Dynamically using same method in multiple web service references?

In c# .Net Framework 4.5 (Visual Studio Ultimate 2012, Version 11.0.61219.00 Update 5), I'm trying to define a service variable at runtime for which webservice to use. Each webservice (there are many) are all defined the same except for the endpoint url but the credentials will not cross over to authenticate. The below condition is menial to simplify the issue at hand. The following code gives the error: Cannot implicitly convert type WebService2.Service to WebService1.Service.
What I've tried: calling functions to return the proper service but the parameters or assignment all require a specific type.
var service = new WebService1.Service();
service = new WebService2.Service();
I want to be able to use the variable service in the rest of the program without having to duplicate code everywhere for using the many web service references.
It seems like what you are looking to do, you would need a common interface between the two services so you could inject whichever service you wish to use.
public class WebService1 : IWebService {...service code}
public class WebService2 : IWebService{...service code}
public interface IWebService{...service methods you will be calling}
Then you could do the following.
IWebService service = new WebService1.Service();
service = new WebService2.Service();
Assuming that the different services share the same method names, you can create an interface that all of the services implement by using the interface
IMyService.cs
interface IMyService
{
void MyMethod(string filter);
}
MyWebServiceImplementation.cs
public class MyWebServiceImplementation : IMyService
{
public void MyMethod(string filter);
}
MySecondWebServiceImplementation.cs
public class MySecondWebServiceImplementation : IMyService
{
public void MyMethod(string filter);
}
MyImplemetationCode.cs
//Use different services from same variable
IMyService service = new MyWebServiceImplementation();
service.MyMethod("filter");
service = new MySecondWebServiceImplementation();
service.MyMethod("another filter");

WCF service creating separate proxy class

I have a WCF service method that sends back a MembershipCreateStatus (System.Web.Security) to the calling method. When I look at the service definition it has recreated the enum as a type of MyProject.MyWebService.MembershipCreateStatus so it is essentially a completely different object.
Is there a way in which I can tell the service definition to use the System.Web.Security class instead, even though it is this within the WCF service?
You you can. You need to use the KnownTypeAttribute class to decorate the DataContract in your WCF Service to specify that the enum is of type System.Web.Security.MembershipCreateStatus I'm not aware of the details of your environment but in general unless you control both the WCF service and the consuming clients, I would carefully research the support requirements and the possibility of a future change to the enum causing backwards compatibility issues with clients that are consuming this enum. Also to consider is a scenario where a non .NET client could consume your WCF service. In that case you need to consider if using the System.Web.Security.MembershipCreateStatus enum is a good idea versus implementing your own statuses for Member creation. Here is another question on StackOverflow with a good discussion on this topic.
For example see the following code below
[ServiceContract]
public interface IMembershipService
{
[OperationContract]
CreateMemberResponse CreateMember(ApplicationUser userToCreate);
}
[DataContract]
[KnownType(typeof(System.Web.Security.MembershipCreateStatus))]
public class CreateMemberResponse
{
[DataMember]
public MembershipCreateStatus Status { get; set; }
}
[DataContract]
public class ApplicationUser
{
public bool ReturnSuccess { get; set; }
public ApplicationUser()
{
ReturnSuccess = true;
}
}
You can write a test against this service as follows and this test will succeed.
[TestClass]
public class MembershipStatusInvocationTests
{
[TestMethod]
public void CreateMemberShouldReturnMembershipCreateStatusEnum()
{
var client = new MembershipServiceClient();
var response = client.CreateMember(new ApplicationUser {ReturnSuccess = true});
Assert.IsInstanceOfType(response.Status, typeof(System.Web.Security.MembershipCreateStatus));
}
}
For more information on the KnownTypeAttribute class see here

What should I pass to duplex WCF client instance context

Here is a generated proxy for my duplex WCF service:
public partial class MyWcfServiceClient : System.ServiceModel.DuplexClientBase<Ifa.WcfClients.ServiceReference1.IMyWcfService>, Ifa.WcfClients.ServiceReference1.IMyWcfService {
public MyWcfServiceClient(System.ServiceModel.InstanceContext callbackInstance) :
base(callbackInstance) {
}
.
.
.
}
I want to inherit from this class and build a new class like this:
public class WcfClientBase : MyWcfServiceClient
{
public WcfClientBase() : base(???)
{
}
somemethod1(){....}
somemethod2(){....}
}
My problem is that the base class needs an argument of InstanceContext. What should I pass as this argument?
It's a duplex setup right? Meaning the server communicates results back via callbacks.
So the client needs to specify the class which has these callback methods - which will get invoked on replies from server.
You need to write a class implementing the callback interface (it'll be part of your service contract) and then pass an object of this class to the InstanceContext.

Categories