[Mono-dev] Http Content Type Header Problem
monoUser
cancomert at gmail.com
Tue Nov 22 11:23:17 EST 2011
Hello,
I'm trying to implement a WCF Web service in C#. I run the service under
Mono in a Linux system.
I'm creating a SelfHost host for my test cases.
I can test the service on both mono and .Net runtime with my own client
application written in C# and shares contract library without any problem.
But this service should be able to used by other clients also. So that I'm
testing the service by using SoapUi tool.
The problem is the when I send the following request I get an error about
the content type
but the content type itself seems exactly same except one space between
text/xml;(there is no space in soap ui request)charset=utf-8
POST http://soda5-update-test:100/Calculator/Service HTTP/1.1
Content-Type: text/xml;charset=utf-8 <==Mono Server Complains about
this line
SOAPAction: "http://tempuri.org/ICalculator/Add"
User-Agent: Jakarta Commons-HttpClient/3.1
Host: soda5-update-test:100
Expect: 100-continue
Content-Length: 338
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:tem="http://tempuri.org/">
<soapenv:Header/>
<soapenv:Body>
<tem:Add>
<tem:n1>5</tem:n1>
<tem:n2>10</tem:n2>
</tem:Add>
</soapenv:Body>
</soapenv:Envelope>
This is the response I get from the server.
HTTP/1.1 415 Expected content-type 'text/xml; charset=utf-8' but got
'text/xml;charset=utf-8'
Server: Mono-HTTPAPI/1.0
Date: Tue, 22 Nov 2011 15:51:57 GMT
Content-Length: 0
Keep-Alive: timeout=15,max=99
My mono --version output is
Mono JIT compiler version 2.10.5 (/ Fri Sep 2 12:26:51 CEST 2011)
Copyright (C) 2002-2011 Novell, Inc, Xamarin, Inc and Contributors.
www.mono-project.com
TLS: __thread
SIGSEGV: altstack
Notifications: epoll
Architecture: amd64
Disabled: none
Misc: softdebug
LLVM: supported, not enabled.
GC: Included Boehm (with typed GC and Parallel Mark)
The same service is working for the following response and request pair
properly.
These are the successful execution traffic examples.
POST /Calculator/Service HTTP/1.1
Content-Type: text/xml; charset=utf-8
SOAPAction: "http://tempuri.org/ICalculator/Add"
Host: soda5-update-test:100
Content-Length: 159
Expect: 100-continue
Accept-Encoding: gzip, deflate
Connection: Keep-Alive
HTTP/1.1 100 Continue
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/"><s:Body><Add
xmlns="http://tempuri.org/"><n1>100</n1><n2>15.99</n2></Add></s:Body></s:Envelope>
HTTP/1.1 200 OK
Content-Type: text/xml; charset=utf-8
Server: Mono-HTTPAPI/1.0
Date: Tue, 22 Nov 2011 16:03:46 GMT
Content-Length: 219
Keep-Alive: timeout=15,max=100
<?xml version="1.0" encoding="utf-8"?><s:Envelope
xmlns:s="http://schemas.xmlsoap.org/soap/envelope/"><s:Body><AddResponse
xmlns="http://tempuri.org/"><AddResult>115.99</AddResult></AddResponse></s:Body></s:Envelope>
I'm also adding the server side testing code below
namespace WCFMonoTestServer
{
class Program
{
static void Main(string[] args)
{
// Step 1 of the address configuration procedure: Create a URI
to serve as the base address.
Uri baseAddress = new Uri(string.Format(
"http://{0}:100/Calculator/Service",
Environment.MachineName));
Console.WriteLine("Service starts on
"+baseAddress.AbsoluteUri);
// Step 2 of the hosting procedure: Create ServiceHost
ServiceHost selfHost = new
ServiceHost(typeof(WCFMonoCalculatorService), baseAddress);
try
{
ServiceMetadataBehavior metadataBehavior =
new ServiceMetadataBehavior();
metadataBehavior.HttpGetEnabled = true;
metadataBehavior.HttpGetUrl = new Uri(string.Format(
"http://{0}:100/Calculator/Service/CalculatorService.svc",
Environment.MachineName));
selfHost.Description.Behaviors.Add(metadataBehavior);
ServiceDebugBehavior debugBehavior = ( from behavior in
selfHost.Description.Behaviors
where behavior is
ServiceDebugBehavior
select behavior as
ServiceDebugBehavior).First();
selfHost.Description.Behaviors.Remove(debugBehavior);
debugBehavior.IncludeExceptionDetailInFaults=true;
selfHost.Description.Behaviors.Add(debugBehavior);
CustomBinding customBinding = new CustomBinding();
customBinding.Elements.Add(new
TextMessageEncodingBindingElement()
{
WriteEncoding = System.Text.UTF8Encoding.UTF8,
MessageVersion =
MessageVersion.CreateVersion(EnvelopeVersion.Soap11,
AddressingVersion.None),
});
customBinding.Elements.Add(new
HttpTransportBindingElement());
//BasicHttpBinding binding = new BasicHttpBinding();
// Step 3 of the hosting procedure: Add a service endpoint.
selfHost.AddServiceEndpoint(typeof(ICalculator),
// new
SodaCustomBinding(SodaCustomTrasnportMode.HTTPTransport,SodaCustomEncodingMode.MtomMessage)
customBinding //binding
, baseAddress);
// Step 4 of the hosting procedure: Enable metadata
exchange.
//ServiceMetadataBehavior smb = new
ServiceMetadataBehavior();
//smb.HttpGetEnabled = true;
//selfHost.Description.Behaviors.Add(smb);
// Step 5 of the hosting procedure: Start (and then stop)
the service.
selfHost.Open();
selfHost.Faulted += new EventHandler(selfHost_Faulted);
selfHost.UnknownMessageReceived += new
EventHandler<UnknownMessageReceivedEventArgs>(selfHost_UnknownMessageReceived);
Console.WriteLine("The service is ready.");
Console.WriteLine("Press <ENTER> to terminate service.");
Console.WriteLine();
Console.ReadKey();
// Close the ServiceHostBase to shutdown the service.
selfHost.Close();
}
catch (CommunicationException ce)
{
Console.WriteLine("An exception occurred: {0}", ce.Message);
selfHost.Abort();
Console.ReadKey();
}
catch (Exception ex) {
Console.WriteLine("An exception occurred: {0}", ex.Message);
Console.WriteLine(ex.StackTrace);
selfHost.Abort();
Console.ReadKey();
}
}
static void selfHost_Faulted(object sender, EventArgs e)
{
Console.WriteLine(e.ToString());
}
static void selfHost_UnknownMessageReceived(object sender,
UnknownMessageReceivedEventArgs e)
{
Console.WriteLine(e.Message);
}
}
}
What can I do to be able to handle the other client such as soapUi tool
requests?
Thanks in advice.
Best Regards
--
View this message in context: http://mono.1490590.n4.nabble.com/Http-Content-Type-Header-Problem-tp4096321p4096321.html
Sent from the Mono - Dev mailing list archive at Nabble.com.
More information about the Mono-devel-list
mailing list