0

I have a Winform Application that I can use TCP client to connect to WCF service, but I don't know how to call its function.

I've been looking at sending SOAP-XML request to WCF service through TCP client, but always get "Bad Request" respond.

Here's my request:

POST /MyService.svc HTTP/1.1
Host: MyHost.com
Content-Type: text/xml; charset=utf-8
Content-Length: 700
SOAPAction: "http://MyHost.com/MyService/MyFunction"
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi=http://www.w3.org/2001/XMLSchema-instance 
xmlns:xsd=http://www.w3.org/2001/XMLSchema 
xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Header>
<Action soap:must Understand="1"
xmlns="http://schemas.microsoft.com/ws/2005/05/addressing/none">
http://MyHost.com/MyService/MyFunction
</Action>
</soap:Header>
<soap:Body>
<MyFunction xmlns="http://MyHost.com/">
</MyFunction>
</soap:Body>

And here's response:

HTTP/1.1 400 Bad Request
Content-Type: text/html; charset=us-ascii
Server: Microsoft-HTTPAPI/2.0
Date: Tue, 07 Jul 2015 01:32:13 GMT
Connection: close
Content-Length: 339

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN""http://www.w3.org/TR/html4/strict.dtd">
<HTML><HEAD><TITLE>Bad Request</TITLE>
<META HTTP-EQUIV="Content-Type" Content="text/html; charset=us-ascii"></HEAD>
<BODY><h2>Bad Request - Invalid Header</h2>
<hr><p>HTTP Error 400. The request has an invalid header name.</p>
</BODY></HTML>
  • Your XML is wrong; you must have quotes around attributes and must not put quote around header values. – Dour High Arch Jul 07 '15 at 02:30
  • I have no idea about this. Can you show me where I should fix. – Nguyễn Trung Hiếu Jul 07 '15 at 02:42
  • None of those URIs make sense; are you really connecting to a service at http://tempuri.org/MyService/MyFunction? `tempuri.org` is not a real URI, it is a metavariable used in examples to show you where to put your service URI. You have to find out the URL and path of the real service you want and use that. – Dour High Arch Jul 07 '15 at 15:53
  • I get the SOAPAction in MyService.svc?wsdl. I've tried replace `tempuri.org` to `MyHost.com` too but still the same response – Nguyễn Trung Hiếu Jul 08 '15 at 04:08

0 Answers0