c# - Getting SOAP Errors with ASMX Web Service e.g Unsupported Media Tyype -
i have been given old webservice .asmx work , although code works fine in debug mode (vs play debug on local host) when seek , write consumer app pass relevant soap request response cannot work.
in .net status 415 unsupported media type (never heard of before) - tech asked me media sending said text xml.
here code plus debug. tried writing asp classic version different errors depending on soap version.
the webservice on 1 server. trying consume local machine , server.
webmethods in .amsx file e.g
[webmethod] public string getname(string clienthash) { }
running on localhost vs in debug mode works treat. copied files website in iis setup me called http://webservice.demo.co.uk
has in next folder structure
webservice.demo.co.uk/http.demo/app_data (empty) webservice.demo.co.uk/http.demo/bin -webservice.dll -webservice.pdb webservice.demo.co.uk/http.demo/properties -assemblyinfo webservice.demo.co.uk/http.demo/ -webservice.asmx -web.config
config file contents
<?xml version="1.0"?> <configuration> <configsections> <sectiongroup name="system.web.extensions" type="system.web.configuration.systemwebextensionssectiongroup, system.web.extensions, version=3.5.0.0, culture=neutral, publickeytoken=31bf3856ad364e35"> <sectiongroup name="scripting" type="system.web.configuration.scriptingsectiongroup, system.web.extensions, version=3.5.0.0, culture=neutral, publickeytoken=31bf3856ad364e35"> <sectiongroup name="webservices" type="system.web.configuration.scriptingwebservicessectiongroup, system.web.extensions, version=3.5.0.0, culture=neutral, publickeytoken=31bf3856ad364e35"> </sectiongroup> </sectiongroup> </sectiongroup> </configsections> <connectionstrings> <add name="apidatabase" connectionstring="xxx" /> <add name="scotland" connectionstring="xxx" /> </connectionstrings> <appsettings> <add key="server" value="server1" /> <add key="demoserver" value="server12" /> <add key="serviceurl" value="http://webservice.demo.co.uk/" /> </appsettings> <system.web> <compilation debug="true" > <assemblies> <add assembly="system.core, version=3.5.0.0, culture=neutral, publickeytoken=b77a5c561934e089"/> <add assembly="system.data.datasetextensions, version=3.5.0.0, culture=neutral, publickeytoken=b77a5c561934e089"/> <add assembly="system.web.extensions, version=3.5.0.0, culture=neutral, publickeytoken=31bf3856ad364e35"/> <add assembly="system.xml.linq, version=3.5.0.0, culture=neutral, publickeytoken=b77a5c561934e089"/> </assemblies> </compilation> <!-- <authentication> section enables configuration of security authentication mode used asp.net identify incoming user. --> <authentication mode="windows" /> <!-- <customerrors> section enables configuration of if/when unhandled error occurs during execution of request. specifically, enables developers configure html error pages displayed in place of error stack trace. <customerrors mode="remoteonly" defaultredirect="genericerrorpage.htm"> <error statuscode="403" redirect="noaccess.htm" /> <error statuscode="404" redirect="filenotfound.htm" /> </customerrors> --> <pages> <controls> <add tagprefix="asp" namespace="system.web.ui" assembly="system.web.extensions, version=3.5.0.0, culture=neutral, publickeytoken=31bf3856ad364e35"/> <add tagprefix="asp" namespace="system.web.ui.webcontrols" assembly="system.web.extensions, version=3.5.0.0, culture=neutral, publickeytoken=31bf3856ad364e35"/> </controls> </pages> <httphandlers> <remove verb="*" path="*.asmx"/> <add verb="*" path="*.asmx" validate="false" type="system.web.script.services.scripthandlerfactory, system.web.extensions, version=3.5.0.0, culture=neutral, publickeytoken=31bf3856ad364e35"/> <add verb="*" path="*_appservice.axd" validate="false" type="system.web.script.services.scripthandlerfactory, system.web.extensions, version=3.5.0.0, culture=neutral, publickeytoken=31bf3856ad364e35"/> <add verb="get,head" path="scriptresource.axd" type="system.web.handlers.scriptresourcehandler, system.web.extensions, version=3.5.0.0, culture=neutral, publickeytoken=31bf3856ad364e35" validate="false"/> </httphandlers> <httpmodules> <add name="scriptmodule" type="system.web.handlers.scriptmodule, system.web.extensions, version=3.5.0.0, culture=neutral, publickeytoken=31bf3856ad364e35"/> </httpmodules> </system.web> <system.codedom> <compilers> <compiler language="c#;cs;csharp" extension=".cs" warninglevel="4" type="microsoft.csharp.csharpcodeprovider, system, version=2.0.0.0, culture=neutral, publickeytoken=b77a5c561934e089"> <provideroption name="compilerversion" value="v3.5"/> <provideroption name="warnaserror" value="false"/> </compiler> </compilers> </system.codedom> <!-- system.webserver section required running asp.net ajax under net info services 7.0. not necessary previous version of iis. --> <system.webserver> <validation validateintegratedmodeconfiguration="false"/> <modules> <remove name="scriptmodule" /> <add name="scriptmodule" precondition="managedhandler" type="system.web.handlers.scriptmodule, system.web.extensions, version=3.5.0.0, culture=neutral, publickeytoken=31bf3856ad364e35"/> </modules> <handlers> <remove name="webservicehandlerfactory-integrated"/> <remove name="scripthandlerfactory" /> <remove name="scripthandlerfactoryappservices" /> <remove name="scriptresource" /> <add name="scripthandlerfactory" verb="*" path="*.asmx" precondition="integratedmode" type="system.web.script.services.scripthandlerfactory, system.web.extensions, version=3.5.0.0, culture=neutral, publickeytoken=31bf3856ad364e35"/> <add name="scripthandlerfactoryappservices" verb="*" path="*_appservice.axd" precondition="integratedmode" type="system.web.script.services.scripthandlerfactory, system.web.extensions, version=3.5.0.0, culture=neutral, publickeytoken=31bf3856ad364e35"/> <add name="scriptresource" precondition="integratedmode" verb="get,head" path="scriptresource.axd" type="system.web.handlers.scriptresourcehandler, system.web.extensions, version=3.5.0.0, culture=neutral, publickeytoken=31bf3856ad364e35" /> </handlers> </system.webserver> <runtime> <assemblybinding appliesto="v2.0.50727" xmlns="urn:schemas-microsoft-com:asm.v1"> <dependentassembly> <assemblyidentity name="system.web.extensions" publickeytoken="31bf3856ad364e35"/> <bindingredirect oldversion="1.0.0.0-1.1.0.0" newversion="3.5.0.0"/> </dependentassembly> <dependentassembly> <assemblyidentity name="system.web.extensions.design" publickeytoken="31bf3856ad364e35"/> <bindingredirect oldversion="1.0.0.0-1.1.0.0" newversion="3.5.0.0"/> </dependentassembly> </assemblybinding> </runtime> </configuration>
this console project app trying run it
and c# consumer app run console trying response error
c:\users\rreid>"c:\users\rreid\documents\visual studio 2010\projects\webs rvice\testwebservice\bin\debug\testwebservice.exe" start 07/10/2014 16:33:31 send xml == <?xml version="1.0" encoding="utf-8"?><soap12:envelope xmlns:xi="http://www.w3.org/2001/xmlschema-instance" xmlns:xsd="http://www.w3.org/2001xmlschema" xmlns:soap12="http://www.w3.org/2003/05/soap-envelope"><soap12:body> getname xmlns="http://tempuri.org/"><clienthash>6d104928-7633-4998-90c5-c01abd4010b</clienthash></getname></soap12:body></soap12:envelope> in httprequest post - http://webservice.demo.co.uk/webservice.asmxop=getname - <?xml version="1.0" encoding="utf-8"?><soap12:envelope xmlns:xsi=" ttp://www.w3.org/2001/xmlschema-instance" xmlns:xsd="http://www.w3.org/2001/xmlchema" xmlns:soap12="http://www.w3.org/2003/05/soap-envelope"><soap12:body><getame xmlns="http://tempuri.org/"><clienthash>6d104928-7633-4998-90c5-c01abd4e010</clienthash></getname></soap12:body></soap12:envelope> - robsbot end of init in makehttprequest in accessurl create post request http://webservice.demo.co.uk/webservice.asmx?p=getname create post request http://webservice.demo.co.uk/webservice.asm?op=getname add together headers create request robsbot convert post info stream = <?xml version="1.0" encoding="utf-8"?><soap12:evelope xmlns:xsi="http://www.w3.org/2001/xmlschema-instance" xmlns:xsd="http://ww.w3.org/2001/xmlschema" mlns:soap12="http://www.w3.org/2003/05/soap-envelope><soap12:body><getname xmlns="http://tempuri.org/"><clienthash>6d104928-7633-498-90c5-c01abd4e010b</clienthash></getname></soap12:body></soap12:envelope> **webexeption remote server returned error: (415) unsupported media type. status = 415 - unsupported media type error = remote server returned error: (415) unsupported media type. error = unknown error statuscode 415 - tries = 1** error unknown error stop 07/10/2014 16:33:34
these soap request examples come hitting debug button in vs 2010 , running on local host on port) - works fine e.g
post /webservice.asmx http/1.1 host: localhost content-type: application/soap+xml; charset=utf-8 content-length: length <?xml version="1.0" encoding="utf-8"?> <soap12:envelope xmlns:xsi="http://www.w3.org/2001/xmlschema-instance" xmlns:xsd="http://www.w3.org/2001/xmlschema" xmlns:soap12="http://www.w3.org/2003/05/soap-envelope"> <soap12:body> <getname xmlns="http://tempuri.org/"> <clienthash>string</clienthash> </getname> </soap12:body> </soap12:envelope>
so have replaced values host , on url on server web service based
these asp attempts
soap 1.1 illustration asp classic
post /webservice.asmx http/1.1 host: webservice.demo.co.uk content-type: text/xml; charset=utf-8 content-length: length soapaction: "http://webservice.demo.co.uk/webservice.asmx/getname" <?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:body> <getname xmlns="http://webservice.demo.co.uk/webservice.asmx/"> <clienthash>string</clienthash> </getname> </soap:body> </soap:envelope>
debug
in soappost & http://webservice.demo.co.uk/webservice.asmx posting http://webservice.demo.co.uk/webservice.asmx build soap wrapper our soap request = <?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:soap12="http://www.w3.org/2003/05/soap-envelope"> <soap:body> <getname xmlns="http://webservice.demo.co.uk/"> <clienthash>6d104928-7633-4998-90c5-c01abd4e010b</clienthash> </getname> </soap:body> </soap:envelope> in makesoaprequest create post request http://webservice.demo.co.uk/webservice.asmx set host header webservice.demo.co.uk set content-type header text/xml; charset=utf-8 set soapaction header **/webservice.asmx/getname** set user-agent pdr internal crawler set request header content-length 385 post request == <?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:soap12="http://www.w3.org/2003/05/soap-envelope"> <soap:body> <getname xmlns="http://webservice.demo.co.uk/"> <clienthash>6d104928-7633-4998-90c5-c01abd4e010b</clienthash> </getname> </soap:body> </soap:envelope> no error sending request response response == <?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><soap:fault><faultcode>soap:client</faultcode><faultstring>**server did not recognize value of http header soapaction: /getname.**</faultstring><detail /></soap:fault></soap:body></soap:envelope> server did not recognize value of http header soapaction: /getname. soap 1.2 illustration asp classic post /webservice.asmx http/1.1 host: localhost content-type: application/soap+xml; charset=utf-8 content-length: length <?xml version="1.0" encoding="utf-8"?> <soap12:envelope xmlns:xsi="http://www.w3.org/2001/xmlschema-instance" xmlns:xsd="http://www.w3.org/2001/xmlschema" xmlns:soap12="http://www.w3.org/2003/05/soap-envelope"> <soap12:body> <getname xmlns="http://tempuri.org/"> <clienthash>string</clienthash> </getname> </soap12:body> </soap12:envelope> in soappost & http://webservice.demo.co.uk/webservice.asmx posting http://webservice.demo.co.uk/webservice.asmx build soap wrapper our soap request = <?xml version="1.0" encoding="utf-8"?> <soap12:envelope xmlns:xsi="http://www.w3.org/2001/xmlschema-instance" xmlns:xsd="http://www.w3.org/2001/xmlschema" xmlns:soap12="http://www.w3.org/2003/05/soap-envelope"> <soap12:body> <getname xmlns="http://webservice.demo.co.uk/"> <clienthash>6d104928-7633-4998-90c5-c01abd4e010b</clienthash> </getname> </soap12:body> </soap12:envelope> in makesoaprequest create post request http://webservice.demo.co.uk/webservice.asmx set host header webservice.demo.co.uk set content-type header application/soap+xml; charset=utf-8 set user-agent pdr internal crawler set request header content-length 393 post request == <?xml version="1.0" encoding="utf-8"?> <soap12:envelope xmlns:xsi="http://www.w3.org/2001/xmlschema-instance" xmlns:xsd="http://www.w3.org/2001/xmlschema" xmlns:soap12="http://www.w3.org/2003/05/soap-envelope"> <soap12:body> <getname xmlns="http://webservice.demo.co.uk/"> <clienthash>6d104928-7633-4998-90c5-c01abd4e010b</clienthash> </getname> </soap12:body> </soap12:envelope> no error sending request response response == <?xml version="1.0" encoding="utf-8"?><soap:envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:xsi="http://www.w3.org/2001/xmlschema-instance" xmlns:xsd="http://www.w3.org/2001/xmlschema"><soap:body><soap:fault><soap:code><soap:value>soap:receiver</soap:value></soap:code><soap:reason><soap:text xml:lang="en">**server unable process request. ---> root element missing.**</soap:text></soap:reason><soap:detail /></soap:fault></soap:body></soap:envelope>
so root element missing? what? , server did not recognize value of http header soapaction: /getname.
so doing wrong?
i know .asmx old have taken on project.
i need consumer app can take works vs on localhost pc server or server server.
why many errors
and unsupported media type error 415?
how can prepare it
c# xml web-services soap asmx
No comments:
Post a Comment