Wysyłanie raw SOAP XML bezpośrednio do usługi WCF z C#
Mam odniesienie do usługi WCF:
http://.../Service.svc(?WSDL)
I mam plik XML zawierający zgodną kopertę SOAP
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Body>
<MyXML>
...
Teraz chciałbym wysłać te surowe dane bezpośrednio do serwisu (i otrzymać odpowiedź) za pomocą kodu C# bez użycia referencji usługi Visual Studio.
Czy to możliwe, a jeśli tak, to jak? 15
3 answers
Możesz użyć UploadString . Musisz odpowiednio ustawić Nagłówki Content-Type
i SOAPAction
:
class Program
{
static void Main(string[] args)
{
using (var client = new WebClient())
{
// read the raw SOAP request message from a file
var data = File.ReadAllText("request.xml");
// the Content-Type needs to be set to XML
client.Headers.Add("Content-Type", "text/xml;charset=utf-8");
// The SOAPAction header indicates which method you would like to invoke
// and could be seen in the WSDL: <soap:operation soapAction="..." /> element
client.Headers.Add("SOAPAction", "\"http://www.example.com/services/ISomeOperationContract/GetContract\"");
var response = client.UploadString("http://example.com/service.svc", data);
Console.WriteLine(response);
}
}
}
30
Author: Darin Dimitrov,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2009-11-13 10:34:58
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2009-11-13 10:34:58
Chcę tylko skomentować, że odpowiedź Darina zadziałała dla mnie, poza tym, że musiałem wyjąć dodatkowe cudzysłowy wokół wartości nagłówka SOAPAction (oczywiście podmienić swoje uri):
client.Headers.Add("SOAPAction", "http://www.example.com/services/ISomeOperationContract/GetContract");
5
Author: user984672,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2011-11-25 00:45:35
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2011-11-25 00:45:35
Możesz spróbować użyć klasy webclient i opublikować swój xml do usługi.
0
Author: Shiraz Bhaiji,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2009-11-13 10:11:10
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2009-11-13 10:11:10