How to call a web service using XDocument?

Suppose I have an asmx web service at the following address: http: //localhost/BudgetWeb/Service.asmx

This web service has a web method with the following signature:

string GetValue(string key)

This GetValue method returns the following line:

<?xml version=\"1.0\" encoding=\"utf-8\" ?><value>250.00</value>

What if I would like to do this:

XDocument doc = XDocument.Load("http://localhost/BudgetWeb/Service.asmx?op=GetValue&key=key1")

This does not work, and I am sure that XDocument.Load does not actually call the web method on the server. I think he expects uri to point to a file that he can download. To call the web method, I think I should have a proxy class and it would have to use it to call string GetValue(string key), and then I could use that value returned from the web proxy class to go to the XDocument.Load method .

, , XDocument.Load - ?

+3
2

:

XDocument doc = XDocument.Load(
        "http://localhost/BudgetWeb/Service.asmx/GetValue?key=key1");

: : URI:

http://localhost/BudgetWeb/Service.asmx?op=GetValue&key=key1

http://localhost/BudgetWeb/Service.asmx/GetValue?key=key1

:

string uri = "http://www.webservicex.net/stockquote.asmx/GetQuote?symbol=MSFT";
XDocument doc1 = XDocument.Load(uri);
Console.WriteLine(doc1.Root.Value);  // <StockQuotes><Stock><Symbol>MSFT...
+5

, . web.config - :

<webServices>
    <protocols>
        <add name="HttpGet"/>
        <add name="HttpPost"/>
    </protocols>
</webServices>

, , , .

+3

Source: https://habr.com/ru/post/1725567/


All Articles