Tuesday, April 1, 2014

WCF HTTP Post returns 400

Hi All,


Im creating Wcf service and here is my IService function and config



[OperationContract]
[WebInvoke(Method = "POST", RequestFormat = WebMessageFormat.Xml,
BodyStyle = WebMessageBodyStyle.Wrapped, ResponseFormat = WebMessageFormat.Xml,
UriTemplate = "DoWork")]
string DoWork(string name);




<?xml version="1.0" encoding="utf-8"?>
<configuration>
<configSections>
<!-- For more information on Entity Framework configuration, visit http://ift.tt/1eigFsq -->
<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
</configSections>
<appSettings>
<add key="aspnet:UseTaskFriendlySynchronizationContext" value="true" />
</appSettings>
<system.web>
<compilation debug="true" targetFramework="4.5" />
<httpRuntime targetFramework="4.5" />
</system.web>
<system.serviceModel>
<bindings>
<webHttpBinding>
<binding maxReceivedMessageSize="262144"></binding>
</webHttpBinding>
</bindings>
<behaviors>
<serviceBehaviors>
<behavior>
<!-- To avoid disclosing metadata information, set the values below to false before deployment -->
<serviceMetadata httpGetEnabled="true" httpsGetEnabled="true" />
<!-- 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 -->
<serviceDebug includeExceptionDetailInFaults="false" />
</behavior>
<behavior name="MetadataBehavior">
<serviceMetadata httpGetEnabled="true" />
</behavior>
</serviceBehaviors>
<endpointBehaviors>
<behavior name="RestBehavior">
<webHttp />
</behavior>
</endpointBehaviors>
</behaviors>
<protocolMapping>
<add binding="webHttpBinding" scheme="https" />
</protocolMapping>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
<services>

<service behaviorConfiguration="MetadataBehavior" name="XXXXX.AdminOptions">
<endpoint address="xxxxxx/AdminOptions.svc" binding="basicHttpBinding" bindingConfiguration="" name="Soap" contract="XXXX.IAdminOptions" />
<endpoint behaviorConfiguration="RestBehavior" binding="webHttpBinding" bindingConfiguration="" name="webHttpBinding" contract="BigHartsService.IAdminOptions" />
</service>
</services>
</system.serviceModel>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true" />
<!--
To browse web app root directory during debugging, set the value below to true.
Set to false before deployment to avoid disclosing web app folder information.
-->
<directoryBrowse enabled="true" />
</system.webServer>
<entityFramework>
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">
<parameters>
<parameter value="v11.0" />
</parameters>
</defaultConnectionFactory>
<providers>
<provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
</providers>
</entityFramework>

<connectionStrings><add name="db" connectionString="metadata=http://res*/BigHartModel.csdl|res*/BigHartModel.ssdl|res*/BigHartModel.msl;provider=System.Data.SqlClient;provider connection string=&quot;data source=source;initial catalog=dbct;user id=XXXXX;password=XXXXX;MultipleActiveResultSets=True;App=EntityFramework&quot;" providerName="System.Data.EntityClient" /></connectionStrings></configuration>

Here is my client code



var client = new HttpWebRequest();
var postData = new List<KeyValuePair<string, string>>();
postData.Add(new KeyValuePair<string, string>("name", "Saman"));

HttpContent content = new FormUrlEncodedContent(postData);

var response = await client.PostAsync("http://localhost:3395/AdminOptions.svc/DoWork", content);



i Tried clint side code with WebRequest also.. But eroor is status code returns 400..


whats wrong and how to fix



No comments:

Post a Comment