2

I have one solution in which I have 2 projects with:

  1. ASP.NET MVC Application to consume wcf services.
  2. 5 WCF services.

I have added one web service reference in the project 1. Now, I need to use different services based on the user e.g.

User Type 1: Only allow to consume Service 1.
User Type 2: Only allow to consume Service 2. etc.

I have Service URL's like localhost:6227/Service1.svc, localhost:6227/Service2.svc etc.

I have stored all service URL's in the db and I need to change URL for each user type to consume his allowed service only without adding more end points and only change URL from the backend based on user type. I need relevant link or code to solve this problem.

Edit

In Web Config I have added just this endpoint in the mvc application and I don't want to use web config to change address in here but I want to change address in the code for each user type while application is running.

<client>
      <endpoint address="http://localhost:6227/Service1.svc"
        binding="customBinding" bindingConfiguration="CustomBinding_IService1"
        contract="Service1.IService1" name="CustomBinding_IService1" />
    </client>
3

3 Answers 3

3

if i completely realize your question you need dynamic soap service calling. maybe something like this:

private void CallService()
{
    var myBinding = new BasicHttpBinding();
    myBinding.Security.Mode = BasicHttpSecurityMode.None;
    var myEndpointAddress = new EndpointAddress("your url depend on user type");
    var client = new ClientService1(myBinding, myEndpointAddress);
    var outpiut = client.someCall();
    client.close();
}
Sign up to request clarification or add additional context in comments.

Comments

0

Not sure if I understand you correctly but you could use below snippet, if it suits.

//assuming you get string URL. Change type as per need.
string reqdURL = GetServiceURL(typeof(userObject));

private string GetServiceURL(Type userType)
{
    if (userType == typeof(UserType1))
    {
        // currently hardcoded but you can replace your own fetch logic
        return "localhost:6227/Service1.svc";
    }
    if (userType == typeof(UserType2))
    {
        return "localhost:6227/Service2.svc";
    }
    //and so on
}

4 Comments

and how to use this reqdURL to deliver user only data from this service?
What is the problem you're trying to solve? Change URL dynamically or change the data that comes out of the service (and not the URL)?
I need to change the URL to allowed him to consume only his service.
Can you edit your question and provide an example of what it is exactly you're looking for? To me it seemed like you're looking for switching services, which above snippet does.
0

You can modify directly your EndPoint Address doing this:

ClientService1 ws = new ClientService1();
ws.Endpoint.Address = new EndpointAddress("Your new URL svc service");

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.