wget is a utility that should be in any web developer's tool box. If you're on linux this is a no-brainer (apt-get install wget), but you can also get this on windows. Heard of gnuwin32? You can use the download manager getgnuwin32 to get the entire package, or you can just download what's needed for wget. If not, make sure you download both the binaries and the dependencies zip file.
Using BasicHttpBinding (SOAP 1.1)
As an example, let's say you've created the following service[ServiceContract(Namespace = "http://tepmuri.org/myservice/")] public interface IService { [OperationContract] string Hello(string name); } public class Service : IService { public string Hello(string name) { return "Hello " + name; } }It's a simple Hello World service that takes a string for input and returns one as output. Let's also make the following assumptions:
- You're serving it at http://localhost/Service.svc
- You're using BasicHttpBinding
For the example service given above under the given circumstances (BasicHttpBinding), this is a valid SOAP 1.1 XML input:
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/"> <s:Body> <Hello xmlns="http://tepmuri.org/myservice/"> <name>world</name> </Hello> </s:Body> </s:Envelope>
Let's say you've saved this text into a file called hello.xml. To perform the call, execute the following wget command from the command line:
There's really not much to it We need four parameteres
- The input XML as a filename
- A HTTP header specifying the content-type
- A HTTP header specifying the SOAP Action name with full namespace
- URL of the service
If you've done everything correctly, you should get a 200 return code and the SOAP XML Body in the HTTP Body.
Using WsHttpBinding (SOAP 1.2)
Now if you're using WsHttpBinding, you need a slightly more complex input XML. Use this as a starting point:
<s:Envelope xmlns:s="http://www.w3.org/2003/05/soap-envelope" xmlns:a="http://www.w3.org/2005/08/addressing"> <s:Header> <a:Action s:mustUnderstand="1" >http://tepmuri.org/myservice/IService/Hello</a:Action> <a:MessageID>urn:uuid:149c449f-0593-416b-ae1f-b73308a6e2d2</a:MessageID> <a:ReplyTo> <a:Address>http://www.w3.org/2005/08/addressing/anonymous</a:Address> </a:ReplyTo> <a:To s:mustUnderstand="1">http://localhost/Service.svc</a:To> </s:Header> <s:Body> <Hello xmlns="http://tepmuri.org/myservice/"> <name>world</name> </Hello> </s:Body> </s:Envelope>In addition you'll need to change the content-type HTTP header of the wget command to the following:
-header "Content-Type: application/soap+xml; charset=utf-8"
A couple of more wget paramteres that might come handy:
- HTTPS: If you're exposing the service with HTTPS security and you have a temporary SSL Certificate, use --no-check-certificate
- Proxy: Wget takes proxy credentials on the command line, but the URL is specified by an environment variable named http_proxy. Running SET http_proxy=localhost:8888 on the command line before wget will redirect all commands through a proxy (like i.e. fiddler)
No comments:
Post a Comment