c#


C# client of Axis2 web service complains “but expected 'text/xml'”


My C# sample client ASP.NET program successfully runs a call in my Axis2 server but the client does not seem to like the response.
I get:
Client found response content type of 'multipart/related;
boundary=MIMEBoundaryurn_uuid_38D413ACFC9D56F28E1258666845186;
type="application/xop+xml";
start="<0.urn:uuid:38D413ACFC9D56F28E1258666845187#apache.org>";
start-info="text/xml"', but expected 'text/xml'.
According to the MSDN forums I supposedly must enable MTOM but they only explain this for the now-obsolete WSE 3 package.
In the WCF space, for an ASP.NET program in C#, how to I enable MTOM or otherwise fix this response content-type mismatch? Actually, I'll need MTOM next.
For one thing, you have to enable MTOM in Axis2 as well. Find your axis2.xml configuration file (WEB-INF/conf/axis2.xml) and adjust the following setting:
<axisconfig name="AxisJava2.0">
<!-- ================================================= -->
<!-- Parameters -->
<!-- ================================================= -->
.../...
<parameter name="enableMTOM">true</parameter>
.../...
</axisconfig>
Wihthout this, Axis will not handle MTOM at all and the client will be very confused.
Switching to XOP/MTOM means switching to multipart-mime as well, and your client actually got a multipart-mime answer, so I suppose the Axis2 setting is OK afterall :) The fact that your client is expecting plain XML (i.e. a nice SOAP response) indicates that you have not set up MTOM on the client side.
Supposing you are using a BasicHttpBinding, enabling MTOM in WCF could be done as:
<configuration>
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="MySOAP11Binding"
...
messageEncoding="Mtom"
...
>
.../...
</binding>
</basicHttpBinding>
.../...
You will most certainly have to tweak the maxBufferSize, maxBufferPoolSize and maxReceivedMessageSize attributes of the binding element as well.
Alternatively, you can set this up in code:
private ServiceProxy<MyPortTypeClient, MyPortType> getClient()
{
EndpointAddress endpoint = new EndpointAddress("http://server/axis/services/My");
// The binding
BasicHttpBinding binding = new BasicHttpBinding();
binding.OpenTimeout = minutes(1);
binding.CloseTimeout = minutes(1);
binding.SendTimeout = minutes(10);
binding.ReceiveTimeout = minutes(10);
binding.MaxBufferPoolSize = Int32.MaxValue;
binding.MaxReceivedMessageSize = Int32.MaxValue;
binding.ReaderQuotas = System.Xml.XmlDictionaryReaderQuotas.Max;
binding.MessageEncoding = WSMessageEncoding.Mtom;
if (binding is BasicHttpBinding)
{
// Also setting to streamed mode
((BasicHttpBinding)(Object)binding).TransferMode = TransferMode.Streamed;
}
binding.AllowCookies = true;
// MyPortType and MyPortTypeClient are implemented in Reference.cs, i.e. this
// code is generated by svcutil or Visual Studio from your WSDL.
MyPortTypeClient _proxy = new MyPortTypeClient(binding, endpoint);
ServiceProxy<MyPortTypeClient, MyPortType> proxy = new ServiceProxy<MyPortTypeClient, MyPortType>(_proxy);
if (!String.IsNullOrEmpty(wsUsername) && !String.IsNullOrEmpty(wsPassword))
{
UserNamePasswordClientCredential credentials = _proxy.ClientCredentials.UserName;
credentials.UserName = wsUsername;
credentials.Password = wsPassword;
}
return proxy;
}
The nice thing about doing this in code, is that you will get help form your IDE regarding what parameters can be set for any specific binding. If you switch from BasicHttpBinding to, say, WSHttpBinding you will get compilation errors for those parameters that does not match the new binding.
This in normally that the client expects an xml response, but gets an error message from the server that it cannot parse.
Either log the reponse or use a network sniffer (fiddler) to check what you are getting back.

Related Links

How can I calculate business date and time from date assigned in SQL
Xamarin Form(PCL) IOS Firebase Push Message not working
Is there any way to revert single file using libgit2sharp?
How to consume WCF POST with List<Object> as parameters
GoogleConnect.Fetch throws Unable to cast object error
Sum method return long value
Why doesn't my code access the control inside item template?
Trying to add rows to a Table results in multiple tables
Getting error “Unable to load DLL 'SQLite.Interop.dll'” despite it being in the bin folder
Append data in a json file in C#
C# Foreach loop through json-object, get key [duplicate]
Excel Connectionstring DriverId
BotConnector dynamic field not working: even when a user clicks on one of the buttons in the prompt, the Bot fails to recognize the response
WCF Collection returns empty
Extending interface with new model
How to programmatically get Azure Service Bus Relay details (C#)?

Categories

HOME
reactjs
itunesconnect
domain-driven-design
blob
symfony-sonata
subprocess
olap
jcodemodel
kairosdb
osrm
resharper
chef-recipe
hdf5
lambda-calculus
exchange-transport-agents
taxonomy
ringcentral
windows-phone
ofbiz
cucumberjs
summernote
multipart
devexpress-mvc
suitescript
android-cursorloader
formtastic
dynamic-memory-allocation
delphi-2010
boost-log
foxpro
slim-lang
scene7
favorites
rtos
n1ql
mootools
http-proxy
headphones
sdl-2
gstreamer-1.0
abide
python-venv
grails-2.0
logan-square
anonymous-function
automapper-4
easyquery
stream-socket-client
emacs24
visio-2010
gige-sdk
aws-rds
webmatrix
node.js-client
rmq
recursive-query
alarmmanager
stripes
alfred
git-push
tinybox2
csc
bytearray
sbt-proguard
nd4j
nslocalizedstring
lytro
textblob
nmock
p4python
tokudb
vspackage
android-networking
mathics
caption
mind-manager
nsnotificationcenter
windows-search
disabled-control
hotlinking
opencobol
elixir-framework
internet-radio
windows-phone-store
azure-pack
wpa
dd4t
coinbase-php
netbiscuits
nserror
win-prolog
xpolog
windows-xp-embedded
funambol
symfony-1.2
lgpl
viewdata
scala-designer
authkit
ffdshow
weak-typing

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App