Professional Web Applications Themes

Client found response content type of '', but expected 'text/xml' - ASP.NET Web Services

I am trying to run a web service project with multiple web services. The problem is that this works sometimes, and sometimes it does not work. I've worked on this problem for nearly 3 days now, and still no solution :( The exception is An unhandled exception of type 'System.InvalidOperationException' occurred in system.web.services.dl Additional information: Client found response content type of '', but expected 'text/xml' When I try to run the web service from the project on the Internet Explorer test page, it runs without any problem, but then if I run it from another application using a web reference, ...

Sponsored Links
  1. #1

    Default Client found response content type of '', but expected 'text/xml'

    I am trying to run a web service project with multiple web services. The problem is that this works sometimes, and sometimes it does not work. I've worked on this problem for nearly 3 days now, and still no solution :( The exception is

    An unhandled exception of type 'System.InvalidOperationException' occurred in system.web.services.dl
    Additional information: Client found response content type of '', but expected 'text/xml'

    When I try to run the web service from the project on the Internet Explorer test page, it runs without any problem, but then if I run it from another application using a web reference, it does not work

    I tried creating the project all over again by copying the code for the web services exactly from the previous code, it worked initially, but then after a few minutes it started giving the same error agin

    I suspected that it is the namespace of the services which is probably giving the problem, so I commented the WebService attribute for all web service classes, and then tried. It worked! Just to make sure that this was the problem, I reverted back, and it didnt work! Really satisfied that I solved the problem, I commented back the attributes and tested it again. IT DID NOT WORK

    Now I am totally stuck not knowing what to do. Can anyone please help me

    Thanks a lot in advanc
    Vis


    Sponsored Links
    Vish Ramachandran Guest

  2. #2

    Default Re: Client found response content type of '', but expected 'text/xml'


    Hi,

    did you update your web reference after changeing the webservice namespace?

    Check the file reference.cs if the correct namespace is in there. If it's
    not in there leave the file open in the editor and then refresh your web
    reference. There seems to be a bug in VS.Net when updating a web reference,
    but leaving the reference.cs file open in the editor will cause the editor
    to reload the file.

    best regards
    Martin

    "Vish Ramachandran" <vish r at a s u period ed u> schrieb im Newsbeitrag
    news:29ECA9C7-72F3-4D87-B2C4-EACD0B115152microsoft.com...
    > I am trying to run a web service project with multiple web services. The
    problem is that this works sometimes, and sometimes it does not work. I've
    worked on this problem for nearly 3 days now, and still no solution :( The
    exception is:
    >
    > An unhandled exception of type 'System.InvalidOperationException' occurred
    in system.web.services.dll
    > Additional information: Client found response content type of '', but
    expected 'text/xml'.
    >
    > When I try to run the web service from the project on the Internet
    Explorer test page, it runs without any problem, but then if I run it from
    another application using a web reference, it does not work.
    >
    > I tried creating the project all over again by copying the code for the
    web services exactly from the previous code, it worked initially, but then
    after a few minutes it started giving the same error agin.
    >
    > I suspected that it is the namespace of the services which is probably
    giving the problem, so I commented the WebService attribute for all web
    service classes, and then tried. It worked! Just to make sure that this was
    the problem, I reverted back, and it didnt work! Really satisfied that I
    solved the problem, I commented back the attributes and tested it again. IT
    DID NOT WORK!
    >
    > Now I am totally stuck not knowing what to do. Can anyone please help me?
    >
    > Thanks a lot in advance
    > Vish
    >
    >

    Martin Boehm Guest

  3. #3

    Default Client found response content type of '', but expected 'text/xml'

    On day 3 of debugging this. I've implemented a simple soap extension
    to intercept the servers outgoing soap message stream and replace it
    with my own (code below).

    Everything seems to work in the code step through except the server
    side afterserialize stage is called twice (2 times!) but why? It
    should only fire once afaik. In the second fire, afterserialize writes
    an empty stream to the output stream, but I already wrote to the output
    stream correctly on the first fire! My client says, expectedly, the
    above error, the service returns nothing==empty stream.

    I've found many hits on the net, but no answers. Day 4 is coming.
    Argggh! The only post I found with an answer was this one:
    http://www.thescripts.com/forum/thread375954.html but I don't think it
    applies in my case as I rewound the stream correctly (or at least I
    think I did).

    I'm using vs 2005 and I'm running on XP pro. I'm using the embedded
    webserver in 2005 (cassini?)

    As I said, everything appears to work fine. On the server side It
    takes the input message, transforms it, and then writes it to the
    output stream. I checked the stream it copies to the output (in
    afterserialize on the first time it fires) and everything looks
    hunky-dory. However, the second time afterserialize fires everything
    is messed up and the streams are empty (appoutputstream and
    httpoutputstream).


    all code below here
    --*********************
    Here is the soap extension
    --**********************

    using System;
    using System.Web;
    using System.Web.Services;
    using System.IO;
    using System.Web.Services.Protocols;
    using System.Xml;

    public class XmlStreamSoapExtension :
    System.Web.Services.Protocols.SoapExtension
    {
    bool output = false;
    Stream httpOutputStream;
    Stream chainedOutputStream;
    Stream appOutputStream;

    public override Stream ChainStream(Stream stream)
    {
    Stream result = stream;
    if ((output))
    {
    httpOutputStream = stream;
    chainedOutputStream = new MemoryStream();
    result = chainedOutputStream;
    }
    else
    {
    output = true;
    }
    return result;
    }

    public override object GetInitializer(System.Type serviceType)
    {
    return null;
    }

    public override object
    GetInitializer(System.Web.Services.Protocols.Logic alMethodInfo
    methodInfo, System.Web.Services.Protocols.SoapExtensionAttribu te
    attribute)
    {
    return null;
    }

    public override void Initialize(object initializer)
    {
    }

    public override void ProcessMessage(SoapMessage message)
    {
    if (message.Stage == SoapMessageStage.AfterDeserialize)
    {
    HttpContext.Current.Request.InputStream.Position = 0;
    HttpContext.Current.Items["SoapInputStream"] =
    HttpContext.Current.Request.InputStream;
    appOutputStream = new MemoryStream();
    HttpContext.Current.Items["SoapOutputStream"] =
    appOutputStream;
    }
    else if (message.Stage == SoapMessageStage.AfterSerialize)
    {
    chainedOutputStream.Position = 0;
    XmlReader reader = new
    XmlTextReader(chainedOutputStream);
    reader.ReadStartElement("Envelope",
    "http://schemas.xmlsoap.org/soap/envelope/");
    reader.MoveToContent();
    if ((reader.LocalName == "Header"))
    {
    reader.Skip();
    }
    reader.ReadStartElement("Body",
    "http://schemas.xmlsoap.org/soap/envelope/");
    reader.MoveToContent();
    if ((reader.LocalName == "Fault" & reader.NamespaceURI
    == "http://schemas.xmlsoap.org/soap/envelope/"))
    {
    chainedOutputStream.Position = 0;
    CopyStream(chainedOutputStream, httpOutputStream);
    }
    else
    {
    appOutputStream.Flush();
    appOutputStream.Position = 0;
    CopyStream(appOutputStream, httpOutputStream);

    }
    appOutputStream.Close();
    }
    }

    private void CopyStream(Stream src, Stream dest)
    {
    StreamReader reader = new StreamReader(src);
    StreamWriter writer = new StreamWriter(dest);
    writer.Write(reader.ReadToEnd());
    writer.Flush();
    }

    public class SoapStreams
    {

    public static Stream InputMessage
    {
    get
    {
    return
    ((Stream)(HttpContext.Current.Items["SoapInputStream"]));
    }
    }

    public static Stream OutputMessage
    {
    get
    {
    return
    ((Stream)(HttpContext.Current.Items["SoapOutputStream"]));
    }
    }
    }
    [AttributeUsage(AttributeTargets.Method)]
    public class XmlStreamSoapExtensionAttribute :
    SoapExtensionAttribute
    {
    private int m_priority;
    public override Type ExtensionType
    {
    get{ return typeof(XmlStreamSoapExtension);}
    }

    public override int Priority
    {
    get {return m_priority;}
    set{m_priority = 1;}
    }
    }

    --*********************
    end of soap extension class
    --**********************

    --*********************
    --here is the asmx file --all it does is a simple transform of the
    input message
    --*********************

    using System;
    using System.Web;
    using System.Collections;
    using System.Web.Services;
    using System.Web.Services.Protocols;
    using System.Xml;
    using System.Xml.Xsl;
    using System.Xml.Serialization;
    [System.Web.Services.WebServiceBindingAttribute(Nam e = "Arithmetic",
    Namespace = "urn:msdn-microsoft-com:hows")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    public class arithmetic : WebService {

    private const string soapURI =
    "http://schemas.xmlsoap.org/soap/envelope/";
    private const string nsURI = "urn:msdn-microsoft-com:hows";

    [XmlStreamSoapExtension]
    [WebMethod]
    [SoapDoentMethod("urn:msdn-microsoft-com:hows/Add", Use =
    System.Web.Services.Description.SoapBindingUse.Lit eral, ParameterStyle
    = System.Web.Services.Protocols.SoapParameterStyle.B are)]
    [return: XmlElement("AddResponse", Namespace =
    "urn:msdn-microsoft-com:hows")]
    public /* AddResponse */ void Add(/* Add Add1 */)
    {
    //************
    //this will transform the input stream (in a reader) directly
    to output stream
    //************
    XslCompiledTransform docXsl = new XslCompiledTransform();
    XsltSettings xslset = new XsltSettings();
    xslset.EnableDoentFunction = true;
    string xslsource = "add.xslt";
    XmlUrlResolver resolver = new XmlUrlResolver();
    string pathxsl = HttpContext.Current.Server.MapPath(xslsource);
    docXsl.Load(new XmlTextReader(pathxsl), xslset, resolver);
    docXsl.Transform(xReader, new
    XmlTextWriter(SoapStreams.OutputMessage, System.Text.Encoding.UTF8));
    }
    public arithmetic () {
    //Uncomment the following line if using designed components
    //InitializeComponent();
    }

    }

    --***************************
    --end of the asmx file
    --****************************


    --**********************
    --here is the xml message sent to the service by the client w/soap
    action of
    --"urn:msdn-microsoft-com:hows/Add"
    --which works fine as it fires the service up
    --************************

    <?xml version='1.0' encoding='utf-8'?><soap:Envelope
    xmlns:soap='http://schemas.xmlsoap.org/soap/envelope/'
    xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'
    xmlns:xsd='http://www.w3.org/2001/XMLSchema'><soap:Body><Add
    xmlns='urn:msdn-microsoft-com:hows'><n1>10</n1><n2>20</n2></Add></soap:Body></soap:Envelope>

    --*****************
    --end of the input message
    --*****************

    --*****************
    --here is the add.xslt file
    --****************
    <?xml version="1.0" encoding="utf-8"?>
    <soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xsl:version="1.0">
    <soap:Body>
    <ns:AddResponse xmlns:ns="urn:msdn-microsoft-com:hows">
    <ns:sum>
    <xsl:value-of select="sum(//ns:Add/*/text())"/>
    </ns:sum>
    </ns:AddResponse>
    </soap:Body>
    </soap:Envelope>

    --******************
    --end of add.xslt file
    --******************

    hugedifference@gmail.com Guest

  4. #4

    Default Re: Client found response content type of '', but expected 'text/xml'

    sorry forgot to include the xreader creation in the asmx code file.
    Here it is, insert this into the asmx code before you use the xreader

    XmlReaderSettings settings = new XmlReaderSettings();
    SoapStreams.InputMessage.Position = 0;
    XmlReader xReader = XmlReader.Create(new
    XmlTextReader(SoapStreams.InputMessage),settings);
    while (xReader.Read())
    {
    }

    hugedifference@gmail.com Guest

  5. #5

    Default Re: Client found response content type of '', but expected 'text/xml'

    could this be due to the new plumbing in vs 2005 webservices? It wants
    all the code in the app_code directory and maybe when you put classes
    in there they don't know what is really going on, i.e., in the process
    they are losing their connection to the webservices http pipeline?
    maybe there is a parallel pipeline created that is running too and that
    is why I hit afterserialize twice?

    btw, in case you didn't figure it out, all the .cs code for this app is
    in the app_code directory except for the asmx file (even the asmx.cs is
    in app_code) per the recommendation of VS when you create these
    classes.

    If app_code classes are running in a parallel (disconnected) process
    then why do my soap exceptions work? For example, if I purposely put a
    exception in the asmx.cs file, e.g,, int x = 1/0;, then the
    afterserialize event sees the exception and correctly sends the regular
    output stream (do you call this the chained stream?) and not my
    appoutputstream.

    hugedifference@gmail.com Guest

  6. #6

    Default Re: Client found response content type of '', but expected 'text/xml'

    BTW, the only changes I made to the web.config are below. I really
    don't like using 'App_Code' as the class for my soap extension type,
    but that is what it took to make it work and apparently that is what VS
    2005 wants you to do, i.e., put everything in that directory.

    <webServices>
    <soapExtensionTypes>
    <add type="XmlStreamSoapExtension, App_Code" priority="1"
    group="High"/>
    </soapExtensionTypes>
    <protocols>
    <remove name="HttpGet" />
    <remove name="HttpPost" />
    <remove name="Doentation" />
    </protocols>
    </webServices>

    hugedifference@gmail.com Guest

  7. #7

    Default Re: Client found response content type of '', but expected 'text/xml'

    I figured it out here:
    http://www.experts-exchange.com/Programming/Programming_Languages/Dot_Net/ASP_DOT_NET/Q_22045885.html

    hugedifference@gmail.com Guest

  8. #8

    Default Re: Client found response content type of '', but expected 'text/xml'

    I figured it out here:
    http://www.experts-exchange.com/Programming/Programming_Languages/Dot_Net/ASP_DOT_NET/Q_22045885.html

    hugedifference@gmail.com Guest

Similar Threads

  1. Replies: 4
    Last Post: February 15th, 11:00 PM
  2. Error: (Client found response content type...)
    By Soheil in forum ASP.NET Web Services
    Replies: 2
    Last Post: August 9th, 02:22 PM
  3. Replies: 0
    Last Post: July 26th, 02:47 AM
  4. Client found response content type of 'application/soap'
    By nilok in forum ASP.NET Web Services
    Replies: 0
    Last Post: December 16th, 02:32 PM
  5. Replies: 0
    Last Post: November 14th, 08:47 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139