-1

I have a web api with controller methods that use rest http(post/get calls). Clients consume this API with normal httpclient calls and I pass an http response back.

My use case is I have a legacy method that needs to make a call to another server. This method currently uses WCF and contract binding but I don't want to use WCF in this API project.

Is there a way that I can still call these methods using just WEB API or do I have to mix architectures (Web api with WCF)?

Here is the normal method call

  1. First I initialize the proxy

    var proxy = GetAccountProxy();
    
     public static AcountClient GetAccountProxy()
     {
       var client = new AccountClient();
       client.ClientCredentials.ClientCertificate.SetCertificate(...);
      return client;
     }
    
  2. I connect to a method on the other server through the proxy

    var accountInfo = proxy.GetAccountInfo(xmlAccount);
    

    public string AccountInfo(string sXml){ AccountLookup val = new AccountLookup(); val.Body = new AccountLookupRequestBody(); val.Body.XML = sXML; AccountLookupResponse retVal = ((AccountLookupResponse)(this)).AccountLookup(val); return retVal; }

In my webconfig the endpoints look like this

<endpoint address="https://www.mylookup.com/AccountLookupWS/AccountLookupWS.svc/wshttp" binding="wsHttpBinding" bindingConfiguration="WSHttpBinding_IAccountLookupWS" contract="AccountLookupWS.IAccountLookupWS" name="WSHttpBinding_IAccountLookupWS1" />

So my question is can I just call this endpoint using a normal rest httpclient call and have the same result?

 Uri baseUrl = new Uri("https://www.mylookup.com/AccountLookupWS/AccountLookupWS.svc/wshttp");
            IRestClient client = new RestClient(baseUrl);
            IRestRequest request = new RestRequest("GetAccountInfo", Method.GET) 
            request.AddParameter("XmlAccount", sXml);

            IRestResponse<dynamic> response = client.Execute<dynamic>(request);

            if (response.IsSuccessful)
            {
                response.Data.Write();
            }
            else
            {
                Console.WriteLine(response.ErrorMessage);
            }

            Console.WriteLine();

1 Answer 1

1

The short answer is no. The WCF client wraps a SOAP(XML)-based endpoint and the RestClient/Request expects a JSON-based contract (among other things).

Not sure if you've seen this, but there are a few ideas here: https://stackoverflow.com/a/33474284/49720

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.