EDN Admin
Well-known member
Hi,
I want create a WCF Web Service that uses HTTP post instead of the standard SOAP xmls, looking through the internet I managed to make it work with HTTP GET, but I am having some trouble getting the HTTP POST working.
This is my server code:
<div style="color:black; background-color:white
<pre>[ServiceContract(Namespace = <span style="color:#a31515 "http://myCompany.com.br/MyCompany/Test")]<br/> <span style="color:blue public <span style="color:blue interface HTTPPostTest<br/> {<br/> [OperationContract]<br/> <span style="color:blue byte[] WS_HttpPostTest(<span style="color:blue string request);<br/> }<br/>[/code]
<div style="color:black; background-color:white
<pre><span style="color:blue public <span style="color:blue class HTTPostTestImpl : HTTPostTest
{
<span style="color:blue public HTTPostTestImpl()
{
}
<span style="color:blue public <span style="color:blue byte[] WS_HttpPostTest(<span style="color:blue string request)
{
<span style="color:blue byte[] resultadoConsulta;
resultadoConsulta = <span style="color:blue new <span style="color:blue byte[11];
resultadoConsulta[0] = 1;
resultadoConsulta[1] = 1;
resultadoConsulta[2] = 1;
resultadoConsulta[3] = 0;
resultadoConsulta[4] = 1;
resultadoConsulta[5] = 0;
resultadoConsulta[6] = 0;
resultadoConsulta[7] = 0;
resultadoConsulta[8] = 0;
resultadoConsulta[9] = 0;
resultadoConsulta[10] = 4;
<span style="color:blue return resultadoConsulta;
}
}
[/code]
This is the web.config:
<div style="color:black; background-color:white
<pre><span style="color:blue <?<span style="color:#a31515 xml <span style="color:red version<span style="color:blue =<span style="color:black "<span style="color:blue 1.0<span style="color:black "<span style="color:blue ?>
<span style="color:green <!--
Note: As an alternative to hand editing this file you can use the
web admin tool to configure settings for your application. Use
the Website->Asp.Net Configuration option in Visual Studio.
A full list of settings and comments can be found in
machine.config.comments usually located in
WindowsMicrosoft.NetFrameworkv2.xConfig
-->
<span style="color:blue <<span style="color:#a31515 configuration<span style="color:blue >
<span style="color:blue <<span style="color:#a31515 configSections<span style="color:blue >
<span style="color:blue <<span style="color:#a31515 sectionGroup <span style="color:red name<span style="color:blue =<span style="color:black "<span style="color:blue system.web.extensions<span style="color:black " <span style="color:red type<span style="color:blue =<span style="color:black "<span style="color:blue System.Web.Configuration.SystemWebExtensionsSectionGroup, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35<span style="color:black "<span style="color:blue >
<span style="color:blue <<span style="color:#a31515 sectionGroup <span style="color:red name<span style="color:blue =<span style="color:black "<span style="color:blue scripting<span style="color:black " <span style="color:red type<span style="color:blue =<span style="color:black "<span style="color:blue System.Web.Configuration.ScriptingSectionGroup, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35<span style="color:black "<span style="color:blue >
<span style="color:blue <<span style="color:#a31515 section <span style="color:red name<span style="color:blue =<span style="color:black "<span style="color:blue scriptResourceHandler<span style="color:black " <span style="color:red type<span style="color:blue =<span style="color:black "<span style="color:blue System.Web.Configuration.ScriptingScriptResourceHandlerSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35<span style="color:black " <span style="color:red requirePermission<span style="color:blue =<span style="color:black "<span style="color:blue false<span style="color:black " <span style="color:red allowDefinition<span style="color:blue =<span style="color:black "<span style="color:blue MachineToApplication<span style="color:black "<span style="color:blue />
<span style="color:blue <<span style="color:#a31515 sectionGroup <span style="color:red name<span style="color:blue =<span style="color:black "<span style="color:blue webServices<span style="color:black " <span style="color:red type<span style="color:blue =<span style="color:black "<span style="color:blue System.Web.Configuration.ScriptingWebServicesSectionGroup, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35<span style="color:black "<span style="color:blue >
<span style="color:blue <<span style="color:#a31515 section <span style="color:red name<span style="color:blue =<span style="color:black "<span style="color:blue jsonSerialization<span style="color:black " <span style="color:red type<span style="color:blue =<span style="color:black "<span style="color:blue System.Web.Configuration.ScriptingJsonSerializationSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35<span style="color:black " <span style="color:red requirePermission<span style="color:blue =<span style="color:black "<span style="color:blue false<span style="color:black " <span style="color:red allowDefinition<span style="color:blue =<span style="color:black "<span style="color:blue Everywhere<span style="color:black "<span style="color:blue />
<span style="color:blue <<span style="color:#a31515 section <span style="color:red name<span style="color:blue =<span style="color:black "<span style="color:blue profileService<span style="color:black " <span style="color:red type<span style="color:blue =<span style="color:black "<span style="color:blue System.Web.Configuration.ScriptingProfileServiceSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35<span style="color:black " <span style="color:red requirePermission<span style="color:blue =<span style="color:black "<span style="color:blue false<span style="color:black " <span style="color:red allowDefinition<span style="color:blue =<span style="color:black "<span style="color:blue MachineToApplication<span style="color:black "<span style="color:blue />
<span style="color:blue <<span style="color:#a31515 section <span style="color:red name<span style="color:blue =<span style="color:black "<span style="color:blue authenticationService<span style="color:black " <span style="color:red type<span style="color:blue =<span style="color:black "<span style="color:blue System.Web.Configuration.ScriptingAuthenticationServiceSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35<span style="color:black " <span style="color:red requirePermission<span style="color:blue =<span style="color:black "<span style="color:blue false<span style="color:black " <span style="color:red allowDefinition<span style="color:blue =<span style="color:black "<span style="color:blue MachineToApplication<span style="color:black "<span style="color:blue />
<span style="color:blue <<span style="color:#a31515 section <span style="color:red name<span style="color:blue =<span style="color:black "<span style="color:blue roleService<span style="color:black " <span style="color:red type<span style="color:blue =<span style="color:black "<span style="color:blue System.Web.Configuration.ScriptingRoleServiceSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35<span style="color:black " <span style="color:red requirePermission<span style="color:blue =<span style="color:black "<span style="color:blue false<span style="color:black " <span style="color:red allowDefinition<span style="color:blue =<span style="color:black "<span style="color:blue MachineToApplication<span style="color:black "<span style="color:blue />
<span style="color:blue </<span style="color:#a31515 sectionGroup<span style="color:blue >
<span style="color:blue </<span style="color:#a31515 sectionGroup<span style="color:blue >
<span style="color:blue </<span style="color:#a31515 sectionGroup<span style="color:blue >
<span style="color:blue </<span style="color:#a31515 configSections<span style="color:blue >
<span style="color:blue <<span style="color:#a31515 appSettings<span style="color:blue />
<span style="color:blue <<span style="color:#a31515 connectionStrings<span style="color:blue />
<span style="color:blue <<span style="color:#a31515 system.web<span style="color:blue >
<span style="color:green <!--
Set compilation debug="true" to insert debugging
symbols into the compiled page. Because this
affects performance, set this value to true only
during development.
-->
<span style="color:blue <<span style="color:#a31515 compilation <span style="color:red debug<span style="color:blue =<span style="color:black "<span style="color:blue true<span style="color:black "<span style="color:blue >
<span style="color:blue <<span style="color:#a31515 assemblies<span style="color:blue >
<span style="color:blue <<span style="color:#a31515 add <span style="color:red assembly<span style="color:blue =<span style="color:black "<span style="color:blue System.Core, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089<span style="color:black "<span style="color:blue />
<span style="color:blue <<span style="color:#a31515 add <span style="color:red assembly<span style="color:blue =<span style="color:black "<span style="color:blue System.Xml.Linq, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089<span style="color:black "<span style="color:blue />
<span style="color:blue <<span style="color:#a31515 add <span style="color:red assembly<span style="color:blue =<span style="color:black "<span style="color:blue System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35<span style="color:black "<span style="color:blue />
<span style="color:blue <<span style="color:#a31515 add <span style="color:red assembly<span style="color:blue =<span style="color:black "<span style="color:blue System.Data.DataSetExtensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089<span style="color:black "<span style="color:blue />
<span style="color:blue </<span style="color:#a31515 assemblies<span style="color:blue >
<span style="color:blue </<span style="color:#a31515 compilation<span style="color:blue >
<span style="color:green <!--
The <authentication> section enables configuration
of the security authentication mode used by
ASP.NET to identify an incoming user.
-->
<span style="color:blue <<span style="color:#a31515 authentication <span style="color:red mode<span style="color:blue =<span style="color:black "<span style="color:blue Windows<span style="color:black "<span style="color:blue />
<span style="color:green <!--
The <customErrors> section enables configuration
of what to do if/when an unhandled error occurs
during the execution of a request. Specifically,
it enables developers to configure html error pages
to be displayed in place of a error stack trace.
<customErrors mode="RemoteOnly" defaultRedirect="GenericErrorPage.htm
<error statusCode="403" redirect="NoAccess.htm" />
<error statusCode="404" redirect="FileNotFound.htm" />
</customErrors>
-->
<span style="color:blue <<span style="color:#a31515 pages<span style="color:blue >
<span style="color:blue <<span style="color:#a31515 controls<span style="color:blue >
<span style="color:blue <<span style="color:#a31515 add <span style="color:red tagPrefix<span style="color:blue =<span style="color:black "<span style="color:blue asp<span style="color:black " <span style="color:red namespace<span style="color:blue =<span style="color:black "<span style="color:blue System.Web.UI<span style="color:black " <span style="color:red assembly<span style="color:blue =<span style="color:black "<span style="color:blue System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35<span style="color:black "<span style="color:blue />
<span style="color:blue </<span style="color:#a31515 controls<span style="color:blue >
<span style="color:blue </<span style="color:#a31515 pages<span style="color:blue >
<span style="color:blue <<span style="color:#a31515 httpHandlers<span style="color:blue >
<span style="color:blue <<span style="color:#a31515 remove <span style="color:red verb<span style="color:blue =<span style="color:black "<span style="color:blue *<span style="color:black " <span style="color:red path<span style="color:blue =<span style="color:black "<span style="color:blue *.asmx<span style="color:black "<span style="color:blue />
<span style="color:blue <<span style="color:#a31515 add <span style="color:red verb<span style="color:blue =<span style="color:black "<span style="color:blue *<span style="color:black " <span style="color:red path<span style="color:blue =<span style="color:black "<span style="color:blue *.asmx<span style="color:black " <span style="color:red validate<span style="color:blue =<span style="color:black "<span style="color:blue false<span style="color:black " <span style="color:red type<span style="color:blue =<span style="color:black "<span style="color:blue System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35<span style="color:black "<span style="color:blue />
<span style="color:blue <<span style="color:#a31515 add <span style="color:red verb<span style="color:blue =<span style="color:black "<span style="color:blue *<span style="color:black " <span style="color:red path<span style="color:blue =<span style="color:black "<span style="color:blue *_AppService.axd<span style="color:black " <span style="color:red validate<span style="color:blue =<span style="color:black "<span style="color:blue false<span style="color:black " <span style="color:red type<span style="color:blue =<span style="color:black "<span style="color:blue System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35<span style="color:black "<span style="color:blue />
<span style="color:blue <<span style="color:#a31515 add <span style="color:red verb<span style="color:blue =<span style="color:black "<span style="color:blue GET,HEAD<span style="color:black " <span style="color:red path<span style="color:blue =<span style="color:black "<span style="color:blue ScriptResource.axd<span style="color:black " <span style="color:red type<span style="color:blue =<span style="color:black "<span style="color:blue System.Web.Handlers.ScriptResourceHandler, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35<span style="color:black " <span style="color:red validate<span style="color:blue =<span style="color:black "<span style="color:blue false<span style="color:black "<span style="color:blue />
<span style="color:blue </<span style="color:#a31515 httpHandlers<span style="color:blue >
<span style="color:blue <<span style="color:#a31515 httpModules<span style="color:blue >
<span style="color:blue <<span style="color:#a31515 add <span style="color:red name<span style="color:blue =<span style="color:black "<span style="color:blue ScriptModule<span style="color:black " <span style="color:red type<span style="color:blue =<span style="color:black "<span style="color:blue System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35<span style="color:black "<span style="color:blue />
<span style="color:blue </<span style="color:#a31515 httpModules<span style="color:blue >
<span style="color:blue </<span style="color:#a31515 system.web<span style="color:blue >
<span style="color:blue <<span style="color:#a31515 system.codedom<span style="color:blue >
<span style="color:blue <<span style="color:#a31515 compilers<span style="color:blue >
<span style="color:blue <<span style="color:#a31515 compiler <span style="color:red language<span style="color:blue =<span style="color:black "<span style="color:blue c#;cs;csharp<span style="color:black " <span style="color:red extension<span style="color:blue =<span style="color:black "<span style="color:blue .cs<span style="color:black " <span style="color:red warningLevel<span style="color:blue =<span style="color:black "<span style="color:blue 4<span style="color:black " <span style="color:red type<span style="color:blue =<span style="color:black "<span style="color:blue Microsoft.CSharp.CSharpCodeProvider, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089<span style="color:black "<span style="color:blue >
<span style="color:blue <<span style="color:#a31515 providerOption <span style="color:red name<span style="color:blue =<span style="color:black "<span style="color:blue CompilerVersion<span style="color:black " <span style="color:red value<span style="color:blue =<span style="color:black "<span style="color:blue v3.5<span style="color:black "<span style="color:blue />
<span style="color:blue <<span style="color:#a31515 providerOption <span style="color:red name<span style="color:blue =<span style="color:black "<span style="color:blue WarnAsError<span style="color:black " <span style="color:red value<span style="color:blue =<span style="color:black "<span style="color:blue false<span style="color:black "<span style="color:blue />
<span style="color:blue </<span style="color:#a31515 compiler<span style="color:blue >
<span style="color:blue <<span style="color:#a31515 compiler <span style="color:red language<span style="color:blue =<span style="color:black "<span style="color:blue vb;vbs;visualbasic;vbscript<span style="color:black " <span style="color:red extension<span style="color:blue =<span style="color:black "<span style="color:blue .vb<span style="color:black " <span style="color:red warningLevel<span style="color:blue =<span style="color:black "<span style="color:blue 4<span style="color:black " <span style="color:red type<span style="color:blue =<span style="color:black "<span style="color:blue Microsoft.VisualBasic.VBCodeProvider, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089<span style="color:black "<span style="color:blue >
<span style="color:blue <<span style="color:#a31515 providerOption <span style="color:red name<span style="color:blue =<span style="color:black "<span style="color:blue CompilerVersion<span style="color:black " <span style="color:red value<span style="color:blue =<span style="color:black "<span style="color:blue v3.5<span style="color:black "<span style="color:blue />
<span style="color:blue <<span style="color:#a31515 providerOption <span style="color:red name<span style="color:blue =<span style="color:black "<span style="color:blue OptionInfer<span style="color:black " <span style="color:red value<span style="color:blue =<span style="color:black "<span style="color:blue true<span style="color:black "<span style="color:blue />
<span style="color:blue <<span style="color:#a31515 providerOption <span style="color:red name<span style="color:blue =<span style="color:black "<span style="color:blue WarnAsError<span style="color:black " <span style="color:red value<span style="color:blue =<span style="color:black "<span style="color:blue false<span style="color:black "<span style="color:blue />
<span style="color:blue </<span style="color:#a31515 compiler<span style="color:blue >
<span style="color:blue </<span style="color:#a31515 compilers<span style="color:blue >
<span style="color:blue </<span style="color:#a31515 system.codedom<span style="color:blue >
<span style="color:blue <<span style="color:#a31515 system.web.extensions<span style="color:blue >
<span style="color:blue <<span style="color:#a31515 scripting<span style="color:blue >
<span style="color:blue <<span style="color:#a31515 webServices<span style="color:blue >
<span style="color:green <!--
Uncomment this section to enable the authentication service. Include
requireSSL="true" if appropriate.
<authenticationService enabled="true" requireSSL = "true|false"/>
-->
<span style="color:green <!--
Uncomment these lines to enable the profile service, and to choose the
profile properties that can be retrieved and modified in ASP.NET AJAX
applications.
<profileService enabled="true"
readAccessProperties="propertyname1,propertyname2"
writeAccessProperties="propertyname1,propertyname2" />
-->
<span style="color:green <!--
Uncomment this section to enable the role service.
<roleService enabled="true"/>
-->
<span style="color:blue </<span style="color:#a31515 webServices<span style="color:blue >
<span style="color:green <!--
<scriptResourceHandler enableCompression="true" enableCaching="true" />
-->
<span style="color:blue </<span style="color:#a31515 scripting<span style="color:blue >
<span style="color:blue </<span style="color:#a31515 system.web.extensions<span style="color:blue >
<span style="color:green <!--
The system.webServer section is required for running ASP.NET AJAX under Internet
Information Services 7.0. It is not necessary for previous version of IIS.
-->
<span style="color:blue <<span style="color:#a31515 system.webServer<span style="color:blue >
<span style="color:blue <<span style="color:#a31515 validation <span style="color:red validateIntegratedModeConfiguration<span style="color:blue =<span style="color:black "<span style="color:blue false<span style="color:black "<span style="color:blue />
<span style="color:blue <<span style="color:#a31515 modules<span style="color:blue >
<span style="color:blue <<span style="color:#a31515 add <span style="color:red name<span style="color:blue =<span style="color:black "<span style="color:blue ScriptModule<span style="color:black " <span style="color:red preCondition<span style="color:blue =<span style="color:black "<span style="color:blue integratedMode<span style="color:black " <span style="color:red type<span style="color:blue =<span style="color:black "<span style="color:blue System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35<span style="color:black "<span style="color:blue />
<span style="color:blue </<span style="color:#a31515 modules<span style="color:blue >
<span style="color:blue <<span style="color:#a31515 handlers<span style="color:blue >
<span style="color:blue <<span style="color:#a31515 remove <span style="color:red name<span style="color:blue =<span style="color:black "<span style="color:blue WebServiceHandlerFactory-Integrated<span style="color:black "<span style="color:blue />
<span style="color:blue <<span style="color:#a31515 add <span style="color:red name<span style="color:blue =<span style="color:black "<span style="color:blue ScriptHandlerFactory<span style="color:black " <span style="color:red verb<span style="color:blue =<span style="color:black "<span style="color:blue *<span style="color:black " <span style="color:red path<span style="color:blue =<span style="color:black "<span style="color:blue *.asmx<span style="color:black " <span style="color:red preCondition<span style="color:blue =<span style="color:black "<span style="color:blue integratedMode<span style="color:black " <span style="color:red type<span style="color:blue =<span style="color:black "<span style="color:blue System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35<span style="color:black "<span style="color:blue />
<span style="color:blue <<span style="color:#a31515 add <span style="color:red name<span style="color:blue =<span style="color:black "<span style="color:blue ScriptHandlerFactoryAppServices<span style="color:black " <span style="color:red verb<span style="color:blue =<span style="color:black "<span style="color:blue *<span style="color:black " <span style="color:red path<span style="color:blue =<span style="color:black "<span style="color:blue *_AppService.axd<span style="color:black " <span style="color:red preCondition<span style="color:blue =<span style="color:black "<span style="color:blue integratedMode<span style="color:black " <span style="color:red type<span style="color:blue =<span style="color:black "<span style="color:blue System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35<span style="color:black "<span style="color:blue />
<span style="color:blue <<span style="color:#a31515 add <span style="color:red name<span style="color:blue =<span style="color:black "<span style="color:blue ScriptResource<span style="color:black " <span style="color:red preCondition<span style="color:blue =<span style="color:black "<span style="color:blue integratedMode<span style="color:black " <span style="color:red verb<span style="color:blue =<span style="color:black "<span style="color:blue GET,HEAD<span style="color:black " <span style="color:red path<span style="color:blue =<span style="color:black "<span style="color:blue ScriptResource.axd<span style="color:black " <span style="color:red type<span style="color:blue =<span style="color:black "<span style="color:blue System.Web.Handlers.ScriptResourceHandler, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35<span style="color:black "<span style="color:blue />
<span style="color:blue </<span style="color:#a31515 handlers<span style="color:blue >
<span style="color:blue </<span style="color:#a31515 system.webServer<span style="color:blue >
<span style="color:blue <<span style="color:#a31515 system.serviceModel<span style="color:blue >
<span style="color:green <!-- Bindings -->
<span style="color:blue <<span style="color:#a31515 bindings<span style="color:blue >
<span style="color:blue <<span style="color:#a31515 basicHttpBinding<span style="color:blue >
<span style="color:blue <<span style="color:#a31515 binding <span style="color:red name<span style="color:blue =<span style="color:black "<span style="color:blue TestBasicHttpBinding<span style="color:black "<span style="color:blue >
<span style="color:blue </<span style="color:#a31515 binding<span style="color:blue >
<span style="color:blue </<span style="color:#a31515 basicHttpBinding<span style="color:blue >
<span style="color:blue </<span style="color:#a31515 bindings<span style="color:blue >
<span style="color:blue <<span style="color:#a31515 services<span style="color:blue >
<span style="color:blue <<span style="color:#a31515 service <span style="color:red name<span style="color:blue =<span style="color:black "<span style="color:blue HttpPostTestImpl<span style="color:black " <span style="color:red behaviorConfiguration<span style="color:blue =<span style="color:black "<span style="color:blue ServiceBehavior<span style="color:black "<span style="color:blue >
<span style="color:blue <<span style="color:#a31515 endpoint <span style="color:red address<span style="color:blue =<span style="color:black "<span style="color:blue " behaviorConfiguration="WebBehavior<span style="color:black " <span style="color:red binding<span style="color:blue =<span style="color:black "<span style="color:blue webHttpBinding<span style="color:black " <span style="color:red contract<span style="color:blue =<span style="color:black "<span style="color:blue HttpPostTest<span style="color:black "<span style="color:blue >
<span style="color:green <!--
Upon deployment, the following identity element should be removed or replaced to reflect the
identity under which the deployed service runs. If removed, WCF will infer an appropriate identity
automatically.
-->
<span style="color:blue <<span style="color:#a31515 identity<span style="color:blue >
<span style="color:blue <<span style="color:#a31515 dns <span style="color:red value<span style="color:blue =<span style="color:black "<span style="color:blue localhost<span style="color:black "<span style="color:blue />
<span style="color:blue </<span style="color:#a31515 identity<span style="color:blue >
<span style="color:blue </<span style="color:#a31515 endpoint<span style="color:blue >
<span style="color:blue <<span style="color:#a31515 endpoint <span style="color:red address<span style="color:blue =<span style="color:black "<span style="color:blue mex<span style="color:black " <span style="color:red binding<span style="color:blue =<span style="color:black "<span style="color:blue mexHttpBinding<span style="color:black " <span style="color:red contract<span style="color:blue =<span style="color:black "<span style="color:blue IMetadataExchange<span style="color:black "<span style="color:blue />
<span style="color:blue </<span style="color:#a31515 service<span style="color:blue >
<span style="color:blue </<span style="color:#a31515 services<span style="color:blue >
<span style="color:blue <<span style="color:#a31515 behaviors<span style="color:blue >
<span style="color:blue <<span style="color:#a31515 serviceBehaviors<span style="color:blue >
<span style="color:blue <<span style="color:#a31515 behavior <span style="color:red name<span style="color:blue =<span style="color:black "<span style="color:blue ServiceBehavior<span style="color:black "<span style="color:blue >
<span style="color:green <!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment -->
<span style="color:blue <<span style="color:#a31515 serviceMetadata <span style="color:red httpGetEnabled<span style="color:blue =<span style="color:black "<span style="color:blue true<span style="color:black "<span style="color:blue />
<span style="color:green <!-- To receive exception details in faults for debugging purposes, set the value below to true. Set to false before deployment to avoid disclosing exception information -->
<span style="color:blue <<span style="color:#a31515 serviceDebug <span style="color:red includeExceptionDetailInFaults<span style="color:blue =<span style="color:black "<span style="color:blue false<span style="color:black "<span style="color:blue />
<span style="color:blue </<span style="color:#a31515 behavior<span style="color:blue >
<span style="color:blue </<span style="color:#a31515 serviceBehaviors<span style="color:blue >
<span style="color:blue <<span style="color:#a31515 endpointBehaviors<span style="color:blue >
<span style="color:blue <<span style="color:#a31515 behavior <span style="color:red name<span style="color:blue =<span style="color:black "<span style="color:blue WebBehavior<span style="color:black "<span style="color:blue >
<span style="color:blue <<span style="color:#a31515 webHttp<span style="color:blue />
<span style="color:blue </<span style="color:#a31515 behavior<span style="color:blue >
<span style="color:blue </<span style="color:#a31515 endpointBehaviors<span style="color:blue >
<span style="color:blue </<span style="color:#a31515 behaviors<span style="color:blue >
<span style="color:blue </<span style="color:#a31515 system.serviceModel<span style="color:blue >
<span style="color:blue </<span style="color:#a31515 configuration<span style="color:blue >
[/code]
This is my client code:
<div style="color:black; background-color:white
<pre> WebRequest webRequest = WebRequest.Create(<span style="color:#a31515 "http://localhost:8889/HttpPostTest/Service.svc/WS_HttpPostTest");
webRequest.ContentType = <span style="color:#a31515 "application/x-www-form-urlencoded";
webRequest.Method = <span style="color:#a31515 "POST";
<span style="color:blue string data = <span style="color:#a31515 "request=" + Convert.ToString(1231234);
<span style="color:blue byte[] bytes = Encoding.ASCII.GetBytes(data);
Stream os = <span style="color:blue null;
<span style="color:blue try
{ <span style="color:green // send the Post
Console.WriteLine(<span style="color:#a31515 "Enviando pedido");
webRequest.ContentLength = bytes.Length; <span style="color:green //Count bytes to send
os = webRequest.GetRequestStream();
os.Write(bytes, 0, bytes.Length); <span style="color:green //Send it
}
<span style="color:blue catch (WebException ex)
{
Console.WriteLine(<span style="color:#a31515 "HttpPost: Request error: " + ex.Message);
Console.WriteLine(ex.StackTrace);
}
<span style="color:blue finally
{
<span style="color:blue if (os != <span style="color:blue null)
{
os.Close();
}
}
<span style="color:blue try
{ <span style="color:green // get the response
WebResponse webResponse = webRequest.GetResponse();
<span style="color:blue if (webResponse != <span style="color:blue null)
{
StreamReader sr = <span style="color:blue new StreamReader(webResponse.GetResponseStream());
Console.WriteLine(<span style="color:#a31515 "Valor recebido: " + sr.ReadToEnd().Trim());
}
<span style="color:blue else
Console.WriteLine(<span style="color:#a31515 "Nenhum valor recebido");
}
<span style="color:blue catch (WebException ex)
{
Console.WriteLine(<span style="color:#a31515 "HttpPost: Response error: " + ex.Message);
Console.WriteLine(ex.StackTrace);
}
[/code]
When I run this test program I get the following error:
<pre>Enviando pedido
HttpPost: Response error: O servidor remoto retornou um erro: (400) SolicitaÃÃo Incorreta. <br/>[/code]
What am I doing wrong in this program?
Thanks,<br/>
Komyg
<br/>
View the full article
I want create a WCF Web Service that uses HTTP post instead of the standard SOAP xmls, looking through the internet I managed to make it work with HTTP GET, but I am having some trouble getting the HTTP POST working.
This is my server code:
<div style="color:black; background-color:white
<pre>[ServiceContract(Namespace = <span style="color:#a31515 "http://myCompany.com.br/MyCompany/Test")]<br/> <span style="color:blue public <span style="color:blue interface HTTPPostTest<br/> {<br/> [OperationContract]<br/> <span style="color:blue byte[] WS_HttpPostTest(<span style="color:blue string request);<br/> }<br/>[/code]
<div style="color:black; background-color:white
<pre><span style="color:blue public <span style="color:blue class HTTPostTestImpl : HTTPostTest
{
<span style="color:blue public HTTPostTestImpl()
{
}
<span style="color:blue public <span style="color:blue byte[] WS_HttpPostTest(<span style="color:blue string request)
{
<span style="color:blue byte[] resultadoConsulta;
resultadoConsulta = <span style="color:blue new <span style="color:blue byte[11];
resultadoConsulta[0] = 1;
resultadoConsulta[1] = 1;
resultadoConsulta[2] = 1;
resultadoConsulta[3] = 0;
resultadoConsulta[4] = 1;
resultadoConsulta[5] = 0;
resultadoConsulta[6] = 0;
resultadoConsulta[7] = 0;
resultadoConsulta[8] = 0;
resultadoConsulta[9] = 0;
resultadoConsulta[10] = 4;
<span style="color:blue return resultadoConsulta;
}
}
[/code]
This is the web.config:
<div style="color:black; background-color:white
<pre><span style="color:blue <?<span style="color:#a31515 xml <span style="color:red version<span style="color:blue =<span style="color:black "<span style="color:blue 1.0<span style="color:black "<span style="color:blue ?>
<span style="color:green <!--
Note: As an alternative to hand editing this file you can use the
web admin tool to configure settings for your application. Use
the Website->Asp.Net Configuration option in Visual Studio.
A full list of settings and comments can be found in
machine.config.comments usually located in
WindowsMicrosoft.NetFrameworkv2.xConfig
-->
<span style="color:blue <<span style="color:#a31515 configuration<span style="color:blue >
<span style="color:blue <<span style="color:#a31515 configSections<span style="color:blue >
<span style="color:blue <<span style="color:#a31515 sectionGroup <span style="color:red name<span style="color:blue =<span style="color:black "<span style="color:blue system.web.extensions<span style="color:black " <span style="color:red type<span style="color:blue =<span style="color:black "<span style="color:blue System.Web.Configuration.SystemWebExtensionsSectionGroup, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35<span style="color:black "<span style="color:blue >
<span style="color:blue <<span style="color:#a31515 sectionGroup <span style="color:red name<span style="color:blue =<span style="color:black "<span style="color:blue scripting<span style="color:black " <span style="color:red type<span style="color:blue =<span style="color:black "<span style="color:blue System.Web.Configuration.ScriptingSectionGroup, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35<span style="color:black "<span style="color:blue >
<span style="color:blue <<span style="color:#a31515 section <span style="color:red name<span style="color:blue =<span style="color:black "<span style="color:blue scriptResourceHandler<span style="color:black " <span style="color:red type<span style="color:blue =<span style="color:black "<span style="color:blue System.Web.Configuration.ScriptingScriptResourceHandlerSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35<span style="color:black " <span style="color:red requirePermission<span style="color:blue =<span style="color:black "<span style="color:blue false<span style="color:black " <span style="color:red allowDefinition<span style="color:blue =<span style="color:black "<span style="color:blue MachineToApplication<span style="color:black "<span style="color:blue />
<span style="color:blue <<span style="color:#a31515 sectionGroup <span style="color:red name<span style="color:blue =<span style="color:black "<span style="color:blue webServices<span style="color:black " <span style="color:red type<span style="color:blue =<span style="color:black "<span style="color:blue System.Web.Configuration.ScriptingWebServicesSectionGroup, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35<span style="color:black "<span style="color:blue >
<span style="color:blue <<span style="color:#a31515 section <span style="color:red name<span style="color:blue =<span style="color:black "<span style="color:blue jsonSerialization<span style="color:black " <span style="color:red type<span style="color:blue =<span style="color:black "<span style="color:blue System.Web.Configuration.ScriptingJsonSerializationSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35<span style="color:black " <span style="color:red requirePermission<span style="color:blue =<span style="color:black "<span style="color:blue false<span style="color:black " <span style="color:red allowDefinition<span style="color:blue =<span style="color:black "<span style="color:blue Everywhere<span style="color:black "<span style="color:blue />
<span style="color:blue <<span style="color:#a31515 section <span style="color:red name<span style="color:blue =<span style="color:black "<span style="color:blue profileService<span style="color:black " <span style="color:red type<span style="color:blue =<span style="color:black "<span style="color:blue System.Web.Configuration.ScriptingProfileServiceSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35<span style="color:black " <span style="color:red requirePermission<span style="color:blue =<span style="color:black "<span style="color:blue false<span style="color:black " <span style="color:red allowDefinition<span style="color:blue =<span style="color:black "<span style="color:blue MachineToApplication<span style="color:black "<span style="color:blue />
<span style="color:blue <<span style="color:#a31515 section <span style="color:red name<span style="color:blue =<span style="color:black "<span style="color:blue authenticationService<span style="color:black " <span style="color:red type<span style="color:blue =<span style="color:black "<span style="color:blue System.Web.Configuration.ScriptingAuthenticationServiceSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35<span style="color:black " <span style="color:red requirePermission<span style="color:blue =<span style="color:black "<span style="color:blue false<span style="color:black " <span style="color:red allowDefinition<span style="color:blue =<span style="color:black "<span style="color:blue MachineToApplication<span style="color:black "<span style="color:blue />
<span style="color:blue <<span style="color:#a31515 section <span style="color:red name<span style="color:blue =<span style="color:black "<span style="color:blue roleService<span style="color:black " <span style="color:red type<span style="color:blue =<span style="color:black "<span style="color:blue System.Web.Configuration.ScriptingRoleServiceSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35<span style="color:black " <span style="color:red requirePermission<span style="color:blue =<span style="color:black "<span style="color:blue false<span style="color:black " <span style="color:red allowDefinition<span style="color:blue =<span style="color:black "<span style="color:blue MachineToApplication<span style="color:black "<span style="color:blue />
<span style="color:blue </<span style="color:#a31515 sectionGroup<span style="color:blue >
<span style="color:blue </<span style="color:#a31515 sectionGroup<span style="color:blue >
<span style="color:blue </<span style="color:#a31515 sectionGroup<span style="color:blue >
<span style="color:blue </<span style="color:#a31515 configSections<span style="color:blue >
<span style="color:blue <<span style="color:#a31515 appSettings<span style="color:blue />
<span style="color:blue <<span style="color:#a31515 connectionStrings<span style="color:blue />
<span style="color:blue <<span style="color:#a31515 system.web<span style="color:blue >
<span style="color:green <!--
Set compilation debug="true" to insert debugging
symbols into the compiled page. Because this
affects performance, set this value to true only
during development.
-->
<span style="color:blue <<span style="color:#a31515 compilation <span style="color:red debug<span style="color:blue =<span style="color:black "<span style="color:blue true<span style="color:black "<span style="color:blue >
<span style="color:blue <<span style="color:#a31515 assemblies<span style="color:blue >
<span style="color:blue <<span style="color:#a31515 add <span style="color:red assembly<span style="color:blue =<span style="color:black "<span style="color:blue System.Core, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089<span style="color:black "<span style="color:blue />
<span style="color:blue <<span style="color:#a31515 add <span style="color:red assembly<span style="color:blue =<span style="color:black "<span style="color:blue System.Xml.Linq, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089<span style="color:black "<span style="color:blue />
<span style="color:blue <<span style="color:#a31515 add <span style="color:red assembly<span style="color:blue =<span style="color:black "<span style="color:blue System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35<span style="color:black "<span style="color:blue />
<span style="color:blue <<span style="color:#a31515 add <span style="color:red assembly<span style="color:blue =<span style="color:black "<span style="color:blue System.Data.DataSetExtensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089<span style="color:black "<span style="color:blue />
<span style="color:blue </<span style="color:#a31515 assemblies<span style="color:blue >
<span style="color:blue </<span style="color:#a31515 compilation<span style="color:blue >
<span style="color:green <!--
The <authentication> section enables configuration
of the security authentication mode used by
ASP.NET to identify an incoming user.
-->
<span style="color:blue <<span style="color:#a31515 authentication <span style="color:red mode<span style="color:blue =<span style="color:black "<span style="color:blue Windows<span style="color:black "<span style="color:blue />
<span style="color:green <!--
The <customErrors> section enables configuration
of what to do if/when an unhandled error occurs
during the execution of a request. Specifically,
it enables developers to configure html error pages
to be displayed in place of a error stack trace.
<customErrors mode="RemoteOnly" defaultRedirect="GenericErrorPage.htm
<error statusCode="403" redirect="NoAccess.htm" />
<error statusCode="404" redirect="FileNotFound.htm" />
</customErrors>
-->
<span style="color:blue <<span style="color:#a31515 pages<span style="color:blue >
<span style="color:blue <<span style="color:#a31515 controls<span style="color:blue >
<span style="color:blue <<span style="color:#a31515 add <span style="color:red tagPrefix<span style="color:blue =<span style="color:black "<span style="color:blue asp<span style="color:black " <span style="color:red namespace<span style="color:blue =<span style="color:black "<span style="color:blue System.Web.UI<span style="color:black " <span style="color:red assembly<span style="color:blue =<span style="color:black "<span style="color:blue System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35<span style="color:black "<span style="color:blue />
<span style="color:blue </<span style="color:#a31515 controls<span style="color:blue >
<span style="color:blue </<span style="color:#a31515 pages<span style="color:blue >
<span style="color:blue <<span style="color:#a31515 httpHandlers<span style="color:blue >
<span style="color:blue <<span style="color:#a31515 remove <span style="color:red verb<span style="color:blue =<span style="color:black "<span style="color:blue *<span style="color:black " <span style="color:red path<span style="color:blue =<span style="color:black "<span style="color:blue *.asmx<span style="color:black "<span style="color:blue />
<span style="color:blue <<span style="color:#a31515 add <span style="color:red verb<span style="color:blue =<span style="color:black "<span style="color:blue *<span style="color:black " <span style="color:red path<span style="color:blue =<span style="color:black "<span style="color:blue *.asmx<span style="color:black " <span style="color:red validate<span style="color:blue =<span style="color:black "<span style="color:blue false<span style="color:black " <span style="color:red type<span style="color:blue =<span style="color:black "<span style="color:blue System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35<span style="color:black "<span style="color:blue />
<span style="color:blue <<span style="color:#a31515 add <span style="color:red verb<span style="color:blue =<span style="color:black "<span style="color:blue *<span style="color:black " <span style="color:red path<span style="color:blue =<span style="color:black "<span style="color:blue *_AppService.axd<span style="color:black " <span style="color:red validate<span style="color:blue =<span style="color:black "<span style="color:blue false<span style="color:black " <span style="color:red type<span style="color:blue =<span style="color:black "<span style="color:blue System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35<span style="color:black "<span style="color:blue />
<span style="color:blue <<span style="color:#a31515 add <span style="color:red verb<span style="color:blue =<span style="color:black "<span style="color:blue GET,HEAD<span style="color:black " <span style="color:red path<span style="color:blue =<span style="color:black "<span style="color:blue ScriptResource.axd<span style="color:black " <span style="color:red type<span style="color:blue =<span style="color:black "<span style="color:blue System.Web.Handlers.ScriptResourceHandler, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35<span style="color:black " <span style="color:red validate<span style="color:blue =<span style="color:black "<span style="color:blue false<span style="color:black "<span style="color:blue />
<span style="color:blue </<span style="color:#a31515 httpHandlers<span style="color:blue >
<span style="color:blue <<span style="color:#a31515 httpModules<span style="color:blue >
<span style="color:blue <<span style="color:#a31515 add <span style="color:red name<span style="color:blue =<span style="color:black "<span style="color:blue ScriptModule<span style="color:black " <span style="color:red type<span style="color:blue =<span style="color:black "<span style="color:blue System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35<span style="color:black "<span style="color:blue />
<span style="color:blue </<span style="color:#a31515 httpModules<span style="color:blue >
<span style="color:blue </<span style="color:#a31515 system.web<span style="color:blue >
<span style="color:blue <<span style="color:#a31515 system.codedom<span style="color:blue >
<span style="color:blue <<span style="color:#a31515 compilers<span style="color:blue >
<span style="color:blue <<span style="color:#a31515 compiler <span style="color:red language<span style="color:blue =<span style="color:black "<span style="color:blue c#;cs;csharp<span style="color:black " <span style="color:red extension<span style="color:blue =<span style="color:black "<span style="color:blue .cs<span style="color:black " <span style="color:red warningLevel<span style="color:blue =<span style="color:black "<span style="color:blue 4<span style="color:black " <span style="color:red type<span style="color:blue =<span style="color:black "<span style="color:blue Microsoft.CSharp.CSharpCodeProvider, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089<span style="color:black "<span style="color:blue >
<span style="color:blue <<span style="color:#a31515 providerOption <span style="color:red name<span style="color:blue =<span style="color:black "<span style="color:blue CompilerVersion<span style="color:black " <span style="color:red value<span style="color:blue =<span style="color:black "<span style="color:blue v3.5<span style="color:black "<span style="color:blue />
<span style="color:blue <<span style="color:#a31515 providerOption <span style="color:red name<span style="color:blue =<span style="color:black "<span style="color:blue WarnAsError<span style="color:black " <span style="color:red value<span style="color:blue =<span style="color:black "<span style="color:blue false<span style="color:black "<span style="color:blue />
<span style="color:blue </<span style="color:#a31515 compiler<span style="color:blue >
<span style="color:blue <<span style="color:#a31515 compiler <span style="color:red language<span style="color:blue =<span style="color:black "<span style="color:blue vb;vbs;visualbasic;vbscript<span style="color:black " <span style="color:red extension<span style="color:blue =<span style="color:black "<span style="color:blue .vb<span style="color:black " <span style="color:red warningLevel<span style="color:blue =<span style="color:black "<span style="color:blue 4<span style="color:black " <span style="color:red type<span style="color:blue =<span style="color:black "<span style="color:blue Microsoft.VisualBasic.VBCodeProvider, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089<span style="color:black "<span style="color:blue >
<span style="color:blue <<span style="color:#a31515 providerOption <span style="color:red name<span style="color:blue =<span style="color:black "<span style="color:blue CompilerVersion<span style="color:black " <span style="color:red value<span style="color:blue =<span style="color:black "<span style="color:blue v3.5<span style="color:black "<span style="color:blue />
<span style="color:blue <<span style="color:#a31515 providerOption <span style="color:red name<span style="color:blue =<span style="color:black "<span style="color:blue OptionInfer<span style="color:black " <span style="color:red value<span style="color:blue =<span style="color:black "<span style="color:blue true<span style="color:black "<span style="color:blue />
<span style="color:blue <<span style="color:#a31515 providerOption <span style="color:red name<span style="color:blue =<span style="color:black "<span style="color:blue WarnAsError<span style="color:black " <span style="color:red value<span style="color:blue =<span style="color:black "<span style="color:blue false<span style="color:black "<span style="color:blue />
<span style="color:blue </<span style="color:#a31515 compiler<span style="color:blue >
<span style="color:blue </<span style="color:#a31515 compilers<span style="color:blue >
<span style="color:blue </<span style="color:#a31515 system.codedom<span style="color:blue >
<span style="color:blue <<span style="color:#a31515 system.web.extensions<span style="color:blue >
<span style="color:blue <<span style="color:#a31515 scripting<span style="color:blue >
<span style="color:blue <<span style="color:#a31515 webServices<span style="color:blue >
<span style="color:green <!--
Uncomment this section to enable the authentication service. Include
requireSSL="true" if appropriate.
<authenticationService enabled="true" requireSSL = "true|false"/>
-->
<span style="color:green <!--
Uncomment these lines to enable the profile service, and to choose the
profile properties that can be retrieved and modified in ASP.NET AJAX
applications.
<profileService enabled="true"
readAccessProperties="propertyname1,propertyname2"
writeAccessProperties="propertyname1,propertyname2" />
-->
<span style="color:green <!--
Uncomment this section to enable the role service.
<roleService enabled="true"/>
-->
<span style="color:blue </<span style="color:#a31515 webServices<span style="color:blue >
<span style="color:green <!--
<scriptResourceHandler enableCompression="true" enableCaching="true" />
-->
<span style="color:blue </<span style="color:#a31515 scripting<span style="color:blue >
<span style="color:blue </<span style="color:#a31515 system.web.extensions<span style="color:blue >
<span style="color:green <!--
The system.webServer section is required for running ASP.NET AJAX under Internet
Information Services 7.0. It is not necessary for previous version of IIS.
-->
<span style="color:blue <<span style="color:#a31515 system.webServer<span style="color:blue >
<span style="color:blue <<span style="color:#a31515 validation <span style="color:red validateIntegratedModeConfiguration<span style="color:blue =<span style="color:black "<span style="color:blue false<span style="color:black "<span style="color:blue />
<span style="color:blue <<span style="color:#a31515 modules<span style="color:blue >
<span style="color:blue <<span style="color:#a31515 add <span style="color:red name<span style="color:blue =<span style="color:black "<span style="color:blue ScriptModule<span style="color:black " <span style="color:red preCondition<span style="color:blue =<span style="color:black "<span style="color:blue integratedMode<span style="color:black " <span style="color:red type<span style="color:blue =<span style="color:black "<span style="color:blue System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35<span style="color:black "<span style="color:blue />
<span style="color:blue </<span style="color:#a31515 modules<span style="color:blue >
<span style="color:blue <<span style="color:#a31515 handlers<span style="color:blue >
<span style="color:blue <<span style="color:#a31515 remove <span style="color:red name<span style="color:blue =<span style="color:black "<span style="color:blue WebServiceHandlerFactory-Integrated<span style="color:black "<span style="color:blue />
<span style="color:blue <<span style="color:#a31515 add <span style="color:red name<span style="color:blue =<span style="color:black "<span style="color:blue ScriptHandlerFactory<span style="color:black " <span style="color:red verb<span style="color:blue =<span style="color:black "<span style="color:blue *<span style="color:black " <span style="color:red path<span style="color:blue =<span style="color:black "<span style="color:blue *.asmx<span style="color:black " <span style="color:red preCondition<span style="color:blue =<span style="color:black "<span style="color:blue integratedMode<span style="color:black " <span style="color:red type<span style="color:blue =<span style="color:black "<span style="color:blue System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35<span style="color:black "<span style="color:blue />
<span style="color:blue <<span style="color:#a31515 add <span style="color:red name<span style="color:blue =<span style="color:black "<span style="color:blue ScriptHandlerFactoryAppServices<span style="color:black " <span style="color:red verb<span style="color:blue =<span style="color:black "<span style="color:blue *<span style="color:black " <span style="color:red path<span style="color:blue =<span style="color:black "<span style="color:blue *_AppService.axd<span style="color:black " <span style="color:red preCondition<span style="color:blue =<span style="color:black "<span style="color:blue integratedMode<span style="color:black " <span style="color:red type<span style="color:blue =<span style="color:black "<span style="color:blue System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35<span style="color:black "<span style="color:blue />
<span style="color:blue <<span style="color:#a31515 add <span style="color:red name<span style="color:blue =<span style="color:black "<span style="color:blue ScriptResource<span style="color:black " <span style="color:red preCondition<span style="color:blue =<span style="color:black "<span style="color:blue integratedMode<span style="color:black " <span style="color:red verb<span style="color:blue =<span style="color:black "<span style="color:blue GET,HEAD<span style="color:black " <span style="color:red path<span style="color:blue =<span style="color:black "<span style="color:blue ScriptResource.axd<span style="color:black " <span style="color:red type<span style="color:blue =<span style="color:black "<span style="color:blue System.Web.Handlers.ScriptResourceHandler, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35<span style="color:black "<span style="color:blue />
<span style="color:blue </<span style="color:#a31515 handlers<span style="color:blue >
<span style="color:blue </<span style="color:#a31515 system.webServer<span style="color:blue >
<span style="color:blue <<span style="color:#a31515 system.serviceModel<span style="color:blue >
<span style="color:green <!-- Bindings -->
<span style="color:blue <<span style="color:#a31515 bindings<span style="color:blue >
<span style="color:blue <<span style="color:#a31515 basicHttpBinding<span style="color:blue >
<span style="color:blue <<span style="color:#a31515 binding <span style="color:red name<span style="color:blue =<span style="color:black "<span style="color:blue TestBasicHttpBinding<span style="color:black "<span style="color:blue >
<span style="color:blue </<span style="color:#a31515 binding<span style="color:blue >
<span style="color:blue </<span style="color:#a31515 basicHttpBinding<span style="color:blue >
<span style="color:blue </<span style="color:#a31515 bindings<span style="color:blue >
<span style="color:blue <<span style="color:#a31515 services<span style="color:blue >
<span style="color:blue <<span style="color:#a31515 service <span style="color:red name<span style="color:blue =<span style="color:black "<span style="color:blue HttpPostTestImpl<span style="color:black " <span style="color:red behaviorConfiguration<span style="color:blue =<span style="color:black "<span style="color:blue ServiceBehavior<span style="color:black "<span style="color:blue >
<span style="color:blue <<span style="color:#a31515 endpoint <span style="color:red address<span style="color:blue =<span style="color:black "<span style="color:blue " behaviorConfiguration="WebBehavior<span style="color:black " <span style="color:red binding<span style="color:blue =<span style="color:black "<span style="color:blue webHttpBinding<span style="color:black " <span style="color:red contract<span style="color:blue =<span style="color:black "<span style="color:blue HttpPostTest<span style="color:black "<span style="color:blue >
<span style="color:green <!--
Upon deployment, the following identity element should be removed or replaced to reflect the
identity under which the deployed service runs. If removed, WCF will infer an appropriate identity
automatically.
-->
<span style="color:blue <<span style="color:#a31515 identity<span style="color:blue >
<span style="color:blue <<span style="color:#a31515 dns <span style="color:red value<span style="color:blue =<span style="color:black "<span style="color:blue localhost<span style="color:black "<span style="color:blue />
<span style="color:blue </<span style="color:#a31515 identity<span style="color:blue >
<span style="color:blue </<span style="color:#a31515 endpoint<span style="color:blue >
<span style="color:blue <<span style="color:#a31515 endpoint <span style="color:red address<span style="color:blue =<span style="color:black "<span style="color:blue mex<span style="color:black " <span style="color:red binding<span style="color:blue =<span style="color:black "<span style="color:blue mexHttpBinding<span style="color:black " <span style="color:red contract<span style="color:blue =<span style="color:black "<span style="color:blue IMetadataExchange<span style="color:black "<span style="color:blue />
<span style="color:blue </<span style="color:#a31515 service<span style="color:blue >
<span style="color:blue </<span style="color:#a31515 services<span style="color:blue >
<span style="color:blue <<span style="color:#a31515 behaviors<span style="color:blue >
<span style="color:blue <<span style="color:#a31515 serviceBehaviors<span style="color:blue >
<span style="color:blue <<span style="color:#a31515 behavior <span style="color:red name<span style="color:blue =<span style="color:black "<span style="color:blue ServiceBehavior<span style="color:black "<span style="color:blue >
<span style="color:green <!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment -->
<span style="color:blue <<span style="color:#a31515 serviceMetadata <span style="color:red httpGetEnabled<span style="color:blue =<span style="color:black "<span style="color:blue true<span style="color:black "<span style="color:blue />
<span style="color:green <!-- To receive exception details in faults for debugging purposes, set the value below to true. Set to false before deployment to avoid disclosing exception information -->
<span style="color:blue <<span style="color:#a31515 serviceDebug <span style="color:red includeExceptionDetailInFaults<span style="color:blue =<span style="color:black "<span style="color:blue false<span style="color:black "<span style="color:blue />
<span style="color:blue </<span style="color:#a31515 behavior<span style="color:blue >
<span style="color:blue </<span style="color:#a31515 serviceBehaviors<span style="color:blue >
<span style="color:blue <<span style="color:#a31515 endpointBehaviors<span style="color:blue >
<span style="color:blue <<span style="color:#a31515 behavior <span style="color:red name<span style="color:blue =<span style="color:black "<span style="color:blue WebBehavior<span style="color:black "<span style="color:blue >
<span style="color:blue <<span style="color:#a31515 webHttp<span style="color:blue />
<span style="color:blue </<span style="color:#a31515 behavior<span style="color:blue >
<span style="color:blue </<span style="color:#a31515 endpointBehaviors<span style="color:blue >
<span style="color:blue </<span style="color:#a31515 behaviors<span style="color:blue >
<span style="color:blue </<span style="color:#a31515 system.serviceModel<span style="color:blue >
<span style="color:blue </<span style="color:#a31515 configuration<span style="color:blue >
[/code]
This is my client code:
<div style="color:black; background-color:white
<pre> WebRequest webRequest = WebRequest.Create(<span style="color:#a31515 "http://localhost:8889/HttpPostTest/Service.svc/WS_HttpPostTest");
webRequest.ContentType = <span style="color:#a31515 "application/x-www-form-urlencoded";
webRequest.Method = <span style="color:#a31515 "POST";
<span style="color:blue string data = <span style="color:#a31515 "request=" + Convert.ToString(1231234);
<span style="color:blue byte[] bytes = Encoding.ASCII.GetBytes(data);
Stream os = <span style="color:blue null;
<span style="color:blue try
{ <span style="color:green // send the Post
Console.WriteLine(<span style="color:#a31515 "Enviando pedido");
webRequest.ContentLength = bytes.Length; <span style="color:green //Count bytes to send
os = webRequest.GetRequestStream();
os.Write(bytes, 0, bytes.Length); <span style="color:green //Send it
}
<span style="color:blue catch (WebException ex)
{
Console.WriteLine(<span style="color:#a31515 "HttpPost: Request error: " + ex.Message);
Console.WriteLine(ex.StackTrace);
}
<span style="color:blue finally
{
<span style="color:blue if (os != <span style="color:blue null)
{
os.Close();
}
}
<span style="color:blue try
{ <span style="color:green // get the response
WebResponse webResponse = webRequest.GetResponse();
<span style="color:blue if (webResponse != <span style="color:blue null)
{
StreamReader sr = <span style="color:blue new StreamReader(webResponse.GetResponseStream());
Console.WriteLine(<span style="color:#a31515 "Valor recebido: " + sr.ReadToEnd().Trim());
}
<span style="color:blue else
Console.WriteLine(<span style="color:#a31515 "Nenhum valor recebido");
}
<span style="color:blue catch (WebException ex)
{
Console.WriteLine(<span style="color:#a31515 "HttpPost: Response error: " + ex.Message);
Console.WriteLine(ex.StackTrace);
}
[/code]
When I run this test program I get the following error:
<pre>Enviando pedido
HttpPost: Response error: O servidor remoto retornou um erro: (400) SolicitaÃÃo Incorreta. <br/>[/code]
What am I doing wrong in this program?
Thanks,<br/>
Komyg
<br/>
View the full article