2

Is there anyway I can invoke a WCF service without adding service reference or even having a proxy at all.

VJAI
  • 32,167
  • 23
  • 102
  • 164

3 Answers3

0

Brief answer: No

WCF is based on the very fundamental principle of having a proxy between the client and the service being called. You cannot "get around" this.

You have your choice of creating a proxy using Add Service Reference, or creating it in code - but you need a proxy - no way around that.

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
0

If you asks this, it means you might be interested in Dynamic Proxy Generation.

Please have a look at this article. Several points might need to be discussed, but the idea is in here.

This question might also help.

Community
  • 1
  • 1
Larry
  • 17,605
  • 9
  • 77
  • 106
0

You can invoke the service using a HttpWebRequest. Example below:-

private static XDocument CallSoapServiceInternal(string uri, string soapAction, string contentType, XDocument reqXml)
{
    var req = (HttpWebRequest)WebRequest.Create(uri);
    req.ContentType = contentType;
    req.Method = "POST";
    req.Headers.Add("SOAPAction", soapAction);
    req.Credentials = CredentialCache.DefaultCredentials;
    req.Timeout = 20000;
    //req.Timeout = System.Threading.Timeout.Infinite;

    using (var reqStream = req.GetRequestStream())
    {
        reqXml.Save(reqStream);
    }

    string respStr;

    try
    {
        using (var resp = (HttpWebResponse)req.GetResponse())
        {
            using (var rdr = new StreamReader(resp.GetResponseStream()))
            {
                respStr = rdr.ReadToEnd();
            }
        }
    }
    catch (Exception ex)
    {
        throw new Exception("Error getting service response.", ex);
    }

    Console.WriteLine(respStr);
    Assert.IsTrue(respStr.Length > 0, "Nothing returned");

    var respXml = XDocument.Parse(respStr);
    return respXml;
}
Nick Ryan
  • 2,662
  • 1
  • 17
  • 24
  • Does System.ServiceModel has classes to frame/send Soap Messages quite easily? – VJAI Jul 07 '11 at 11:34
  • Found this.. Send and Receive a SOAP Message By Using the SoapSender and SoapReceiver Classes http://msdn.microsoft.com/en-us/library/ms824662.aspx – VJAI Jul 12 '11 at 06:51