I have a problem... I explored whole internet and I don't know what I'm doing wrong.
Problem: WCF web service, .Net Framework 3.5, 2 different type of clients (Handheld device and usual computer)
What I'm trying to do is to create 2 diferent endpoints, one with basicBinding (For SOAP request) and other with wsBinding (for usual computers)
So I go thru web.config and I created 2 different bindings, related with 2 different endpoints:
<bindings>
<basicHttpBinding>
<binding name="BasicBinding" openTimeout="00:10:00" receiveTimeout="23:59:00"
sendTimeout="23:59:00" messageEncoding="Text" />
</basicHttpBinding>
<wsHttpBinding>
<binding name="DefaultBinding" openTimeout="00:10:00" receiveTimeout="23:59:59"
sendTimeout="23:59:59">
<reliableSession inactivityTimeout="01:00:00" />
<security mode="None">
<transport clientCredentialType="None" />
<message clientCredentialType="None" />
</security>
</binding>
</wsHttpBinding>
</bindings>
<services>
<service behaviorConfiguration="qtswsdl.QTS_ServiceBehavior"
name="qtswsdl.QTS_Service">
<endpoint address="http://host.com/service.svc/ForHh"
binding="basicHttpBinding" bindingConfiguration="BasicBinding"
name="handHeldEndPoint" contract="qtswsdl.QTSPort" />
<endpoint address="http://host.com/service.svc/ForCp"
binding="wsHttpBinding" bindingConfiguration="DefaultBinding"
name="coProcessorEndPoint" contract="qtswsdl.QTSPort" />
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="qtswsdl.QTS_ServiceBehavior">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="true" />
<dataContractSerializer maxItemsInObjectGraph="2147483647" />
<serviceThrottling maxConcurrentCalls="2147483647"maxConcurrentSessions="2147483647"
maxConcurrentInstances="2147483647" />
</behavior>
</serviceBehaviors>
</behaviors>
So when I try to send SOAP messages to "http://host.com/service.svc/ForHh" Im getting a "HTTP 400 - Bad Request" (the /ForCp is also not working)
I tried with custom clients, with WcfTestClient.exe and I was not able to fin what is happening
Any tip or suggestion?
Thanks for your time
EDIT:
After enable Svc trace I got a couple of exceptions:
<Message>The message with Action 'http://Host.com/Service.svc/ForHh' cannot be processed at the receiver, due to a ContractFilter mismatch at the EndpointDispatcher. This may be because of either a contract mismatch (mismatched Actions between sender and receiver) or a binding/security mismatch between the sender and the receiver. Check that sender and receiver have the same contract and the same binding (including security requirements, e.g. Message, Transport, None).</Message>
Funny thing is that I'm sending the SOAP request programatically. It's my understanding that if I'm sending SOAP request programatically i don't need to define any contract because it is being send using SOAP 1.1 by default.
Code that sends the request is the following code:
private string SendRequestAndGetAnswerFromWebService(string methodName, string requestXml){
StringBuilder soapRequest = new StringBuilder("<soap:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"");
soapRequest.Append(" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" ");
soapRequest.Append("xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\"><soap:Body>");
soapRequest.Append(requestXml);//Body
soapRequest.Append("</soap:Body></soap:Envelope>");
WebRequest webRequest = WebRequest.Create(@"http://Host.com/Service.svc/" + methodName);
HttpWebRequest httpRequest = (HttpWebRequest)webRequest;
httpRequest.Method = "POST";
httpRequest.ContentType = "text/xml; charset=ascii";
httpRequest.Headers.Add("SOAPAction: " + @"http://Host.com/Service.svc/Service.svc/" + methodName);
httpRequest.ProtocolVersion = HttpVersion.Version11;
httpRequest.Credentials = CredentialCache.DefaultCredentials;
httpRequest.Timeout = 7000;
httpRequest.ContentLength = System.Text.Encoding.ASCII.GetByteCount(soapRequest.ToString());
Stream requestStream = httpRequest.GetRequestStream();
//Create Stream and send Request
StreamWriter streamWriter = new StreamWriter(requestStream, Encoding.ASCII);
streamWriter.Write(soapRequest.ToString());
//Send the request
streamWriter.Close();
//Get the Response
HttpWebResponse wr = (HttpWebResponse)httpRequest.GetResponse();
StreamReader srd = new StreamReader(wr.GetResponseStream());
string resulXmlFromWebService = srd.ReadToEnd();
return resulXmlFromWebService;
}
Maybe my assumption about contract and soap messages sent programatically are wrong...